def run(self, line): """ Main update task queue worker function :param line: string of arguments passed in :type line: str. """ try: (options, _) = self._parse_arglist(line, default=True) except (InvalidCommandLineErrorOPTS, SystemExit): if ("-h" in line) or ("--help" in line): return ReturnCodes.SUCCESS else: raise InvalidCommandLineErrorOPTS("") self.updatetaskqueuevalidation(options) if self.typepath.defs.isgen9: raise IncompatibleiLOVersionError(\ 'iLO Repository commands are only available on iLO 5.') if options.command.lower() == 'create': self.createtask(options.keywords.split(), options) else: if options.resetqueue: self.resetqueue() elif options.cleanqueue: self.cleanqueue() self.printqueue(options) logout_routine(self, options) #Return code return ReturnCodes.SUCCESS
def run(self, line): """ Main sigrecompute function :param line: string of arguments passed in :type line: str. """ try: (options, args) = self._parse_arglist(line) except (InvalidCommandLineErrorOPTS, SystemExit): if ("-h" in line) or ("--help" in line): return ReturnCodes.SUCCESS else: raise InvalidCommandLineErrorOPTS("") if args: raise InvalidCommandLineError( "Sigrecompute command takes no arguments.") self.sigrecomputevalidation(options) path = self.typepath.defs.systempath if self.typepath.defs.flagforrest: body = {"Action": "ServerSigRecompute", "Target": "/Oem/Hp"} self._rdmc.app.post_handler(path, body) else: raise IncompatibleiLOVersionError( "Sigrecompute action not available on redfish.") logout_routine(self, options) #Return code return ReturnCodes.SUCCESS
def run(self, line): """ Main installset worker function :param line: string of arguments passed in :type line: str. """ try: (options, args) = self._parse_arglist(line) except (InvalidCommandLineErrorOPTS, SystemExit): if ("-h" in line) or ("--help" in line): return ReturnCodes.SUCCESS else: raise InvalidCommandLineErrorOPTS("") self.loggedin = None self.comps = None self.loggedin = self.minstallsetvalidation() if self.loggedin and self.typepath.defs.isgen9: raise IncompatibleiLOVersionError('iLO Repository commands are ' \ 'only available on iLO 5.') sys.stdout.write("Warning: This command will run in interactive mode.\n") if args: raise InvalidCommandLineError("makeinstallset command takes no arguments.") self.minstallsetworker(options) logout_routine(self, options) #Return code return ReturnCodes.SUCCESS
def run(self, line): """ Main update maintenance window worker function :param line: string of arguments passed in :type line: str. """ try: (options, _) = self._parse_arglist(line, default=True) except (InvalidCommandLineErrorOPTS, SystemExit): if ("-h" in line) or ("--help" in line): return ReturnCodes.SUCCESS else: raise InvalidCommandLineErrorOPTS("") self.maintenancewindowvalidation(options) if self.typepath.defs.isgen9: raise IncompatibleiLOVersionError(\ 'iLO Repository commands are only available on iLO 5.') windows = self._rdmc.app.getcollectionmembers(\ '/redfish/v1/UpdateService/MaintenanceWindows/') if options.command.lower() == 'add': self.addmaintenancewindow(options, windows, options.time_window) elif options.command.lower() == 'delete': self.deletemaintenancewindow(windows, options.identifier) else: self.listmainenancewindows(options, windows) logout_routine(self, options) #Return code return ReturnCodes.SUCCESS
def run(self, line): """Main ilolicense Function :param line: string of arguments passed in :type line: str. """ try: (options, args) = self._parse_arglist(line) except (InvalidCommandLineErrorOPTS, SystemExit): if ("-h" in line) or ("--help" in line): return ReturnCodes.SUCCESS else: raise InvalidCommandLineErrorOPTS("") self.addlicensevalidation(options) if not len(args) == 1: raise InvalidCommandLineError( "ilolicense command only takes one argument") path = self.typepath.defs.addlicensepath body = {"LicenseKey": "%s" % args[0]} self._rdmc.app.post_handler(path, body) logout_routine(self, options) #Return code return ReturnCodes.SUCCESS
def run(self, line): """Main serverstate function :param line: string of arguments passed in :type line: str. """ try: (options, args) = self._parse_arglist(line) except (InvalidCommandLineErrorOPTS, SystemExit): if ("-h" in line) or ("--help" in line): return ReturnCodes.SUCCESS else: raise InvalidCommandLineErrorOPTS("") if args: raise InvalidCommandLineError("Invalid number of parameters, "\ "serverstate command does not take any parameters.") self.serverstatevalidation(options) path = self.typepath.defs.systempath results = self._rdmc.app.get_handler(path, silent=True, uncache=True).dict if results: results = results['Oem'][self.typepath.defs.oemhp]['PostState'] sys.stdout.write("The server is currently in state: " + results + '\n') else: raise NoContentsFoundForOperationError( "Unable to retrieve server state") logout_routine(self, options) #Return code return ReturnCodes.SUCCESS
def run(self, line): """ Main Certificates Command function :param options: list of options :type options: list. """ try: (options, _) = self._parse_arglist(line) except (InvalidCommandLineErrorOPTS, SystemExit): if ("-h" in line) or ("--help" in line): return ReturnCodes.SUCCESS else: raise InvalidCommandLineErrorOPTS("") self.certificatesvalidation(options) if options.command == 'csr': self.generatecerthelper(options) elif options.command == 'ca': self.importcahelper(options) elif options.command == 'getcsr': self.getcerthelper(options) elif options.command == 'crl': self.importcrlhelper(options) elif options.command == 'tls': self.importtlshelper(options) logout_routine(self, options) #Return code return ReturnCodes.SUCCESS
def run(self, line): """ Main listcomp worker function :param line: string of arguments passed in :type line: str. """ try: (options, _) = self._parse_arglist(line) except (InvalidCommandLineErrorOPTS, SystemExit): if ("-h" in line) or ("--help" in line): return ReturnCodes.SUCCESS else: raise InvalidCommandLineErrorOPTS("") self.listcomponentvalidation(options) if self.typepath.defs.isgen9: raise IncompatibleiLOVersionError('iLO Repository commands are ' \ 'only available on iLO 5.') comps = self._rdmc.app.getcollectionmembers(\ '/redfish/v1/UpdateService/ComponentRepository/') if comps: self.printcomponents(comps, options) else: sys.stdout.write('No components found.\n') logout_routine(self, options) #Return code return ReturnCodes.SUCCESS
def run(self, line): """ Main smart array worker function :param line: command line input :type line: string. """ try: (options, _) = self._parse_arglist(line) except (InvalidCommandLineErrorOPTS, SystemExit): if ("-h" in line) or ("--help" in line): return ReturnCodes.SUCCESS else: raise InvalidCommandLineErrorOPTS("") self.smartarrayvalidation(options) self.selobj.selectfunction("SmartStorageConfig") content = sorted(self._rdmc.app.getprops(), key=lambda idx: idx["Location"]) if options.controller: self.selection_output(options, content) else: self.discovery_output(options, content) logout_routine(self, options) #Return code return ReturnCodes.SUCCESS
def run(self, line): """ Main disk inventory worker function :param line: command line input :type line: string. """ try: (options, args) = self._parse_arglist(line) except (InvalidCommandLineErrorOPTS, SystemExit): if ("-h" in line) or ("--help" in line): return ReturnCodes.SUCCESS else: raise InvalidCommandLineErrorOPTS("") self.deletelogicaldrivevalidation(options) self.selobj.selectfunction("SmartStorageConfig.") content = self._rdmc.app.getprops() if not args and not options.all: raise InvalidCommandLineError( 'You must include a logical drive to delete.') elif not options.controller: raise InvalidCommandLineError( 'You must include a controller to select.') else: if len(args) > 1: logicaldrives = args elif len(args) == 1: logicaldrives = args[0].replace(', ', ',').split(',') else: logicaldrives = None controllist = [] try: if options.controller.isdigit(): if int(options.controller) > 0: controllist.append(content[int(options.controller) - 1]) else: slotcontrol = options.controller.lower().strip('\"').split( 'slot')[-1].lstrip() for control in content: if slotcontrol.lower() == control["Location"].lower( ).split('slot')[-1].lstrip(): controllist.append(control) if not controllist: raise InvalidCommandLineError("") except InvalidCommandLineError: raise InvalidCommandLineError("Selected controller not found in the current inventory "\ "list.") self.deletelogicaldrives(controllist, logicaldrives, options.all, options.force) logout_routine(self, options) #Return code return ReturnCodes.SUCCESS
def run(self, line): """ Main factorydefaults function :param line: string of arguments passed in :type line: str. """ try: (options, args) = self._parse_arglist(line) except (InvalidCommandLineErrorOPTS, SystemExit): if ("-h" in line) or ("--help" in line): return ReturnCodes.SUCCESS else: raise InvalidCommandLineErrorOPTS("") if args: raise InvalidCommandLineError( "factorydefaults command takes no arguments.") self.factorydefaultsvalidation(options) sys.stdout.write("Resetting iLO to factory default settings.\n"\ "Current session will be terminated.\n") select = 'Manager.' results = self._rdmc.app.select(selector=select) try: results = results[0] except: pass if results: path = results.resp.request.path else: raise NoContentsFoundForOperationError("Manager. not found.") bodydict = results.resp.dict['Oem'][self.typepath.defs.oemhp] try: for item in bodydict['Actions']: if 'ResetToFactoryDefaults' in item: if self.typepath.defs.isgen10: action = item.split('#')[-1] else: action = "ResetToFactoryDefaults" path = bodydict['Actions'][item]['target'] body = {"Action": action, "ResetType": "Default"} break except: body = {"Action": "ResetToFactoryDefaults", \ "Target": "/Oem/Hp", "ResetType": "Default"} self._rdmc.app.post_handler(path, body, service=True) logout_routine(self, options) #Return code return ReturnCodes.SUCCESS
def run(self, line): """ Main ESKMCommand function :param line: string of arguments passed in :type line: str. """ try: (options, args) = self._parse_arglist(line) except (InvalidCommandLineErrorOPTS, SystemExit): if ("-h" in line) or ("--help" in line): return ReturnCodes.SUCCESS else: raise InvalidCommandLineErrorOPTS("") if not len(args) == 1: raise InvalidCommandLineError( "eskm command only takes one parameter.") self.eskmvalidation(options) select = self.typepath.defs.hpeskmtype results = self._rdmc.app.select(selector=select) try: results = results[0] except: pass if results: path = results.resp.request.path else: raise NoContentsFoundForOperationError("ESKM not found.") if args[0].lower() == 'clearlog': actionitem = "ClearESKMLog" elif args[0].lower() == 'testconnections': actionitem = "TestESKMConnections" else: raise InvalidCommandLineError('Invalid command.') bodydict = results.resp.dict try: for item in bodydict['Actions']: if actionitem in item: if self.typepath.defs.isgen10: actionitem = item.split('#')[-1] path = bodydict['Actions'][item]['target'] break except: pass body = {"Action": actionitem} self._rdmc.app.post_handler(path, body) logout_routine(self, options) #Return code return ReturnCodes.SUCCESS
def run(self, line): """ Main BIOS defaults worker function """ try: (options, _) = self._parse_arglist(line) except (InvalidCommandLineErrorOPTS, SystemExit): if ("-h" in line) or ("--help" in line): return ReturnCodes.SUCCESS else: raise InvalidCommandLineErrorOPTS("") self.defaultsvalidation(options) sys.stdout.write('Resetting the currently logged in server\'s BIOS settings to defaults.\n') put_path = self.typepath.defs.biospath body = None if self.typepath.defs.isgen10 and not options.manufdefaults: bodydict = self._rdmc.app.get_handler(self.typepath.defs.biospath,\ service=True, silent=True).dict for item in bodydict['Actions']: if 'ResetBios' in item: action = item.split('#')[-1] path = bodydict['Actions'][item]['target'] break body = {"Action": action} if options.userdefaults: body["ResetType"] = "default.user" else: body["ResetType"] = "default" self._rdmc.app.post_handler(path, body) else: if options.userdefaults: body = {'BaseConfig': 'default.user'} elif not options.manufdefaults: body = {'BaseConfig': 'default'} if body: self._rdmc.app.put_handler(put_path + '/settings', body=body, \ optionalpassword=options.biospassword) if not body and options.manufdefaults: setstring = "RestoreManufacturingDefaults=Yes --selector=HpBios. --commit" if options.reboot: setstring += " --reboot=%s" % options.reboot self.setobj.run(setstring) elif options.reboot: self.rebootobj.run(options.reboot) logout_routine(self, options) #Return code return ReturnCodes.SUCCESS
def run(self, line): """ Main disk inventory worker function :param line: command line input :type line: string. """ try: (options, _) = self._parse_arglist(line) except (InvalidCommandLineErrorOPTS, SystemExit): if ("-h" in line) or ("--help" in line): return ReturnCodes.SUCCESS else: raise InvalidCommandLineErrorOPTS("") self.createlogicaldrivevalidation(options) self.selobj.selectfunction("SmartStorageConfig.") content = self._rdmc.app.getprops() if not options.controller: raise InvalidCommandLineError('You must include a controller to select.') controllist = [] #if not args: # raise InvalidCommandLineError('Please choose customdrive or quickdrive creation.') #elif args[0].lower() == 'customdrive' and not len(args) == 3: # raise InvalidCommandLineError('customdrive takes 2 arguments') #elif args[0].lower() == 'quickdrive' and not len(args) == 6: # raise InvalidCommandLineError('quickdrive takes 5 arguments') #elif not args[0] in ['quickdrive', 'customdrive']: # raise InvalidCommandLineError('Please choose customdrive or quickdrive creation.') try: if options.controller.isdigit(): if int(options.controller) > 0: controllist.append(content[int(options.controller) - 1]) else: slotcontrol = options.controller.lower().strip('\"').split('slot')[-1].lstrip() for control in content: if slotcontrol.lower() == control["Location"].lower().split('slot')[-1].\ lstrip(): controllist.append(control) if not controllist: raise InvalidCommandLineError("") except InvalidCommandLineError: raise InvalidCommandLineError("Selected controller not found in the current inventory "\ "list.") for controller in controllist: if self.createlogicaldrive(options, controller): controller['DataGuard'] = "Disabled" self._rdmc.app.put_handler(controller["@odata.id"], \ controller, headers={'If-Match': self.getetag(controller['@odata.id'])}) self._rdmc.app.download_path([controller["@odata.id"]], path_refresh=True, \ crawl=False) logout_routine(self, options) #Return code return ReturnCodes.SUCCESS
def run(self, line): """ Main raw head worker function :param line: command line input :type line: string. """ try: (options, _) = self._parse_arglist(line) except (InvalidCommandLineErrorOPTS, SystemExit): if ("-h" in line) or ("--help" in line): return ReturnCodes.SUCCESS else: raise InvalidCommandLineErrorOPTS("") self.headvalidation(options) if options.path.startswith('"') and options.path.endswith('"'): options.path = options.path[1:-1] results = self._rdmc.app.head_handler(options.path, silent=options.silent, \ service=options.service) content = None tempdict = dict() if results and results.status == 200: if results._http_response: content = results.getheaders() else: content = results._headers tempdict = dict(content) if options.filename: output = json.dumps(tempdict, 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: if options.service: sys.stdout.write("%s\n" % tempdict) else: UI().print_out_json(tempdict) else: return ReturnCodes.NO_CONTENTS_FOUND_FOR_OPERATION logout_routine(self, options) #Return code return ReturnCodes.SUCCESS
def run(self, line): """ Wrapper function for upload command main function :param line: string of arguments passed in :type line: str. """ try: (options, _) = self._parse_arglist(line) except (InvalidCommandLineErrorOPTS, SystemExit): if ("-h" in line) or ("--help" in line): return ReturnCodes.SUCCESS else: raise InvalidCommandLineErrorOPTS("") self.uploadcommandvalidation(options) fwpkg = False if options.component.endswith('.fwpkg'): fwpkg = True comp, loc, ctype = self.fwpkgprepare(self, options.component) if ctype == 'C': options.component = comp[0] else: options.component = os.path.join(loc, comp[0]) if self.typepath.defs.isgen9: raise IncompatibleiLOVersionError(\ 'iLO Repository commands are only available on iLO 5.') filestoupload = self._check_and_split_files(options) if self.componentvalidation(options, filestoupload): start_time = time.time() ret = ReturnCodes.FAILED_TO_UPLOAD_COMPONENT if 'blobstore' in self._rdmc.app.current_client.base_url: ret = self.uploadlocally(filestoupload, options) else: ret = self.uploadfunction(filestoupload, options) sys.stdout.write("%s\n" % human_readable_time(time.time() - start_time)) if len(filestoupload) > 1: path, _ = os.path.split((filestoupload[0])[1]) shutil.rmtree(path) elif fwpkg: if os.path.exists(loc): shutil.rmtree(loc) else: ret = ReturnCodes.SUCCESS logout_routine(self, options) #Return code return ret
def run(self, line): """ Main disk inventory worker function :param line: command line input :type line: string. """ try: (options, _) = self._parse_arglist(line) except (InvalidCommandLineErrorOPTS, SystemExit): if ("-h" in line) or ("--help" in line): return ReturnCodes.SUCCESS else: raise InvalidCommandLineErrorOPTS("") self.clearcontrollerconfigvalidation(options) self.selobj.selectfunction("SmartStorageConfig.") content = self._rdmc.app.getprops() if not options.controller: raise InvalidCommandLineError( 'You must include a controller to select.') if options.controller: controllist = [] contentsholder = {"Actions": [{"Action": "ClearConfigurationMetadata"}], \ "DataGuard": "Disabled"} try: if options.controller.isdigit(): if int(options.controller) > 0: controllist.append(content[int(options.controller) - 1]) else: slotcontrol = options.controller.lower().strip('\"').split( 'slot')[-1].lstrip() for control in content: if slotcontrol.lower() == control["Location"].lower().split('slot')[-1].\ lstrip(): controllist.append(control) if not controllist: raise InvalidCommandLineError("") except InvalidCommandLineError: raise InvalidCommandLineError("Selected controller not found in the current "\ "inventory list.") for controller in controllist: self._rdmc.app.patch_handler(controller["@odata.id"], contentsholder) logout_routine(self, options) #Return code return ReturnCodes.SUCCESS
def run(self, line): """ Main clearrestapistate function. :param line: string of arguments passed in :type line: str. """ try: (options, args) = self._parse_arglist(line) except (InvalidCommandLineErrorOPTS, SystemExit): if ("-h" in line) or ("--help" in line): return ReturnCodes.SUCCESS else: raise InvalidCommandLineErrorOPTS("") if args: raise InvalidCommandLineError( "clearrestapistate command takes no arguments.") self.clearrestapistatevalidation(options) select = 'Manager.' results = self._rdmc.app.select(selector=select) try: results = results[0] except: pass if results: path = results.resp.request.path else: raise NoContentsFoundForOperationError("Manager. not found.") bodydict = results.resp.dict['Oem'][self.typepath.defs.oemhp] try: for item in bodydict['Actions']: if 'ClearRestApiState' in item: if self.typepath.defs.isgen10: action = item.split('#')[-1] else: action = "ClearRestApiState" path = bodydict['Actions'][item]['target'] body = {"Action": action} break except: body = {"Action": "ClearRestApiState", "Target": "/Oem/Hp"} self._rdmc.app.post_handler(path, body) logout_routine(self, options) #Return code return ReturnCodes.SUCCESS
def run(self, line): """ Wrapper function for download command main function :param line: command line input :type line: string. """ try: (options, args) = self._parse_arglist(line) except (InvalidCommandLineErrorOPTS, SystemExit): if ("-h" in line) or ("--help" in line): return ReturnCodes.SUCCESS else: raise InvalidCommandLineErrorOPTS("") repo = ['fwrepo'] urilist = args[0].split('/') if repo[0] not in urilist: repo = ['/fwrepo/'] repo[0] += args[0] args[0] = repo[0] self.downloadcomponentvalidation(options) if self.typepath.defs.isgen9: raise IncompatibleiLOVersionError('iLO Repository commands are ' \ 'only available on iLO 5.') if len(args) > 1: raise InvalidCommandLineError("Download component only takes 1 " \ "component path argument.\n") elif not args: raise InvalidCommandLineError( "Download component missing component path.\n") start_time = time.time() ret = ReturnCodes.FAILED_TO_DOWNLOAD_COMPONENT sys.stdout.write("Downloading component, this may take a while...\n") if 'blobstore' in self._rdmc.app.current_client.base_url: ret = self.downloadlocally(args[0], options) else: ret = self.downloadfunction(args[0], options) sys.stdout.write("%s\n" % human_readable_time(time.time() - start_time)) logout_routine(self, options) #Return code return ret
def run(self, line): """ Main deletecomp worker function :param line: string of arguments passed in :type line: str. """ try: (options, args) = self._parse_arglist(line) except (InvalidCommandLineErrorOPTS, SystemExit): if ("-h" in line) or ("--help" in line): return ReturnCodes.SUCCESS else: raise InvalidCommandLineErrorOPTS("") self.deletecomponentvalidation(options) if self.typepath.defs.isgen9: raise IncompatibleiLOVersionError('iLO Repository commands are ' \ 'only available on iLO 5.') comps = self._rdmc.app.getcollectionmembers(\ '/redfish/v1/UpdateService/ComponentRepository/') if not comps: sys.stdout.write('No components found to delete\n') elif options.deleteall: delopts = [] for comp in comps: try: if comp['Locked']: sys.stderr.write("Unable to delete %s. It is in use by "\ "an install set or update task.\n" % comp['Filename']) continue except KeyError: pass delopts.append(comp['@odata.id']) self.deletecomponents(comps, delopts) elif args: self.deletecomponents(comps, args) else: InvalidCommandLineError( "Please include the component(s) you wish to delete") logout_routine(self, options) #Return code return ReturnCodes.SUCCESS
def run(self, line): """ Main disk inventory worker function :param line: command line input :type line: string. """ try: (options, _) = self._parse_arglist(line) except (InvalidCommandLineErrorOPTS, SystemExit): if ("-h" in line) or ("--help" in line): return ReturnCodes.SUCCESS else: raise InvalidCommandLineErrorOPTS("") self.frcontrollervalidation(options) self.selobj.selectfunction("SmartStorageConfig.") content = self._rdmc.app.getprops() if options.controller: controllist = [] try: if options.controller.isdigit(): if int(options.controller) > 0: controllist.append(content[int(options.controller) - 1]) else: slotcontrol = options.controller.lower().strip('\"').split('slot')[-1].lstrip() for control in content: if slotcontrol.lower() == control["Location"].lower().split('slot')[-1].lstrip(): controllist.append(control) if not controllist: raise InvalidCommandLineError("") except InvalidCommandLineError: raise InvalidCommandLineError("Selected controller not found in the current inventory "\ "list.") for controller in controllist: contentsholder = {"Actions": [{"Action": "FactoryReset"}], \ "DataGuard": "Disabled"} self._rdmc.app.patch_handler(controller["@odata.id"], contentsholder) for idx, val in enumerate(content): sys.stdout.write("[%d]: %s\n" % (idx + 1, val["Location"])) logout_routine(self, options) #Return code return ReturnCodes.SUCCESS
def run(self, line): """ Main factorydefaults function :param line: string of arguments passed in :type line: str. """ try: (options, args) = self._parse_arglist(line) except (InvalidCommandLineErrorOPTS, SystemExit): if ("-h" in line) or ("--help" in line): return ReturnCodes.SUCCESS else: raise InvalidCommandLineErrorOPTS("") if not len(args) == 1: raise InvalidCommandLineError( "backuprestore command takes one argument.") self.ilobackuprestorevalidation(options) if 'blobstore' in self._rdmc.app.current_client.base_url: raise InvalidCommandLineError( "This command is only available remotely.") sessionkey = self._rdmc.app.current_client.session_key sessionkey = (sessionkey).encode('ascii', 'ignore') if args[0].lower() == 'backup': self.backupserver(options, sessionkey) elif args[0].lower() == 'restore': self.restoreserver(options, sessionkey) else: raise InvalidCommandLineError("%s is not a valid option for this "\ "command."% str(args[0])) logout_routine(self, options) #Return code return ReturnCodes.SUCCESS
def run(self, line): """ Show pending changes of settings objects :param line: string of arguments passed in :type line: str. """ try: (options, args) = self._parse_arglist(line) except (InvalidCommandLineErrorOPTS, SystemExit): if ("-h" in line) or ("--help" in line): return ReturnCodes.SUCCESS else: raise InvalidCommandLineErrorOPTS("") if args: raise InvalidCommandLineError( "Pending command does not take any arguments.") self.pendingvalidation(options) self.pendingfunction() logout_routine(self, options) return ReturnCodes.SUCCESS
def run(self, line): """ Main get worker function :param line: command line input :type line: string. """ try: (options, args) = self._parse_arglist(line) except (InvalidCommandLineErrorOPTS, SystemExit): if ("-h" in line) or ("--help" in line): return ReturnCodes.SUCCESS else: raise InvalidCommandLineErrorOPTS("") self.getvalidation(options) filtr = (None, None) if options.filter: try: if (str(options.filter)[0] == str(options.filter)[-1])\ and str(options.filter).startswith(("'", '"')): options.filter = options.filter[1:-1] (sel, val) = options.filter.split('=') filtr = (sel.strip(), val.strip()) except: raise InvalidCommandLineError("Invalid filter" \ " parameter format [filter_attribute]=[filter_value]") self.getworkerfunction(args, options, results=None, uselist=True, filtervals=filtr,\ readonly=options.noreadonly) logout_routine(self, options) #Return code return ReturnCodes.SUCCESS
def run(self, line): """ Main raw get worker function :param line: command line input :type line: string. """ try: (options, args) = self._parse_arglist(line) except (InvalidCommandLineErrorOPTS, SystemExit): if ("-h" in line) or ("--help" in line): return ReturnCodes.SUCCESS else: raise InvalidCommandLineErrorOPTS("") self.getpaths() self.validation(options) self.ipprofileworkerfunction(options, args) logout_routine(self, options) #Return code return ReturnCodes.SUCCESS
def run(self, line): """ Main serverinfo function. :param line: string of arguments passed in :type line: str. """ try: (options, args) = self._parse_arglist(line) except (InvalidCommandLineErrorOPTS, SystemExit): if ("-h" in line) or ("--help" in line): return ReturnCodes.SUCCESS else: raise InvalidCommandLineErrorOPTS("") if args: raise InvalidCommandLineError("serverinfo command takes no "\ "arguments.") self.serverinfovalidation(options) self.optionsvalidation(options) info = self.gatherinfo(options) if not info: raise InvalidCommandLineError("Please verify the commands entered "\ "and try again.") if options.json: UI().print_out_json(info) else: self.prettyprintinfo(info, options.showabsent) logout_routine(self, options) #Return code return ReturnCodes.SUCCESS
def typesfunction(self, line, returntypes=False): """ Main types worker function :param line: command line input :type line: string. :param returntypes: flag to determine if types should be printed :type returntypes: boolean. """ try: (options, args) = self._parse_arglist(line) except (InvalidCommandLineErrorOPTS, SystemExit): if ("-h" in line) or ("--help" in line): return ReturnCodes.SUCCESS else: raise InvalidCommandLineErrorOPTS("") self.typesvalidation(options) if not args: typeslist = list() typeslist = sorted(set(self._rdmc.app.types(options.fulltypes))) if not returntypes: sys.stdout.write("Type options:") sys.stdout.write('\n') for item in typeslist: sys.stdout.write(item) sys.stdout.write('\n') else: return typeslist else: raise InvalidCommandLineError( "The 'types' command does not take any arguments.") logout_routine(self, options)
def run(self, line): """ Main raw delete worker function :param line: command line input :type line: string. """ try: (options, args) = self._parse_arglist(line) except (InvalidCommandLineErrorOPTS, SystemExit): if ("-h" in line) or ("--help" in line): return ReturnCodes.SUCCESS else: raise InvalidCommandLineErrorOPTS("") headers = {} self.deletevalidation(options) if options.path.startswith('"') and options.path.endswith('"'): options.path = options.path[1:-1] if options.expand: options.path = options.path + '?$expand=.' try: currentsess = self._rdmc.app.current_client.session_location except: currentsess = None if options.headers: extraheaders = options.headers.split(',') for item in extraheaders: header = item.split(':') try: headers[header[0]] = header[1] except: InvalidCommandLineError( "Invalid format for --headers option.") if currentsess and (options.path in currentsess): self._rdmc.app.logout() sys.stdout.write("Your session has been deleted.\nPlease log "\ "back in if you wish to continue.\n") else: returnresponse = False if options.response or options.getheaders: returnresponse = True results = self._rdmc.app.delete_handler(options.path, \ headers=headers, silent=options.silent, service=options.service) if returnresponse and results: if options.getheaders: sys.stdout.write( json.dumps(dict(results.getheaders())) + "\n") if options.response: sys.stdout.write(results.read) elif results.status == 404: return ReturnCodes.NO_CONTENTS_FOUND_FOR_OPERATION elif results.status != 200: return ReturnCodes.UI_CLI_USAGE_EXCEPTION logout_routine(self, options) #Return code return ReturnCodes.SUCCESS
if not results['ServiceEnabled']: sys.stderr.write("You must enable this directory service before or during"\ " assignment of username and password. Try adding the flag --enable.\n") raise IloResponseError("") else: raise if priv_patches: self.update_mapping_privs(priv_patches) if keytab: path = oem['Actions'][next(iter(oem['Actions']))]['target'] sys.stdout.write("Adding keytab...\n") self._rdmc.app.post_handler(path, {"ImportUri": keytab}) else: self.test_directory(options, json=options.json) logout_routine(self, options) #Return code return ReturnCodes.SUCCESS def update_mapping_privs(self, roles_to_update): """ Helper function to update created role mappings to match user privileges. :param roles_to_update: Dictionary of privileges to update. :type roles_to_update: dict """ sys.stdout.write("Updating privileges of created role maps...\n") try: results = self._rdmc.app.select(selector='AccountService.', path_refresh=True)[0].dict roles = self._rdmc.app.getcollectionmembers(\ self._rdmc.app.getidbytype('RoleCollection.')[0]) except (KeyError, IndexError):
def run(self, line): """ Main save worker function :param line: command line input :type line: string. """ try: (options, args) = self._parse_arglist(line) except (InvalidCommandLineErrorOPTS, SystemExit): if ("-h" in line) or ("--help" in line): return ReturnCodes.SUCCESS else: raise InvalidCommandLineErrorOPTS("") self.savevalidation(options) if args: raise InvalidCommandLineError('Save command takes no arguments.') sys.stdout.write("Saving configuration...\n") if options.filter: try: if (str(options.filter)[0] == str(options.filter)[-1])\ and str(options.filter).startswith(("'", '"')): options.filter = options.filter[1:-1] (sel, val) = options.filter.split('=') sel = sel.strip() val = val.strip() except: raise InvalidCommandLineError("Invalid filter" \ " parameter format [filter_attribute]=[filter_value]") instances = self._rdmc.app.select(selector=self._rdmc.app.selector, \ fltrvals=(sel, val), path_refresh=options.ref) contents = self.saveworkerfunction(instances=instances) else: contents = self.saveworkerfunction() if options.multisave: for select in options.multisave: self.selobj.run(select) contents += self.saveworkerfunction() if not contents: raise redfish.ris.NothingSelectedError else: #TODO: Maybe add this to the command. Not sure we use it elsewhere in the lib contents = self.add_save_file_header(contents) if options.encryption: with open(self.filename, 'wb') as outfile: outfile.write(Encryption().encrypt_file(json.dumps(contents, \ indent=2, cls=redfish.ris.JSONEncoder), options.encryption)) else: with open(self.filename, 'w') as outfile: outfile.write(json.dumps(contents, indent=2, cls=redfish.ris.JSONEncoder, \ sort_keys=True)) sys.stdout.write("Configuration saved to: %s\n" % self.filename) logout_routine(self, options) #Return code return ReturnCodes.SUCCESS