From 3f16d45c1e4623349b5ab103fdc1c0984ea0599f Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Fri, 27 Sep 2024 12:28:10 -0400 Subject: [PATCH] Move normalized CPU and power to OEM This permits OEM extensions, and use this to provide data for XCC3 accurately. Change-Id: I67e31839810ddf6740a99cf118e31287ec7fa2ba --- pyghmi/redfish/command.py | 30 +++----------------------- pyghmi/redfish/oem/generic.py | 36 +++++++++++++++++++++++++++++++ pyghmi/redfish/oem/lenovo/xcc3.py | 12 +++++++++++ 3 files changed, 51 insertions(+), 27 deletions(-) diff --git a/pyghmi/redfish/command.py b/pyghmi/redfish/command.py index d4e67b29..967b1132 100644 --- a/pyghmi/redfish/command.py +++ b/pyghmi/redfish/command.py @@ -1195,35 +1195,11 @@ class Command(object): return retval def get_average_processor_temperature(self): - cputemps = [] - for chassis in self.sysinfo.get('Links', {}).get('Chassis', []): - thermals = self._get_thermals(chassis) - for temp in thermals: - if temp.get('PhysicalContext', '') != 'CPU': - continue - if temp.get('ReadingCelsius', None) is None: - continue - cputemps.append(temp['ReadingCelsius']) - if not cputemps: - return SensorReading( - None, {'name': 'Average Processor Temperature'}, value=None, units='°C', - unavailable=True) - avgtemp = sum(cputemps) / len(cputemps) - return SensorReading( - None, {'name': 'Average Processor Temperature'}, value=avgtemp, units='°C') + return self.oem.get_average_processor_temperature(self) + def get_system_power_watts(self): - totalwatts = 0 - gotpower = False - for chassis in self.sysinfo.get('Links', {}).get('Chassis', []): - envinfo = self._get_chassis_env(chassis) - currwatts = envinfo.get('watts', None) - if currwatts is not None: - gotpower = True - totalwatts += envinfo['watts'] - if not gotpower: - raise exc.UnsupportedFunctionality("System does not provide Power under redfish EnvironmentMetrics") - return totalwatts + return self.oem.get_system_power_watts(self) def get_inlet_temperature(self): inlets = [] diff --git a/pyghmi/redfish/oem/generic.py b/pyghmi/redfish/oem/generic.py index aadb2e54..d1874ccd 100644 --- a/pyghmi/redfish/oem/generic.py +++ b/pyghmi/redfish/oem/generic.py @@ -198,6 +198,42 @@ class OEMHandler(object): # nothing programattic to consume to know when to do or not do an expand.. return False + def get_system_power_watts(self, fishclient): + totalwatts = 0 + gotpower = False + for chassis in fishclient.sysinfo.get('Links', {}).get('Chassis', []): + envinfo = fishclient._get_chassis_env(chassis) + currwatts = envinfo.get('watts', None) + if currwatts is not None: + gotpower = True + totalwatts += envinfo['watts'] + if not gotpower: + raise exc.UnsupportedFunctionality("System does not provide Power under redfish EnvironmentMetrics") + return totalwatts + + def _get_cpu_temps(self, fishclient): + cputemps = [] + for chassis in fishclient.sysinfo.get('Links', {}).get('Chassis', []): + thermals = fishclient._get_thermals(chassis) + for temp in thermals: + if temp.get('PhysicalContext', '') != 'CPU': + continue + if temp.get('ReadingCelsius', None) is None: + continue + cputemps.append(temp) + return cputemps + + def get_average_processor_temperature(self, fishclient): + cputemps = self._get_cpu_temps(fishclient) + if not cputemps: + return SensorReading( + None, {'name': 'Average Processor Temperature'}, value=None, units='°C', + unavailable=True) + cputemps = [x['ReadingCelsius'] for x in cputemps] + avgtemp = sum(cputemps) / len(cputemps) + return SensorReading( + None, {'name': 'Average Processor Temperature'}, value=avgtemp, units='°C') + def get_health(self, fishclient, verbose=True): health = fishclient.sysinfo.get('Status', {}) health = health.get('HealthRollup', health.get('Health', 'Unknown')) diff --git a/pyghmi/redfish/oem/lenovo/xcc3.py b/pyghmi/redfish/oem/lenovo/xcc3.py index 0ca7428b..5a3923e4 100644 --- a/pyghmi/redfish/oem/lenovo/xcc3.py +++ b/pyghmi/redfish/oem/lenovo/xcc3.py @@ -10,6 +10,18 @@ class OEMHandler(generic.OEMHandler): def supports_expand(self, url): return True + def get_system_power_watts(self, fishclient): + powerinfo = fishclient._do_web_request('/redfish/v1/Chassis/1/Sensors/power_Sys_Power') + return powerinfo['Reading'] + + def _get_cpu_temps(self, fishclient): + cputemps = [] + for reading in super()._get_cpu_temps(fishclient): + if 'Margin' in reading['Name']: + continue + cputemps.append(reading) + return cputemps + def get_system_configuration(self, hideadvanced=True, fishclient=None): stgs = self._getsyscfg(fishclient)[0] outstgs = {}