def addprofileandstartjob(self, options): """ Adds ip profile into the job queue and start it. :return returncode: int """ ipprovider = self.hasipprovider() if ipprovider is None: raise PathUnavailableError(u"System does not support this feature of IP.\n") ipjob = self.hasipjobs() if not ipjob: raise InvalidFileFormattingError(u"System does not have any IP"\ u" profile to copy to the job queue.\n") current_state = self.inipstate(ipprovider) if current_state is None: raise PathUnavailableError(u"System does not support this feature of IP.\n") later_state = False ipstate = current_state["InIP"] if isinstance(ipstate, bool) and ipstate: #make sure we are in IP state. Reset and monitor self.resetinipstate(ipprovider, current_state) #if we are in ip, monitor should be fast, use 15 seconds later_status = self.monitorinipstate(ipprovider, 3) if later_status: self.copyjobtoipqueue(ipjob) sys.stdout.write(u"Copy operation was successful...\n") return ReturnCodes.SUCCESS if not isinstance(ipstate, bool): # inip is in an unknown state, so ... #patch to false, reboot, then monitor...if it turns true later... #then we are in IP state otherwise, manually check system... self.resetinipstate(ipprovider, current_state) later_status = self.monitorinipstate(ipprovider, 3) if later_status: self.copyjobtoipqueue(ipjob) sys.stdout.write(u"Copy operation was successful...\n") return ReturnCodes.SUCCESS try: self.bootorderobj.run("--onetimeboot=Utilities "\ "--reboot=ColdBoot --commit") except: raise InvalidFileFormattingError(u"System failed to reboot") #After reboot, login again self.validation(options) later_state = self.monitorinipstate(ipprovider) if later_state: self.copyjobtoipqueue(ipjob) sys.stdout.write(u"Copy operation was successful...\n") else: raise InvalidFileFormattingError(u"\nSystem reboot took longer than 4 minutes."\ u"something is wrong. You need to physically check this system.\n") return ReturnCodes.SUCCESS
def get_running_job(self): """ Retrieves and decodes, running job :return returncode: int """ results = self._rdmc.app.get_handler(self.running_jobs, silent=True) if results.status == 404: raise PathUnavailableError("The Intelligent Provisioning resource "\ "is not available on this system. You may need"\ " to run IP at least once to add the resource.") if results and results.status == 200: j2python = json.loads(results.read) for _, val in enumerate(j2python.keys()): if isinstance(val, six.string_types): result = self.decode_base64_string(str(j2python[val])) if result is not None: j2python[val] = result results.read = json.dumps(j2python, ensure_ascii=False) if results.dict: UI().print_out_json(results.dict) else: sys.stdout.write("No IP profiles found\n")
def run(self, line): """ wrapper function for main login function :param line: command line input :type line: string. """ try: self.loginfunction(line) if ("-h" in line) or ("--help" in line): return ReturnCodes.SUCCESS if not self._rdmc.app.current_client.monolith._visited_urls: self.logoutobj.run("") raise PathUnavailableError("The path specified by the --path"\ " flag is unavailable.") except Exception, excp: raise excp
def getipprofiledataanddecode(self, options): """ Retrieves and decodes, if encoded, data from hpeprofile data store :param options: command line options :type options: list. :return returncode: int """ results = self._rdmc.app.get_handler(self.path, silent=True, response=True) if results.status == 404: raise PathUnavailableError("The Intelligent Provisioning resource "\ "is not available on this system. You may need"\ " to run IP at least once to add the resource.") if results and results.status == 200: j2python = json.loads(results.read) for _, val in enumerate(j2python.keys()): if isinstance(val, six.string_types): result = self.decode_base64_string(str(j2python[val])) if result is not None: j2python[val] = result results.read = json.dumps(j2python, ensure_ascii=False, sort_keys=True) if results.dict: if options.filename: output = json.dumps(results.dict, indent=2, cls=redfish.ris.JSONEncoder, \ sort_keys=True) filehndl = open(options.filename[0], "w") filehndl.write(output) filehndl.close() sys.stdout.write("Results written out to '%s'.\n" % options.filename[0]) else: UI().print_out_json(results.dict) else: sys.stdout.write("No IP profiles found\n")
def get_hvt_output(self): """ Retrieves and decodes, running job :return returncode: int """ return_value = {} results = self._rdmc.app.get_handler(self.hvt_output, silent=True, response=True) if results.status == 404: raise PathUnavailableError("The Intelligent Provisioning resource "\ "is not available on this system. You may need"\ " to run IP at least once to add the resource.") if results and results.status == 200: j2python = json.loads(results.read) for _, val in enumerate(j2python.keys()): if isinstance(val, six.string_types) and '@' not in val: return_value = json.loads(self.decode_base64_string(str(j2python[val]))) UI().print_out_json(return_value) else: sys.stdout.write("No IP profiles found\n")
def getipprofiledataanddecode(self, options): """ Retrieves and decodes, if encoded, data from hpeprofile data store :param options: command line options :type options: list. :return returncode: int """ try: results = self._rdmc.app.get_handler(self.path, \ verbose=self._rdmc.opts.verbose, silent=True) except: raise PathUnavailableError("The Intelligent Provisioning resource "\ "is not available on this system.") j2python = json.loads(results.read) for _, val in enumerate(j2python.keys()): if isinstance(val, basestring): result = self.decode_base64_string(str(j2python[val])) if result is not None: j2python[val] = result results.read = json.dumps(j2python, ensure_ascii=False) if results and results.status == 200: if results.dict: if options.filename: output = json.dumps(results.dict, indent=2,\ cls=redfish.ris.JSONEncoder) filehndl = open(options.filename[0], "w") filehndl.write(output) filehndl.close() sys.stdout.write(u"Results written out to '%s'.\n" % \ options.filename[0]) else: UI().print_out_json(results.dict) else: return ReturnCodes.NO_CONTENTS_FOUND_FOR_OPERATION