Skip to content
This repository was archived by the owner on Dec 16, 2025. It is now read-only.

Commit 7d464bc

Browse files
Use data of ceph report for analysis instead of multiple sources
Signed-off-by: Tobias Wolf <[email protected]>
1 parent b745bcd commit 7d464bc

File tree

9 files changed

+71
-45
lines changed

9 files changed

+71
-45
lines changed

src/rookify/modules/analyze_ceph/main.py

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,45 @@
77

88

99
class AnalyzeCephHandler(ModuleHandler):
10-
def _process_command(
10+
def _process_command_result(
1111
self, state_data: Any, command: str, value: Optional[Any] = None
1212
) -> bool:
13-
"""Helper method to process commands by either setting or checking state data."""
14-
parts = command.split(" ")
15-
current_level = state_data # the root of the data structure
13+
"""
14+
Helper method to process commands by either setting or checking state data.
15+
"""
16+
17+
command_parts = command.split(" ")
18+
state_structure_data = state_data # the root of the data structure
1619

1720
# Traverse the dictionary structure based on command parts
18-
for idx, part in enumerate(parts):
19-
if len(parts) == idx + 1: # Last part of the command
20-
if value is not None:
21-
current_level[part] = value
22-
else:
23-
return part in current_level
21+
for idx, key in enumerate(command_parts):
22+
# Last part of the command
23+
if len(command_parts) == idx + 1:
24+
if value is None:
25+
return key in state_structure_data
26+
27+
state_structure_data[key] = value
2428
else:
25-
if part not in current_level:
26-
current_level[part] = {}
27-
current_level = current_level[part]
29+
if key not in state_structure_data:
30+
state_structure_data[key] = {}
31+
32+
state_structure_data = state_structure_data[key]
2833

2934
return True
3035

3136
def preflight(self) -> Any:
32-
commands = ["mon dump", "osd dump", "device ls", "fs ls", "node ls"]
3337
state = self.machine.get_preflight_state("AnalyzeCephHandler")
38+
39+
if getattr(state, "data", None) is not None:
40+
return
41+
42+
commands = ["fs ls", "node ls", "report"]
3443
state.data = {}
3544

3645
# Execute each command and store the result
3746
for command in commands:
3847
result = self.ceph.mon_command(command)
39-
self._process_command(state.data, command, result)
48+
self._process_command_result(state.data, command, result)
4049

4150
self.logger.info("AnalyzeCephHandler ran successfully.")
4251

@@ -45,25 +54,25 @@ def get_readable_key_value_state(self) -> Dict[str, str]:
4554

4655
kv_state_data = OrderedDict()
4756

48-
if "mon" not in state.data or "dump" not in state.data["mon"]:
49-
kv_state_data["ceph mon dump"] = "Not analyzed yet"
57+
if "report" not in state.data:
58+
kv_state_data["Ceph report"] = "Not analyzed yet"
5059
else:
51-
kv_state_data["ceph mon dump"] = self._get_readable_json_dump(
52-
state.data["mon"]["dump"]
60+
kv_state_data["Ceph report"] = self._get_readable_json_dump(
61+
state.data["report"]
5362
)
5463

55-
if "osd" not in state.data or "dump" not in state.data["osd"]:
56-
kv_state_data["ceph osd dump"] = "Not analyzed yet"
64+
if "node" not in state.data or "ls" not in state.data["node"]:
65+
kv_state_data["Ceph node ls"] = "Not analyzed yet"
5766
else:
58-
kv_state_data["ceph osd dump"] = self._get_readable_json_dump(
59-
state.data["osd"]["dump"]
67+
kv_state_data["Ceph node ls"] = self._get_readable_json_dump(
68+
state.data["node"]["ls"]
6069
)
6170

62-
if "device" not in state.data or "ls" not in state.data["device"]:
63-
kv_state_data["OSD devices"] = "Not analyzed yet"
71+
if "fs" not in state.data or "ls" not in state.data["fs"]:
72+
kv_state_data["Ceph fs ls"] = "Not analyzed yet"
6473
else:
65-
kv_state_data["OSD devices"] = self._get_readable_json_dump(
66-
state.data["device"]["ls"]
74+
kv_state_data["Ceph fs ls"] = self._get_readable_json_dump(
75+
state.data["fs"]["ls"]
6776
)
6877

6978
return kv_state_data

src/rookify/modules/cephx_auth_config/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88

99
class CephXAuthHandler(ModuleHandler):
10-
def preflight(self) -> Any:
10+
def preflight(self) -> None:
1111
if not self.is_cephx_set(self.ceph.conf_get("auth_cluster_required")):
1212
raise ModuleException(
1313
"Ceph config value auth_cluster_required does not contain cephx"

src/rookify/modules/create_rook_resources/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def __create_configmap_definition(self) -> None:
1919
configmap_mon_list = ""
2020
mapping = {}
2121

22-
for mon in state_data["mon"]["dump"]["mons"]:
22+
for mon in state_data["report"]["monmap"]["mons"]:
2323
if configmap_mon_list != "":
2424
configmap_mon_list += ","
2525

@@ -120,7 +120,7 @@ def execute(self) -> None:
120120
secret_data = {
121121
"admin-secret": admin_auth["key"],
122122
"cluster-name": self._config["rook"]["cluster"]["name"],
123-
"fsid": state_data["mon"]["dump"]["fsid"],
123+
"fsid": state_data["report"]["monmap"]["fsid"],
124124
"mon-secret": mon_auth["key"],
125125
}
126126

src/rookify/modules/migrate_mds_pools/main.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ def get_readable_key_value_state(self) -> Dict[str, str]:
7777
"MigrateMdsPoolsHandler", "migrated_mds_pools", default_value=[]
7878
)
7979

80-
pools = self.machine.get_preflight_state("MigrateMdsPoolsHandler").pools
80+
pools = self.machine.get_preflight_state_data(
81+
"MigrateMdsPoolsHandler", "pools", default_value={}
82+
)
8183

8284
kv_state_data = OrderedDict()
8385

src/rookify/modules/migrate_mons/main.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,18 @@ def execute(self) -> None:
2626
"MigrateMonsHandler", "migrated_mons", default_value=[]
2727
)
2828

29-
if len(migrated_mons) >= len(state_data["mon"]["dump"]["mons"]):
29+
if len(migrated_mons) >= len(state_data["report"]["monmap"]["mons"]):
3030
return
3131

32-
for mon in state_data["mon"]["dump"]["mons"]:
32+
for mon in state_data["report"]["monmap"]["mons"]:
3333
self._migrate_mon(mon)
3434

3535
def get_readable_key_value_state(self) -> Dict[str, str]:
3636
state_data = self.machine.get_preflight_state("AnalyzeCephHandler").data
3737

3838
return {
3939
"ceph mon daemons": self._get_readable_json_dump(
40-
state_data["mon"]["dump"]["mons"]
40+
state_data["report"]["monmap"]["mons"]
4141
)
4242
}
4343

src/rookify/modules/migrate_osd_pools/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def _get_filtered_osd_pools_list(self) -> List[Dict[str, Any]]:
3333
state_data = self.machine.get_preflight_state("AnalyzeCephHandler").data
3434

3535
osd_pool_configurations = self.ceph.get_osd_pool_configurations_from_osd_dump(
36-
state_data["osd"]["dump"]
36+
state_data["report"]["osdmap"]
3737
)
3838

3939
pools = []

src/rookify/modules/migrate_osds/main.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@
99

1010

1111
class MigrateOSDsHandler(ModuleHandler):
12-
REQUIRES = ["migrate_mons"]
12+
REQUIRES = ["analyze_ceph", "migrate_mons"]
1313

1414
def _get_devices_of_hosts(self) -> Dict[str, Dict[str, str]]:
1515
state_data = self.machine.get_preflight_state("AnalyzeCephHandler").data
16+
1617
osd_devices: Dict[str, Dict[str, str]] = {}
18+
osd_metadata = {
19+
str(osd_data["id"]): osd_data for osd_data in state_data["osd_metadata"]
20+
}
1721

1822
for osd_host, osds in state_data["node"]["ls"]["osd"].items():
1923
osd_devices[osd_host] = {}
@@ -23,7 +27,12 @@ def _get_devices_of_hosts(self) -> Dict[str, Dict[str, str]]:
2327
From there we try to get the encrypted volume partition UUID for later use in Rook.
2428
"""
2529
for osd_id in osds:
26-
osd_data = self.ceph.mon_command("osd metadata", id=osd_id)
30+
if osd_id not in osd_metadata:
31+
raise ModuleException(
32+
"Found Ceph OSD ID {0} without metadata".format(osd_id)
33+
)
34+
35+
osd_data = osd_metadata[osd_id]
2736

2837
result = self.ssh.command(
2938
osd_host,

src/rookify/modules/migrate_rgw_pools/main.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ def preflight(self) -> None:
2020
if len(zones) > 0:
2121
return
2222

23-
service_data = self.ceph.mon_command("service dump")
24-
25-
rgw_daemons = service_data["services"].get("rgw", {}).get("daemons", {})
23+
rgw_daemons = (
24+
state_data["report"]["servicemap"]["services"]
25+
.get("rgw", {})
26+
.get("daemons", {})
27+
)
2628

2729
for rgw_daemon in rgw_daemons.values():
2830
if not isinstance(rgw_daemon, dict):
@@ -36,7 +38,7 @@ def preflight(self) -> None:
3638
zones[zone_name] = {"osd_pools": {}, "rgw_count": 1}
3739

3840
osd_pools = self.ceph.get_osd_pool_configurations_from_osd_dump(
39-
state_data["osd"]["dump"]
41+
state_data["report"]["osdmap"]
4042
)
4143

4244
for zone_name in zones:
@@ -76,7 +78,9 @@ def get_readable_key_value_state(self) -> Dict[str, str]:
7678
"MigrateRgwPoolsHandler", "migrated_pools", default_value=[]
7779
)
7880

79-
zones = self.machine.get_preflight_state("MigrateRgwPoolsHandler").zones
81+
zones = self.machine.get_preflight_state_data(
82+
"MigrateRgwPoolsHandler", "zones", default_value={}
83+
)
8084

8185
kv_state_data = OrderedDict()
8286

src/rookify/modules/migrate_rgws/main.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88

99

1010
class MigrateRgwsHandler(ModuleHandler):
11-
REQUIRES = ["migrate_rgw_pools"]
11+
REQUIRES = ["analyze_ceph", "migrate_rgw_pools"]
1212

1313
def _get_rgw_daemon_hosts(self) -> List[str]:
14-
ceph_status = self.ceph.mon_command("status")
14+
state_data = self.machine.get_preflight_state("AnalyzeCephHandler").data
1515

16-
rgw_daemons = ceph_status["servicemap"]["services"]["rgw"]["daemons"]
16+
rgw_daemons = state_data["report"]["servicemap"]["services"]["rgw"]["daemons"]
1717
rgw_daemon_hosts = []
18+
1819
if "summary" in rgw_daemons:
1920
del rgw_daemons["summary"]
2021

@@ -23,6 +24,7 @@ def _get_rgw_daemon_hosts(self) -> List[str]:
2324
raise ModuleException(
2425
"Unexpected ceph-rgw daemon metadata: {0}".format(rgw_daemon)
2526
)
27+
2628
if rgw_daemon["metadata"]["hostname"] not in rgw_daemon_hosts:
2729
rgw_daemon_hosts.append(rgw_daemon["metadata"]["hostname"])
2830

0 commit comments

Comments
 (0)