From 0f70401ad6608a77aeade6486c0eba82e997d059 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Thu, 21 May 2026 10:59:19 -0400 Subject: [PATCH] Port pyghmi fixes forward --- .../aiohmi/ipmi/oem/lenovo/imm.py | 4 +-- confluent_server/aiohmi/redfish/command.py | 2 +- .../aiohmi/redfish/oem/ami/megarac.py | 27 +++++++++++++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/confluent_server/aiohmi/ipmi/oem/lenovo/imm.py b/confluent_server/aiohmi/ipmi/oem/lenovo/imm.py index 02b58260..8657b30a 100644 --- a/confluent_server/aiohmi/ipmi/oem/lenovo/imm.py +++ b/confluent_server/aiohmi/ipmi/oem/lenovo/imm.py @@ -893,7 +893,7 @@ class IMMClient(object): try: fpga = await self.ipmicmd.raw_command(netfn=0x3a, command=0x6b, data=(0,)) - fpga = '{0}.{1}.{2}'.format(*bytearray(fpga['data'])) + fpga = '{0:x}.{1:x}.{2:x}'.format(*bytearray(fpga['data'])) yield ('FPGA', {'version': fpga}) except pygexc.IpmiException as ie: if ie.ipmicode != 193: @@ -1938,7 +1938,7 @@ class XCCClient(IMMClient): try: fpga = await self.ipmicmd.raw_command(netfn=0x3a, command=0x6b, data=(0,)) - fpga = '{0}.{1}.{2}'.format( + fpga = '{0:x}.{1:x}.{2:x}'.format( *struct.unpack('BBB', fpga['data'])) yield 'FPGA', {'version': fpga} except pygexc.IpmiException as ie: diff --git a/confluent_server/aiohmi/redfish/command.py b/confluent_server/aiohmi/redfish/command.py index 87aaae76..72a97a96 100644 --- a/confluent_server/aiohmi/redfish/command.py +++ b/confluent_server/aiohmi/redfish/command.py @@ -1117,7 +1117,7 @@ class Command(object): cidr = _mask_to_cidr(currip['SubnetMask']) retval['ipv4_address'] = '{0}/{1}'.format(currip['Address'], cidr) retval['mac_address'] = netcfg['MACAddress'] - hasgateway = _mask_to_cidr(currip['Gateway']) + hasgateway = _mask_to_cidr(currip['Gateway']) if currip.get('Gateway', None) else None retval['ipv4_gateway'] = currip['Gateway'] if hasgateway else None retval['ipv4_configuration'] = currip['AddressOrigin'] tagged = netcfg.get('VLAN', {}).get('VLANEnable', False) diff --git a/confluent_server/aiohmi/redfish/oem/ami/megarac.py b/confluent_server/aiohmi/redfish/oem/ami/megarac.py index 366413ba..63ebdd8a 100644 --- a/confluent_server/aiohmi/redfish/oem/ami/megarac.py +++ b/confluent_server/aiohmi/redfish/oem/ami/megarac.py @@ -13,6 +13,8 @@ # limitations under the License. import aiohmi.redfish.oem.generic as generic +import aiohmi.util.webclient as webclient +from urllib.parse import urlencode class OEMHandler(generic.OEMHandler): @@ -28,4 +30,29 @@ class OEMHandler(generic.OEMHandler): sysurl = system['@odata.id'] break self._varsysurl = sysurl + self._wc = None + self.bmc = webclient.thehost + self._certverify = webclient.verifycallback return self + + + async def get_wc(self): + self.fwid = None + if self._wc: + rsp, status = await self._wc.grab_json_response_with_status('/api/chassis-status') + if status == 200: + return self._wc + authdata = { + 'username': self.username, + 'password': self.password + } + wc = webclient.WebConnection(self.bmc, 443, verifycallback=self._certverify) + wc.set_header('Content-Type', 'application/x-www-form-urlencoded') + rsp, status = await wc.grab_json_response_with_status('/api/session', method='POST', data=urlencode(authdata)) + if status < 200 or status >= 300: + raise Exception('Failed to authenticate to BMC') + if 'CSRFToken' in rsp: + self.csrftok = rsp['CSRFToken'] + wc.set_header('X-CSRF-Token', rsp['CSRFToken']) + self._wc = wc + return wc