From 074ac03f190f3b911353cf14944b53e30d1d09d9 Mon Sep 17 00:00:00 2001 From: Tobias Wolf Date: Tue, 17 Sep 2024 20:27:31 +0200 Subject: [PATCH] Return representive state data for module `migrate_osds` Signed-off-by: Tobias Wolf --- src/rookify/modules/migrate_osds/main.py | 31 +++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/rookify/modules/migrate_osds/main.py b/src/rookify/modules/migrate_osds/main.py index a14792a..acebdf5 100644 --- a/src/rookify/modules/migrate_osds/main.py +++ b/src/rookify/modules/migrate_osds/main.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- +from collections import OrderedDict from time import sleep from typing import Any, Dict, List from ..exception import ModuleException @@ -84,7 +85,7 @@ def preflight(self) -> None: def execute(self) -> None: osd_host_devices = self.machine.get_preflight_state_data( - "MigrateOSDsHandler", "osd_host_devices", default_value=[] + "MigrateOSDsHandler", "osd_host_devices", default_value={} ) state_data = self.machine.get_preflight_state("AnalyzeCephHandler").data @@ -92,6 +93,34 @@ def execute(self) -> None: for host in osd_host_devices.keys(): self.migrate_osds(host, state_data["node"]["ls"]["osd"][host]) + def get_readable_key_value_state(self) -> Dict[str, str]: + state_data = self.machine.get_preflight_state("AnalyzeCephHandler").data + + osd_host_devices = self.machine.get_preflight_state_data( + "MigrateOSDsHandler", "osd_host_devices", default_value={} + ) + + kv_state_data = OrderedDict() + + for host in state_data["node"]["ls"]["osd"].keys(): + if host in osd_host_devices: + osd_device_list = [] + + for osd_id, device_path in osd_host_devices[host].items(): + osd_device_list.append( + {"OSD ID": osd_id, "Device path": device_path} + ) + + kv_state_data["ceph OSD node {0} devices".format(host)] = ( + self._get_readable_json_dump(osd_device_list) + ) + else: + kv_state_data["ceph OSD node {0} devices".format(host)] = ( + "Not analyzed yet" + ) + + return kv_state_data + def migrate_osds(self, host: str, osd_ids: List[int]) -> None: migrated_osd_ids = self.machine.get_execution_state_data( "MigrateOSDsHandler", "migrated_osd_ids", default_value=[]