def controlbmcpower(client, parser, args): ''' #==================================================================== # @Description: control BMC power entry # @Method: postbmcpower # @Param: # @Return: # @Date: #==================================================================== ''' if parser is None or args is None: return None slotid = client.get_slotid() if slotid is None: return None url = "/redfish/v1/Managers/%s/Actions/Manager.Reset" % slotid payload = {"ResetType": "ForceRestart"} resp = client.create_resource(url, payload) if resp is None: return None if resp.get('status_code') == 200: print('Success: successfully completed request') else: if resp.get('status_code') == 400: msg = resp['message']['error']['@Message.ExtendedInfo'] \ [0]['Message'] print('Failure:' + msg) else: upgrade_sp.print_status_code(resp) return resp
def _setbootsequence(payload, client, slotid, sequence, parser): ''' #========================================================================= # @Description: set boot sequence # @Method: _setbootsequence # @Param: # @Return: # @Date: #========================================================================= ''' if _checkbootsequence(sequence) is False: parser.error('Failure: four parameters that are not duplicate ' + \ 'must be specified for the system boot order.') url = "/redfish/v1/Systems/%s/Bios/Settings" % slotid resp = client.get_resource(url) if resp.get('status_code') == 200: attributes = resp['resource']['Attributes'] if attributes is None: attributes = {} payloads = {"Attributes": attributes} for i in range(0, 4): value = _sequencev3tov5(sequence[i]) payloads['Attributes']["BootTypeOrder%s" % i] = value resp = client.set_resource(url, payloads, timeout=65) if resp is None: return None elif resp.get('status_code') == 200: return 'Success' else: upgrade_sp.print_status_code(resp) return resp else: value = [sequence[0], sequence[1], sequence[2], sequence[3]] payload['BootupSequence'] = value return resp
def controlospower(client, parser, args): ''' #========================================================================= # @Description: control os power entry # @Method: controlospower # @Param: # @Return: # @Date: #========================================================================= ''' if parser is None or args is None: return None slotid = client.get_slotid() if slotid is None: return None url = "/redfish/v1/systems/%s/Actions/ComputerSystem.Reset" % slotid payload = {"ResetType": args.ResetType} resp = client.create_resource(url, payload) if resp is None: return None if resp['status_code'] == 200: print('Success: successfully completed request') else: if resp['status_code'] == 400: # messages = resp['message']['error']['@Message.ExtendedInfo'] # print(messages) # ResetOperationNotAllowed print('Failure: operation not allowed') else: upgrade_sp.print_status_code(resp) return resp
def getbios(client, parser, args): ''' #===================================================================== # @Method: BIOS menu item query subcommand processing functions # @Param: client, RedfishClient object parser, subcommand argparser. Export error messages when parameters are incorrect. args, parameter list # @Return: # @author: # @date: 2017-8-30 09:04:14 #===================================================================== ''' if parser is None and args is None: return None slotid = client.get_slotid() if slotid is None: return None url = "/redfish/v1/Systems/%s/Bios" % slotid resp = client.get_resource(url) if resp is None: return None if resp['status_code'] == 200: info = resp['resource']['Attributes'] if info is None: print('no data available for the resource') return resp print_resource(info, args, parser) elif resp['status_code'] == 404: print('Failure: resource was not found') else: upgrade_sp.print_status_code(resp) return resp
def get_upgrade_progress(client): ''' #===================================================================== # @Method: Obtain the in-band upgrade progress # @Param: client, RedfishClient object # @Return: # @author: #===================================================================== ''' url = "/redfish/v1/Sms/1/UpdateService/Progress" resp = client.get_resource(url) if resp is None: return None if resp['status_code'] != 200: upgrade_sp.print_status_code(resp) return resp status = resp['resource']['Status'] while status == 'done' or status == 'uploading' \ or status == 'tobeupgraded' or status == 'preprocessing': # sys.stdout.write("Progress: 0%\r") # sys.stdout.flush() time.sleep(1) resp = client.get_resource(url) if resp is None: return None if resp['status_code'] != 200: upgrade_sp.print_status_code(resp) return resp status = resp['resource']['Status'] while status == 'upgrading': progress = resp['resource']['Progress'] # sys.stdout.write("Progress: %d%%\r" % int(float(progress))) # sys.stdout.flush() time.sleep(1) resp = client.get_resource(url) if resp is None: return None if resp['status_code'] != 200: upgrade_sp.print_status_code(resp) return resp status = resp['resource']['Status'] flag = suc_or_fail_proc(status, resp) if not flag: sys.exit(144) return resp
def setsysboot(client, parser, args): ''' #========================================================================= # @Description: set system boot information # @Method: setsysboot # @Param: # @Return: # @Date: #========================================================================= ''' slotid = client.get_slotid() if slotid is None: return None if args.target is None and args.tenabled is None and args.mode is None and \ args.menabled is None and args.sequence is None: parser.error('at least one parameter must be specified') return None url = "/redfish/v1/systems/%s" % slotid resp = client.get_resource(url) boot = {} huawei = {} if args.target is not None: boot['BootSourceOverrideTarget'] = args.target if args.tenabled is not None: boot['BootSourceOverrideEnabled'] = args.tenabled if args.mode is not None: boot['BootSourceOverrideMode'] = args.mode bootEnablekey = "BootModeChangeEnabled" if resp['status_code'] == 200: if "BootModeChangeEnabled" in resp['resource']['Oem']['Huawei'].keys(): bootEnablekey = "BootModeChangeEnabled" if "BootModeConfigOverIpmiEnabled" in resp['resource']['Oem'][ 'Huawei'].keys(): bootEnablekey = "BootModeConfigOverIpmiEnabled" if args.menabled is not None: huawei[bootEnablekey] = _stringtobool(args.menabled) ret = None if args.sequence is not None: ret = _setbootsequence(huawei, client, slotid, args.sequence, parser) if ret != 'Success': return ret payload = _makepayload(boot, huawei) if payload is None and ret == 'Success': print('Success: successfully completed request') return resp if resp.get('status_code') != 200: return resp resp = client.set_resource(url, payload) if resp is None: return None if resp['status_code'] == 200: # Some of the settings failed if resp['resource'].get('@Message.ExtendedInfo') is not None: messages = resp['resource']['@Message.ExtendedInfo'] _printferrormessages(1, messages, bootEnablekey) sys.exit(144) # Success else: print('Success: successfully completed request') else: # Failure if resp['status_code'] == 400: messages = resp['message']['error']['@Message.ExtendedInfo'] _printferrormessages(0, messages, bootEnablekey) else: upgrade_sp.print_status_code(resp) return resp