]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
node-proxy: split RedfishSystem class
authorGuillaume Abrioux <gabrioux@ibm.com>
Thu, 6 Apr 2023 15:29:28 +0000 (17:29 +0200)
committerGuillaume Abrioux <gabrioux@ibm.com>
Thu, 25 Jan 2024 14:43:29 +0000 (14:43 +0000)
This class should be split because the logic will be different depending on the
hardware.

Signed-off-by: Guillaume Abrioux <gabrioux@ibm.com>
src/cephadm/node-proxy/redfish_dell.py [new file with mode: 0644]
src/cephadm/node-proxy/redfish_system.py
src/cephadm/node-proxy/server.py
src/cephadm/node-proxy/system.py

diff --git a/src/cephadm/node-proxy/redfish_dell.py b/src/cephadm/node-proxy/redfish_dell.py
new file mode 100644 (file)
index 0000000..9a611fb
--- /dev/null
@@ -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
index 483bdb90a7aefb506e0882a63a6fc03739509526..df012aa964f8f13d04bc4a9c2462ecbd43dbc858 100644 (file)
@@ -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
index 11ce48890d94d54ef656d25ff71b101536ddae29..f450f052395727920338ff1208e82e00bfe1f41d 100644 (file)
@@ -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__)
index cab408d1a7fd318ff1e9bfc6d43835b2984a9a30..1b70bcd2492defc4436cbfc35416d951a35dda23 100644 (file)
@@ -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()