From 4454c64f94bb2fd93ed796a832dedb42faecf3f9 Mon Sep 17 00:00:00 2001 From: Guillaume Abrioux Date: Thu, 6 Apr 2023 17:29:28 +0200 Subject: [PATCH] node-proxy: split RedfishSystem class This class should be split because the logic will be different depending on the hardware. Signed-off-by: Guillaume Abrioux --- src/cephadm/node-proxy/redfish_dell.py | 82 ++++++++++++++++++++++++ src/cephadm/node-proxy/redfish_system.py | 81 ++++------------------- src/cephadm/node-proxy/server.py | 4 +- src/cephadm/node-proxy/system.py | 21 +++--- 4 files changed, 108 insertions(+), 80 deletions(-) create mode 100644 src/cephadm/node-proxy/redfish_dell.py diff --git a/src/cephadm/node-proxy/redfish_dell.py b/src/cephadm/node-proxy/redfish_dell.py new file mode 100644 index 0000000000000..9a611fb7bbe1a --- /dev/null +++ b/src/cephadm/node-proxy/redfish_dell.py @@ -0,0 +1,82 @@ +from redfish_system import RedfishSystem +from util import logger + +log = logger(__name__) + + +class RedfishDell(RedfishSystem): + def __init__(self, **kw): + if kw.get('system_endpoint') is None: + kw['system_endpoint'] = '/Systems/System.Embedded.1' + super().__init__(**kw) + + def _update_network(self): + net_path = self._system['EthernetInterfaces']['@odata.id'] + log.info("Updating network") + network_info = self.client.get_path(net_path) + self._system['network'] = {} + result = dict() + for interface in network_info['Members']: + interface_path = interface['@odata.id'] + interface_info = self.client.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'] = result + + def _update_processors(self): + cpus_path = self._system['Processors']['@odata.id'] + log.info("Updating processors") + cpus_info = self.client.get_path(cpus_path) + self._system['processors'] = {} + result = dict() + for cpu in cpus_info['Members']: + cpu_path = cpu['@odata.id'] + cpu_info = self.client.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'] = result + + def _update_storage(self): + storage_path = self._system['Storage']['@odata.id'] + log.info("Updating storage") + storage_info = self.client.get_path(storage_path) + result = dict() + for storage in storage_info['Members']: + entity_path = storage['@odata.id'] + entity_info = self.client.get_path(entity_path) + for drive in entity_info['Drives']: + drive_path = drive['@odata.id'] + drive_info = self.client.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'] + self._system['storage'] = result + + def _update_metadata(self): + log.info("Updating metadata") + pass + + def _update_memory(self): + log.info("Updating memory") + pass + + def _update_power(self): + log.info("Updating power") + pass diff --git a/src/cephadm/node-proxy/redfish_system.py b/src/cephadm/node-proxy/redfish_system.py index 483bdb90a7aef..df012aa964f8f 100644 --- a/src/cephadm/node-proxy/redfish_system.py +++ b/src/cephadm/node-proxy/redfish_system.py @@ -9,18 +9,17 @@ log = logger(__name__) class RedfishSystem(System): - def __init__(self, - host, - username, - password, - system_endpoint='/Systems/1'): - log.info(f"redfish system initialization, host: {host}, user: {username}") - self.client = RedFishClient(host, username, password) + def __init__(self, **kw): + self.host = kw.get('host') + self.username = kw.get('username') + self.password = kw.get('password') + self.system_endpoint = kw.get('system_endpoint', '/Systems/1') + log.info(f"redfish system initialization, host: {self.host}, user: {self.username}") + self.client = RedFishClient(self.host, self.username, self.password) self.client.login() self._system = {} self.run = False self.thread = None - self.system_endpoint = system_endpoint def get_system(self): return self._system @@ -54,76 +53,22 @@ class RedfishSystem(System): self._system = self._process_redfish_system(redfish_system) def _update_metadata(self): - log.info("Updating metadata") - pass + raise NotImplementedError() def _update_memory(self): - log.info("Updating memory") - pass + raise NotImplementedError() def _update_power(self): - log.info("Updating power") - pass + raise NotImplementedError() def _update_network(self): - net_path = self._system['EthernetInterfaces']['@odata.id'] - log.info("Updating network") - network_info = self.client.get_path(net_path) - self._system['network'] = {} - result = dict() - for interface in network_info['Members']: - interface_path = interface['@odata.id'] - interface_info = self.client.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'] = result + raise NotImplementedError() def _update_processors(self): - cpus_path = self._system['Processors']['@odata.id'] - log.info("Updating processors") - cpus_info = self.client.get_path(cpus_path) - self._system['processors'] = {} - result = dict() - for cpu in cpus_info['Members']: - cpu_path = cpu['@odata.id'] - cpu_info = self.client.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'] = result - + raise NotImplementedError() def _update_storage(self): - storage_path = self._system['Storage']['@odata.id'] - log.info("Updating storage") - storage_info = self.client.get_path(storage_path) - result = dict() - for storage in storage_info['Members']: - entity_path = storage['@odata.id'] - entity_info = self.client.get_path(entity_path) - for drive in entity_info['Drives']: - drive_path = drive['@odata.id'] - drive_info = self.client.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'] - self._system['storage'] = result + raise NotImplementedError() def start_update_loop(self): self.run = True diff --git a/src/cephadm/node-proxy/server.py b/src/cephadm/node-proxy/server.py index 11ce48890d94d..f450f05239572 100644 --- a/src/cephadm/node-proxy/server.py +++ b/src/cephadm/node-proxy/server.py @@ -1,6 +1,6 @@ from flask import Flask, request, jsonify from system import System -from redfish_system import RedfishSystem +from redfish_dell import RedfishDell from reporter import Reporter from util import logger import time @@ -14,7 +14,7 @@ password = "mypassword" # create the redfish system and the obsever log.info(f"Server initialization...") -system = RedfishSystem(host, username, password, system_endpoint='/Systems/System.Embedded.1') +system = RedfishDell(host=host, username=username, password=password, system_endpoint='/Systems/System.Embedded.1') reporter_agent = Reporter(system, "http://127.0.0.1:8000") app = Flask(__name__) diff --git a/src/cephadm/node-proxy/system.py b/src/cephadm/node-proxy/system.py index cab408d1a7fd3..1b70bcd2492de 100644 --- a/src/cephadm/node-proxy/system.py +++ b/src/cephadm/node-proxy/system.py @@ -1,29 +1,30 @@ - +from util import Config class System: - def __init__(self): + def __init__(self, **kw): self._system = {} + self.config: Config = kw['config'] def get_system(self): - return self._system + raise NotImplementedError() def get_status(self): - return self._system['status'] + raise NotImplementedError() def get_metadata(self): - return self._system['metadata'] + raise NotImplementedError() def get_processors(self): - return self._system['processors'] + raise NotImplementedError() def get_memory(self): - return self._system['memory'] + raise NotImplementedError() def get_power(self): - return self._system['power'] + raise NotImplementedError() def get_network(self): - return self._system['network'] + raise NotImplementedError() def get_storage(self): - return self._system['storage'] + raise NotImplementedError() -- 2.39.5