from redfish_system import RedfishSystem
-from util import Logger, normalize_dict
+from util import Logger, normalize_dict, to_snake_case
from typing import Dict, Any
log = Logger(__name__)
super().__init__(**kw)
def _update_network(self) -> None:
- net_path = self._system['EthernetInterfaces']['@odata.id']
+ fields = ['Description', 'Name', 'SpeedMbps', 'Status']
log.logger.info("Updating network")
- network_info = self._get_path(net_path)
- self._system['network'] = {}
- result: Dict[str, Dict[str, Dict]] = dict()
- for interface in network_info['Members']:
- interface_path = interface['@odata.id']
- interface_info = self._get_path(interface_path)
- interface_id = interface_info['Id']
- result[interface_id] = dict()
- result[interface_id]['description'] = interface_info['Description']
- result[interface_id]['name'] = interface_info['Name']
- result[interface_id]['speed_mbps'] = interface_info['SpeedMbps']
- result[interface_id]['status'] = interface_info['Status']
- self._system['network'] = normalize_dict(result)
+ self._system['network'] = self.build_data(fields, 'EthernetInterfaces')
def _update_processors(self) -> None:
- cpus_path = self._system['Processors']['@odata.id']
+ fields = ['Description',
+ 'TotalCores',
+ 'TotalThreads',
+ 'ProcessorType',
+ 'Model',
+ 'Status',
+ 'Manufacturer']
log.logger.info("Updating processors")
- cpus_info = self._get_path(cpus_path)
- self._system['processors'] = {}
- result: Dict[str, Dict[str, Dict]] = dict()
- for cpu in cpus_info['Members']:
- cpu_path = cpu['@odata.id']
- cpu_info = self._get_path(cpu_path)
- cpu_id = cpu_info['Id']
- result[cpu_id] = dict()
- result[cpu_id]['description'] = cpu_info['Description']
- result[cpu_id]['cores'] = cpu_info['TotalCores']
- result[cpu_id]['threads'] = cpu_info['TotalThreads']
- result[cpu_id]['type'] = cpu_info['ProcessorType']
- result[cpu_id]['model'] = cpu_info['Model']
- result[cpu_id]['status'] = cpu_info['Status']
- result[cpu_id]['manufacturer'] = cpu_info['Manufacturer']
- self._system['processors'] = normalize_dict(result)
+ self._system['processors'] = self.build_data(fields, 'Processors')
def _update_storage(self) -> None:
- storage_path = self._system['Storage']['@odata.id']
+ fields = ['Description',
+ 'CapacityBytes',
+ 'Model', 'Protocol',
+ 'SerialNumber', 'Status',
+ 'PhysicalLocation']
+ entities = self.get_members('Storage')
log.logger.info("Updating storage")
- storage_info = self._get_path(storage_path)
result: Dict[str, Dict[str, Dict]] = dict()
- for storage in storage_info['Members']:
- entity_path = storage['@odata.id']
- entity_info = self._get_path(entity_path)
- for drive in entity_info['Drives']:
+ for entity in entities:
+ for drive in entity['Drives']:
drive_path = drive['@odata.id']
drive_info = self._get_path(drive_path)
drive_id = drive_info['Id']
result[drive_id] = dict()
- result[drive_id]['description'] = drive_info['Description']
- result[drive_id]['capacity_bytes'] = drive_info['CapacityBytes']
- result[drive_id]['model'] = drive_info['Model']
- result[drive_id]['protocol'] = drive_info['Protocol']
- result[drive_id]['serial_number'] = drive_info['SerialNumber']
- result[drive_id]['status'] = drive_info['Status']
- result[drive_id]['location'] = drive_info['PhysicalLocation']
+ for field in fields:
+ result[drive_id][to_snake_case(field)] = drive_info[field]
+ result[drive_id]['entity'] = entity['Id']
self._system['storage'] = normalize_dict(result)
def _update_metadata(self) -> None:
from redfish_client import RedFishClient
from threading import Thread, Lock
from time import sleep
-from util import Logger, retry
-from typing import Dict, Any
+from util import Logger, retry, normalize_dict, to_snake_case
+from typing import Dict, Any, List
log = Logger(__name__)
raise RuntimeError(f"Could not get path: {path}")
return result
+ def get_members(self, path: str) -> List:
+ _path = self._system[path]['@odata.id']
+ data = self._get_path(_path)
+ return [self._get_path(member['@odata.id']) for member in data['Members']]
+
+ def build_data(self,
+ fields: List,
+ path: str) -> Dict[str, Dict[str, Dict]]:
+ result: Dict[str, Dict[str, Dict]] = dict()
+ for member_info in self.get_members(path):
+ member_id = member_info['Id']
+ result[member_id] = dict()
+ for field in fields:
+ try:
+ result[member_id][to_snake_case(field)] = member_info[field]
+ except KeyError:
+ log.logger.warning(f"Could not find field: {field} in member_info: {member_info}")
+
+ return normalize_dict(result)
+
def start_client(self) -> None:
if not self.client:
self.client = RedFishClient(self.host, self.username, self.password)