Skip to content

Commit 5f60336

Browse files
committed
tmp
Signed-off-by: Ronan Abhamon <ronan.abhamon@vates.tech>
1 parent dedb299 commit 5f60336

File tree

13 files changed

+738
-140
lines changed

13 files changed

+738
-140
lines changed

xcp-storage/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.mypy_cache
2+
.pytest_cache
3+
.ruff_cache
4+
__pycache__

xcp-storage/pyproject.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,13 @@ ignore = [
3939
"UP045" # pyupgrade: non-pep604-annotation-optional
4040
]
4141
select = [
42+
"ANN", # flake8-annotations
4243
"ARG", # flake8-unused-arguments
4344
"B", # flake8-bugbear
4445
"C90", # mccabe
4546
"F", # Pyflakes
4647
"I", # isort
48+
"ICN", # flake8-import-conventions
4749
"N", # pep8-naming
4850
"PTH", # flake8-use-pathlib
4951
"Q", # flake8-quotes
@@ -52,6 +54,7 @@ select = [
5254
"SIM", # flake8-simplify
5355
"SLF", # flake8-self
5456
"T20", # flake8-print
57+
"TID", # flake8-tidy-imports
5558
"UP" # pyupgrade
5659
]
5760
typing-modules = ["xcp_storage.typing"]
@@ -75,3 +78,7 @@ section-order = [
7578
"local-folder",
7679
"typing"
7780
]
81+
82+
[tool.pytest.ini_options]
83+
pythonpath = ["src", "stubs"]
84+
testpaths = ["tests"]

xcp-storage/src/xcp_storage/backends/drbd.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737

3838
DRBD_BY_RES_PATH = "/dev/drbd/by-res/"
3939

40+
DRBD_PORT_RANGE = (7000, 8000)
41+
4042
# ------------------------------------------------------------------------------
4143

4244
_EXEC_PATH_DRBDSETUP = "/usr/sbin/drbdsetup"
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/usr/bin/env python3
2+
#
3+
# Copyright (C) 2026 Vates SAS
4+
#
5+
# This program is free software: you can redistribute it and/or modify
6+
# it under the terms of the GNU General Public License as published by
7+
# the Free Software Foundation, either version 3 of the License, or
8+
# (at your option) any later version.
9+
# This program is distributed in the hope that it will be useful,
10+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
# GNU General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU General Public License
15+
# along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
17+
from xcp_storage.utils.process import run_command
18+
from xcp_storage.utils.service import (
19+
is_service_active,
20+
restart_service,
21+
start_service,
22+
stop_service,
23+
)
24+
25+
from .satellite import LINSTOR_SATELLITE_PORT_PLAIN, LINSTOR_SATELLITE_PORT_SSL
26+
27+
from xcp_storage.typing import List
28+
29+
# ==============================================================================
30+
31+
LINSTOR_CONTROLLER_PORT_PLAIN = 3370
32+
LINSTOR_CONTROLLER_PORT_SSL = 3371
33+
34+
# ------------------------------------------------------------------------------
35+
36+
_SERVICE_LINSTOR_CONTROLLER = "linstor-controller"
37+
38+
# ------------------------------------------------------------------------------
39+
40+
def get_controller_addresses() -> List[str]:
41+
stdout = run_command([
42+
"/usr/sbin/ss", "-tnpH", "state", "established",
43+
f"( sport = :{LINSTOR_SATELLITE_PORT_PLAIN} or sport = :{LINSTOR_SATELLITE_PORT_SSL} )"
44+
], expected_ret_code=0)
45+
return [
46+
line.split()[3].rsplit(":", 1)[0]
47+
for line in stdout.splitlines()
48+
]
49+
50+
def get_controller_uri() -> str:
51+
# TODO: On caller side, check that an IP address from the current pool is returned.
52+
addresses = get_controller_addresses()
53+
return "linstor://" + addresses[0] if addresses else ""
54+
55+
# ------------------------------------------------------------------------------
56+
57+
def is_controller_running() -> bool:
58+
return is_service_active(_SERVICE_LINSTOR_CONTROLLER)
59+
60+
def start_controller() -> None:
61+
start_service(_SERVICE_LINSTOR_CONTROLLER)
62+
63+
def stop_controller() -> None:
64+
stop_service(_SERVICE_LINSTOR_CONTROLLER)
65+
66+
def restart_controller() -> None:
67+
restart_service(_SERVICE_LINSTOR_CONTROLLER)

0 commit comments

Comments
 (0)