2
0
mirror of https://opendev.org/x/pyghmi synced 2025-01-27 19:37:44 +00:00

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
This commit is contained in:
Jarrod Johnson 2019-09-19 16:41:40 -04:00
parent 8a594e4640
commit a981b4067c
4 changed files with 29 additions and 11 deletions

View File

@ -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):

View File

@ -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)

View File

@ -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},

View File

@ -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)