From a981b4067cd188bc43ed5dc814ca4bb610386c53 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Thu, 19 Sep 2019 16:41:40 -0400 Subject: [PATCH] Refactor TSM code to common with redfish This gives common access to TSM OEM function to redfish and IPMI (which really is using https here). Should any function come up which absolutely suggests IPMI use in the TSM module, it will be conoditionally enabled by ipmi side and ignored redfish side. Change-Id: I635e3a1cb2f333930a5b8f2e0dc90c08e4ec72d0 --- pyghmi/ipmi/oem/lenovo/handler.py | 10 ++++++++-- pyghmi/redfish/oem/lenovo/main.py | 5 +++++ pyghmi/{ipmi => redfish}/oem/lenovo/tsma.py | 22 ++++++++++++--------- pyghmi/redfish/oem/lookup.py | 3 +++ 4 files changed, 29 insertions(+), 11 deletions(-) rename pyghmi/{ipmi => redfish}/oem/lenovo/tsma.py (94%) diff --git a/pyghmi/ipmi/oem/lenovo/handler.py b/pyghmi/ipmi/oem/lenovo/handler.py index cffc5b96..0c308787 100755 --- a/pyghmi/ipmi/oem/lenovo/handler.py +++ b/pyghmi/ipmi/oem/lenovo/handler.py @@ -37,7 +37,7 @@ from pyghmi.ipmi.oem.lenovo import pci from pyghmi.ipmi.oem.lenovo import psu from pyghmi.ipmi.oem.lenovo import raid_controller from pyghmi.ipmi.oem.lenovo import raid_drive -from pyghmi.ipmi.oem.lenovo import tsma +from pyghmi.redfish.oem.lenovo import tsma import pyghmi.util.webclient as wc @@ -158,7 +158,13 @@ class OEMHandler(generic.OEMHandler): elif self.is_fpc: self.smmhandler = nextscale.SMMClient(ipmicmd) elif self.has_tsma: - self.tsmahandler = tsma.TsmHandler(ipmicmd) + conn = wc.SecureHTTPConnection(ipmicmd.bmc, 443, + verifycallback=self.ipmicmd.certverify) + #sysinfo, sysurl, webclient, cache=None): + self.tsmahandler = tsma.TsmHandler(None, None, conn) + self.tsmahandler.set_credentials( + ipmicmd.ipmi_session.userid.decode('utf-8'), + ipmicmd.ipmi_session.password.decode('utf-8')) @property def _megarac_eth_index(self): diff --git a/pyghmi/redfish/oem/lenovo/main.py b/pyghmi/redfish/oem/lenovo/main.py index f8e599f1..aeb61472 100644 --- a/pyghmi/redfish/oem/lenovo/main.py +++ b/pyghmi/redfish/oem/lenovo/main.py @@ -14,6 +14,7 @@ import pyghmi.redfish.oem.generic as generic from pyghmi.redfish.oem.lenovo import xcc +from pyghmi.redfish.oem.lenovo import tsma def get_handler(sysinfo, sysurl, webclient, cache): @@ -21,4 +22,8 @@ def get_handler(sysinfo, sysurl, webclient, cache): if 'FrontPanelUSB' in leninf or sysinfo.get('SKU', '').startswith('7X58'): return xcc.OEMHandler(sysinfo, sysurl, webclient, cache) else: + leninv = sysinfo.get('Links', {}).get('OEM', {}).get( + 'Lenovo', {}).get('Inventory', {}) + if 'hdd' in leninv and 'hostMAC' in leninv and 'backPlane' in leninv: + return tsma.TsmHandler(sysinfo, sysurl, webclient, cache) return generic.OEMHandler(sysinfo, sysurl, webclient, cache) diff --git a/pyghmi/ipmi/oem/lenovo/tsma.py b/pyghmi/redfish/oem/lenovo/tsma.py similarity index 94% rename from pyghmi/ipmi/oem/lenovo/tsma.py rename to pyghmi/redfish/oem/lenovo/tsma.py index 4f32a4ca..dfc92b44 100644 --- a/pyghmi/ipmi/oem/lenovo/tsma.py +++ b/pyghmi/redfish/oem/lenovo/tsma.py @@ -14,6 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import pyghmi.redfish.oem.generic as generic import pyghmi.util.webclient as webclient import struct import time @@ -64,14 +65,18 @@ def read_hpm(filename): -class TsmHandler(object): - def __init__(self, ipmicmd): - self.ipmicmd = weakref.proxy(ipmicmd) - self.tsm = ipmicmd.bmc - self.username = ipmicmd.ipmi_session.userid.decode('utf-8') - self.password = ipmicmd.ipmi_session.password.decode('utf-8') +class TsmHandler(generic.OEMHandler): + def __init__(self, sysinfo, sysurl, webclient, cache=None): + if cache is None: + cache = {} + self._wc = None + self.username = None + self.password = None self._wc = None self.csrftok = None + super(TsmHandler, self).__init__(sysinfo, sysurl, webclient, cache) + self.tsm = webclient.thehost + self._certverify = webclient._certverify @property def wc(self): @@ -82,7 +87,7 @@ class TsmHandler(object): 'username': self.username, 'password': self.password, } - wc = webclient.SecureHTTPConnection(self.tsm, 443, verifycallback=self.ipmicmd.certverify, timeout=180) + wc = webclient.SecureHTTPConnection(self.tsm, 443, verifycallback=self._certverify, timeout=180) rsp, status = wc.grab_json_response_with_status('/api/session', urllib.urlencode(authdata)) if status < 200 or status >= 300: raise Exception('Error establishing web session') @@ -169,8 +174,7 @@ class TsmHandler(object): 'IS_MMC': 1, } rsp, status = wc.grab_json_response_with_status( - '/api/maintenance/hpm/preparecomponents', payload, - referer='https://{0}/'.format(self.tsm), method='PUT') + '/api/maintenance/hpm/preparecomponents', payload, method='PUT') if status < 200 or status >= 300: err = wc.grab_json_response_with_status( '/api/maintenance/hpm/exitupdatemode', {'FWUPDATEID': uid}, diff --git a/pyghmi/redfish/oem/lookup.py b/pyghmi/redfish/oem/lookup.py index 7b7ea6a1..51f8003d 100644 --- a/pyghmi/redfish/oem/lookup.py +++ b/pyghmi/redfish/oem/lookup.py @@ -23,4 +23,7 @@ def get_oem_handler(sysinfo, sysurl, webclient, cache): for oem in sysinfo.get('Oem', {}): if oem in OEMMAP: return OEMMAP[oem].get_handler(sysinfo, sysurl, webclient, cache) + for oem in sysinfo.get('Links', {}).get('OEM'): + if oem in OEMMAP: + return OEMMAP[oem].get_handler(sysinfo, sysurl, webclient, cache) return generic.OEMHandler(sysinfo, sysurl, webclient, cache)