77
88
99class 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
0 commit comments