block storage init commit

This commit is contained in:
2026-03-14 23:56:48 -07:00
parent e7aabdceb4
commit 702a5e99a4
5 changed files with 55 additions and 218 deletions

View File

@ -20,9 +20,11 @@ component_types = [{"name": entry["name"], "multi_check": entry["multi_check"] =
class Component:
def __init__(self, name: str, comp_type: str ):
def __init__(self, name: str, comp_type: str, this_device="None"):
self.name = name
self.type = comp_type
self.this_device = this_device
print(f"This device - {self.this_device}")
for component in component_class_tree:
if component["name"] == self.type:
COMPONENT_DESCRIPTORS = component
@ -39,7 +41,12 @@ class Component:
self.multi_check = self.is_multi()
self._properties: Dict[str, str] = {}
for key, command in descriptor.get('properties', {}).items():
self._properties[key] = run_command(command, True)
if self.this_device != "None":
print(f"command - {command}; this_device - {self.this_device}")
formatted_command = command.format(this_device=self.this_device)
self._properties[key] = run_command(formatted_command, True)
else:
self._properties[key] = run_command(command, True)
# build the description string
self._description_template: str | None = descriptor.get("description")
self.description = self._description_template.format(**self._properties)
@ -59,7 +66,11 @@ class Component:
def update_metrics(self):
for key, command in self._descriptor.get('metrics', {}).items():
self._metrics[key] = run_command(command, True)
if self.this_device != "None":
formatted_command = command.format(this_device=self.this_device)
self._properties[key] = run_command(formatted_command, True)
else:
self._metrics[key] = run_command(command, True)
# complex data type return
def get_metrics(self, type = None):
@ -207,15 +218,25 @@ class System:
for component in component_types:
component_name = component["name"]
multi_check = component["multi_check"]
# if multi, note that the command in device_list creates the list of things to pipe into this_device
if multi_check:
print("placeholder...")
letters = [chr(c) for c in range(ord('a'), ord('z')+1)]
print(f"Creating one component of type {component_name} for each one found")
component_type_device_list = get_device_list(component_name)
for this_device in component_type_device_list:
this_component_letter = letters[component_type_device_list.index(this_device)]
this_component_name = f"{this_device}_{this_component_letter}"
print(f"{this_component_name} - {component_name} - {this_device}")
self.add_components(Component(this_component_name, component_name, this_device))
else:
if debug_output:
print(f"Creating component {component["name"]}")
self.add_components(Component(component_name, component_name))
# Add a component to the system
def add_components(self, component: Component):
def add_components(self, component: Component,):
if debug_output:
print(f"Component description: {component.description}")
self.components.append(component)
@ -357,3 +378,13 @@ def run_command(cmd, zero_only=False):
return output_lines[0] if zero_only else output_lines
except:
return output_lines
def get_device_list(device_type_name: str):
result = []
for component in component_class_tree:
if component["name"] == device_type_name:
device_list_command = component["device_list"]
device_list_result = run_command(device_list_command)
result = device_list_result
return result