def applyfwpkg(self, options, tempdir, components, comptype): """ Apply the component to iLO :param options: command line options :type options: list. :param tempdir: path to temp directory :type tempdir: string. :param components: components to upload :type components: list. :param comptype: type of component. Either A,B,C, or D. :type comptype: str. """ for component in components: taskqueuecommand = ' create %s ' % os.path.basename(component) if options.tover: taskqueuecommand = ' create %s --tpmover' % os.path.basename( component) if component.endswith('.fwpkg') or component.endswith('.zip'): uploadcommand = '--component %s' % component else: uploadcommand = '--component %s' % os.path.join( tempdir, component) if options.forceupload: uploadcommand += ' --forceupload' if comptype in ['A', 'B']: uploadcommand += ' --update_target --update_repository' sys.stdout.write("Uploading firmware: %s\n" % os.path.basename(component)) try: self.uploadobj.run(uploadcommand) except UploadError: if comptype in ['A', 'B']: select = self.typepath.defs.hpilofirmwareupdatetype results = self._rdmc.app.select(selector=select) try: results = results[0] except: pass if results: update_path = results.resp.request.path error = self._rdmc.app.get_handler(update_path, silent=True) self.fwupdateobj.printerrmsg(error) else: raise FirmwareUpdateError( "Error occurred while updating the firmware.") else: raise UploadError('Error uploading component.') if comptype == 'C': sys.stdout.write( "Setting a taskqueue item to flash UEFI flashable firmware.\n" ) self.taskqueueobj.run(taskqueuecommand)
def printerrmsg(self, error): """ raises and prints the detailed error message if possible """ output = "Error occurred while updating the firmware." try: error = error.dict['Oem']['Hpe']['Result']['MessageId'].split('.') errmessages = self._rdmc.app.get_error_messages() for messagetype in list(errmessages.keys()): if error[0] == messagetype: if errmessages[messagetype][error[-1]]["NumberOfArgs"] == 0: output = "Firmware update error. %s" % \ errmessages[messagetype][error[-1]]["Message"] else: output = "Firmware update error. %s" % \ errmessages[messagetype][error[-1]]["Description"] break except: pass raise FirmwareUpdateError(output)
def printerrmsg(self, error): """ raises and prints the detailed error message if possible """ output = "Error occurred while updating the firmware." try: error = error.dict['Oem']['Hpe']['Result']['MessageId'].split('.') #TODO: Update to new ResponseHandler Method 'return_reg' errmessages = ResponseHandler(self.rdmc.app.validation_manager,\ self.rdmc.app.typepath.defs.messageregistrytype).get_error_messages() for messagetype in list(errmessages.keys()): if error[0] == messagetype: if errmessages[messagetype][ error[-1]]["NumberOfArgs"] == 0: output = "Firmware update error. %s" % \ errmessages[messagetype][error[-1]]["Message"] else: output = "Firmware update error. %s" % \ errmessages[messagetype][error[-1]]["Description"] break except: pass raise FirmwareUpdateError(output)
def showupdateprogress(self, path): """ handler function for updating the progress :param path: path to update service. :tyep path: str """ counter = 0 written = False uploadingpost = False spinner = ['|', '/', '-', '\\'] position = 0 while True: if counter == 100: raise FirmwareUpdateError( "Error occurred while updating the firmware.") else: counter += 1 results = self._rdmc.app.get_handler(path, silent=True) results = results.dict try: results = results['Oem']['Hpe'] except: pass if not results: raise FirmwareUpdateError("Unable to contact Update Service. " \ "Please re-login and try again.") if results["State"].lower().startswith("idle"): time.sleep(2) elif results["State"].lower().startswith("uploading"): counter = 0 if not uploadingpost: uploadingpost = True else: if not written: written = True sys.stdout.write( "iLO is uploading the necessary files. Please wait..." ) time.sleep(0.5) elif results["State"].lower().startswith(("progressing", \ "updating", "verifying", "writing")): counter = 0 for _ in range(2): if position < 4: sys.stdout.write("Updating: " + spinner[position] + "\r") position += 1 time.sleep(0.1) else: position = 0 sys.stdout.write("Updating: " + spinner[position] + "\r") position += 1 time.sleep(0.1) elif results["State"].lower().startswith("complete"): sys.stdout.write('\n\nFirmware update has completed and iLO' \ ' may reset. \nIf iLO resets the' \ ' session will be terminated.\nPlease wait' \ ' for iLO to initialize completely before' \ ' logging in again.\nA reboot may be required'\ ' for firmware changes to take effect.\n') break elif results["State"].lower().startswith("error"): error = self._rdmc.app.get_handler(path, silent=True) self.printerrmsg(error)