diff --git a/pyghmi/ipmi/bmc.py b/pyghmi/ipmi/bmc.py index 284d3cbf..93a76907 100644 --- a/pyghmi/ipmi/bmc.py +++ b/pyghmi/ipmi/bmc.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2015 Lenovo # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,12 +12,14 @@ # See the License for the specific language governing permissions and # limitations under the License. +import struct +import traceback + import pyghmi.ipmi.command as ipmicommand import pyghmi.ipmi.console as console import pyghmi.ipmi.private.serversession as serversession import pyghmi.ipmi.private.session as ipmisession -import struct -import traceback + __author__ = 'jjohnson2@lenovo.com' diff --git a/pyghmi/redfish/command.py b/pyghmi/redfish/command.py index 056d8821..40f903cb 100644 --- a/pyghmi/redfish/command.py +++ b/pyghmi/redfish/command.py @@ -23,14 +23,13 @@ from datetime import timedelta from fnmatch import fnmatch import json import os +import re import socket import struct import sys import time from dateutil import tz -import re - import pyghmi.constants as const import pyghmi.exceptions as exc import pyghmi.redfish.oem.lookup as oem diff --git a/pyghmi/redfish/oem/generic.py b/pyghmi/redfish/oem/generic.py index b3076c07..a29292a0 100644 --- a/pyghmi/redfish/oem/generic.py +++ b/pyghmi/redfish/oem/generic.py @@ -14,6 +14,7 @@ import json import os + import pyghmi.exceptions as exc import pyghmi.media as media @@ -59,7 +60,8 @@ class OEMHandler(object): for vminfo in fishclient._do_bulk_requests(vmurls): vminfo = vminfo[0] if vminfo['Image']: - imageurl = vminfo['Image'].replace('/' + vminfo['ImageName'], '') + imageurl = vminfo['Image'].replace( + '/' + vminfo['ImageName'], '') yield media.Media(vminfo['ImageName'], imageurl) elif vminfo['Inserted'] and vminfo['ImageName']: yield media.Media(vminfo['ImageName']) diff --git a/pyghmi/redfish/oem/lenovo/main.py b/pyghmi/redfish/oem/lenovo/main.py index aeb61472..645aa2a2 100644 --- a/pyghmi/redfish/oem/lenovo/main.py +++ b/pyghmi/redfish/oem/lenovo/main.py @@ -13,8 +13,8 @@ # limitations under the License. import pyghmi.redfish.oem.generic as generic -from pyghmi.redfish.oem.lenovo import xcc from pyghmi.redfish.oem.lenovo import tsma +from pyghmi.redfish.oem.lenovo import xcc def get_handler(sysinfo, sysurl, webclient, cache): diff --git a/pyghmi/redfish/oem/lenovo/tsma.py b/pyghmi/redfish/oem/lenovo/tsma.py index 11d6fffa..28e649ad 100644 --- a/pyghmi/redfish/oem/lenovo/tsma.py +++ b/pyghmi/redfish/oem/lenovo/tsma.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2015-2017 Lenovo # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,22 +12,25 @@ # See the License for the specific language governing permissions and # limitations under the License. -import pyghmi.redfish.oem.generic as generic -import pyghmi.exceptions as exc -import pyghmi.media as media -import pyghmi.util.webclient as webclient import struct import time try: from urllib import urlencode except ImportError: from urllib.parse import urlencode -import weakref + +import pyghmi.exceptions as exc +import pyghmi.media as media +import pyghmi.redfish.oem.generic as generic +import pyghmi.util.webclient as webclient hpm_by_filename = {} + class HpmSection(object): - __slots__ = ['comp_id', 'comp_ver', 'comp_name', 'section_flash', 'data', 'hash_size', 'combo_image'] + __slots__ = ['comp_id', 'comp_ver', 'comp_name', 'section_flash', 'data', + 'hash_size', 'combo_image'] + def read_hpm(filename): hpminfo = [] @@ -48,9 +49,11 @@ def read_hpm(filename): currlen = struct.unpack('= 300: raise Exception('Error establishing web session') @@ -210,16 +222,21 @@ class TsmHandler(generic.OEMHandler): else: updatemode = 'flash' rsp = wc.grab_json_response_with_status( - '/api/maintenance/BIOSremoteSave', {"tftpip":"","tftpfile":""}) + '/api/maintenance/BIOSremoteSave', + {"tftpip": "", + "tftpfile": ""} + ) fileupload = 'firmware/BIOS' startit = 'BIOSstart' statusname = 'BIOSstatus' hdrs = wc.stdheaders.copy() hdrs['Content-Length'] = 0 rsp = wc.grab_json_response_with_status( - '/api/maintenance/{0}'.format(updatemode), method='PUT', headers=hdrs) + '/api/maintenance/{0}'.format(updatemode), + method='PUT', headers=hdrs) fu = webclient.FileUploader( - wc, '/api/maintenance/{0}'.format(fileupload), filename, formname='fwimage') + wc, '/api/maintenance/{0}'.format(fileupload), filename, + formname='fwimage') fu.start() while fu.isAlive(): fu.join(3) @@ -229,23 +246,27 @@ class TsmHandler(generic.OEMHandler): 'progress': 100 * wc.get_upload_progress()}) if progress: progress({ - 'phase': 'apply', - 'progress': 0.0}) - rsp = wc.grab_json_response_with_status('/api/maintenance/{0}'.format(startit)) + 'phase': 'apply', + 'progress': 0.0} + ) + rsp = wc.grab_json_response_with_status( + '/api/maintenance/{0}'.format(startit)) applypct = 0.0 if rsp[1] >= 200 and rsp[1] < 300 and rsp[0]['wRet'] == 0: updone = False while not updone: - rsp = wc.grab_json_response('/api/maintenance/{0}'.format(statusname)) + rsp = wc.grab_json_response( + '/api/maintenance/{0}'.format(statusname)) if rsp.get('state', 0) == 9: break if rsp.get('state', 0) in (6, 10): raise Exception('Update Failure') - if (rsp.get('state', 0) == 8 and rsp.get('progress', 0) > 0 - and progress): + if (rsp.get('state', 0) == 8 and + rsp.get('progress', 0) > 0 and progress): progress({ 'phase': 'apply', - 'progress': 70 + float(rsp.get('progress', 0))/100*30}) + 'progress': 70 + float(rsp.get( + 'progress', 0)) / 100 * 30}) elif type == 'bp' and rsp.get('state', 0) == 1: break elif progress and applypct < 70: @@ -290,7 +311,7 @@ class TsmHandler(generic.OEMHandler): rsp, status = wc.grab_json_response_with_status( '/api/maintenance/hpm/preparecomponents', payload, method='PUT') if status < 200 or status >= 300: - err = wc.grab_json_response_with_status( + wc.grab_json_response_with_status( '/api/maintenance/hpm/exitupdatemode', {'FWUPDATEID': uid}, method='PUT') raise Exception(rsp) @@ -336,7 +357,7 @@ class TsmHandler(generic.OEMHandler): percent = rsp['PROGRESS'] if progress: progress({ - 'phase': 'validating', + 'phase': 'validating', 'progress': 0.5 * percent}) if percent < 100: time.sleep(3) @@ -344,7 +365,7 @@ class TsmHandler(generic.OEMHandler): '/api/maintenance/hpm/exitupdatemode', {'FWUPDATEID': uid}, method='PUT') fu = webclient.FileUploader(wc, '/api/maintenance/firmware/firmware', - 'blob', hpminfo[1].combo_image, 'fwimage') + 'blob', hpminfo[1].combo_image, 'fwimage') fu.start() while fu.isAlive(): fu.join(3) @@ -376,7 +397,8 @@ class TsmHandler(generic.OEMHandler): time.sleep(3) hdrs = wc.stdheaders.copy() hdrs['Content-Length'] = 0 - rsp = wc.grab_json_response_with_status('/api/maintenance/reset', method='POST', headers=hdrs) + rsp = wc.grab_json_response_with_status( + '/api/maintenance/reset', method='POST', headers=hdrs) self._wc = None return 'complete' @@ -391,7 +413,8 @@ class TsmHandler(generic.OEMHandler): def detach_remote_media(self): wc = self.wc - slots = wc.grab_json_response('/api/settings/media/remote/configurations') + slots = wc.grab_json_response( + '/api/settings/media/remote/configurations') self._detach_all_media(wc, slots) if not self.isipmi: raise exc.BypassGenericBehavior() @@ -429,7 +452,8 @@ class TsmHandler(generic.OEMHandler): raise exc.UnsupportedFunctionality( 'Cannot mount ISO images from multiple ' 'servers at a time') - if gensettings['cd_remote_source_path'].replace('\\/', '/') != path: + if gensettings['cd_remote_source_path'].replace( + '\\/', '/') != path: raise exc.UnsupportedFunctionality( 'Cannot mount ISO images from different ' 'directories at a time') @@ -444,29 +468,30 @@ class TsmHandler(generic.OEMHandler): self._detach_all_media(wc, slots) if filetype == 1 or (samesettings and currhdds): gensettings['cd_remote_server_address'] = server - gensettings['cd_remote_source_path'] = path #.replace('/', '\\/') + gensettings['cd_remote_source_path'] = path gensettings['cd_remote_share_type'] = 'nfs' gensettings['mount_cd'] = 1 elif filetype == 4: gensettings['same_settings'] = 0 gensettings['hd_remote_server_address'] = server - gensettings['hd_remote_source_path'] = path #.replace('/', '\\/') + gensettings['hd_remote_source_path'] = path gensettings['hd_remote_share_type'] = 'nfs' gensettings['mount_hd'] = 1 gensettings['remote_media_support'] = 1 gensettings['cd_remote_password'] = '' gensettings['hd_remote_password'] = '' - rsp = wc.grab_json_response_with_status('/api/settings/media/general', - gensettings, method='PUT') + wc.grab_json_response_with_status('/api/settings/media/general', + gensettings, method='PUT') # need to calibrate instances correctly - currinfo, status = wc.grab_json_response_with_status('/api/settings/media/instance') + currinfo, status = wc.grab_json_response_with_status( + '/api/settings/media/instance') currinfo['num_cd'] = cdslots currinfo['num_hd'] = hddslots if currinfo['kvm_num_cd'] > cdslots: currinfo['kvm_num_cd'] = cdslots if currinfo['kvm_num_hd'] > hddslots: currinfo['kvm_num_hd'] = hddslots - rsp = wc.grab_json_response_with_status( + wc.grab_json_response_with_status( '/api/settings/media/instance', currinfo, method='PUT') images = wc.grab_json_response('/api/settings/media/remote/images') tries = 20 @@ -509,7 +534,8 @@ class TsmHandler(generic.OEMHandler): hds = rsp['hd_remote_server_address'] hdpath = rsp['hd_remote_source_path'] hdproto = rsp['hd_remote_share_type'] - slots = wc.grab_json_response('/api/settings/media/remote/configurations') + slots = wc.grab_json_response( + '/api/settings/media/remote/configurations') for slot in slots: if slot['redirection_status'] == 1: url = None @@ -554,9 +580,9 @@ class TsmHandler(generic.OEMHandler): else: if currtypeenabled: raise exc.UnsupportedFunctionality( - 'This system cannot mount images from different locations at the same time') + 'This system cannot mount images ' + 'from different locations at the same time') img = None - myslot = None for slot in mountslots: if slot['media_type'] != filetype: continue diff --git a/pyghmi/redfish/oem/lookup.py b/pyghmi/redfish/oem/lookup.py index 51f8003d..284802ca 100644 --- a/pyghmi/redfish/oem/lookup.py +++ b/pyghmi/redfish/oem/lookup.py @@ -19,6 +19,7 @@ OEMMAP = { 'Lenovo': lenovo, } + def get_oem_handler(sysinfo, sysurl, webclient, cache): for oem in sysinfo.get('Oem', {}): if oem in OEMMAP: