Skip to content

Commit 381bf86

Browse files
committed
feat(core): add LINSTOR controller and satellite helpers
Signed-off-by: Ronan Abhamon <ronan.abhamon@vates.tech>
1 parent 9c90aed commit 381bf86

3 files changed

Lines changed: 116 additions & 0 deletions

File tree

‎src/xcp_storage/backends/linstor/__init__.py‎

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

0 commit comments

Comments
 (0)