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:
            if ("-h" in line) or ("--help" in line):
                return ReturnCodes.SUCCESS
            else:
                raise InvalidCommandLineErrorOPTS("")

        if options.encode and options.user and options.password:
            options.user = Encryption.decode_credentials(options.user)
            options.password = Encryption.decode_credentials(options.password)

        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)

        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:
            if ("-h" in line) or ("--help" in line):
                return ReturnCodes.SUCCESS
            else:
                raise InvalidCommandLineErrorOPTS("")

        if options.encode and options.user and options.password:
            options.user = Encryption.decode_credentials(options.user)
            options.password = Encryption.decode_credentials(options.password)

        self.smartarrayvalidation(options)

        self.selobj.selectfunction("SmartStorageConfig")
        content = self._rdmc.app.get_save()

        if options.controller:
            self.selection_output(options, content)
        else:
            self.discovery_output(options, content)

        #Return code
        return ReturnCodes.SUCCESS
    def run(self, line, autotest=False):
        """ Main info worker function

        :param line: command line input
        :type line: string.
        :param autotest: flag to determine if running automatictesting
        :type autotest: bool.
        """
        try:
            (options, args) = self._parse_arglist(line)
        except:
            if ("-h" in line) or ("--help" in line):
                return ReturnCodes.SUCCESS
            else:
                raise InvalidCommandLineErrorOPTS("")

        if options.encode and options.user and options.password:
            options.user = Encryption.decode_credentials(options.user)
            options.password = Encryption.decode_credentials(options.password)

        self.infovalidation(options)

        if args:
            inforesp = ''

            for item in args:
                newargs = list()
                if self._rdmc.app.get_selector().lower().startswith('bios.') \
                                        and not 'attributes' in item.lower():
                    if not (item.lower() in HARDCODEDLIST or '@odata' in item.lower()):
                        item = "Attributes/" + item

                if "/" in item:
                    newargs = item.split("/")
                    item = newargs[0]

                (contents, outdata) = self._rdmc.app.info(selector=item, \
                    dumpjson=options.json, autotest=autotest, newarg=newargs, \
                                            latestschema=options.latestschema)
                if outdata and options.json:
                    UI().print_out_json(outdata)
                elif outdata:
                    sys.stdout.write(outdata)

                if isinstance(contents, list) and not autotest:
                    if 'none' in contents and inforesp != 'success':
                        inforesp = 'none'
                    elif 'Success' in contents:
                        inforesp = 'success'

                try:
                    if not contents or inforesp == 'none':
                        raise InfoMissingEntriesError("There are no valid "\
                            "entries for info in the current instance.")
                except Exception, excp:
                    raise excp

                if len(args) > 1 and not item == args[-1]:
                    sys.stdout.write("\n************************************"\
                                     "**************\n")
    def run(self, line):
        """ Main raw put worker function

        :param line: command line input
        :type line: string.
        """
        try:
            (options, args) = self._parse_arglist(line)
        except:
            if ("-h" in line) or ("--help" in line):
                return ReturnCodes.SUCCESS
            else:
                raise InvalidCommandLineErrorOPTS("")

        url = None
        headers = {}
        results = None

        if options.encode and options.user and options.password:
            options.user = Encryption.decode_credentials(options.user)
            options.password = Encryption.decode_credentials(options.password)

        if options.sessionid:
            url = self.sessionvalidation(options)
        else:
            self.putvalidation(options)

        contentsholder = None

        if len(args) == 1:
            try:
                inputfile = open(args[0], 'r')
                contentsholder = json.loads(inputfile.read())
            except Exception, excp:
                raise InvalidFileInputError("%s" % excp)
    def run(self, line):
        """ Main BIOS defaults worker function """
        try:
            (options, _) = self._parse_arglist(line)
        except:
            if ("-h" in line) or ("--help" in line):
                return ReturnCodes.SUCCESS
            else:
                raise InvalidCommandLineErrorOPTS("")

        if options.encode and options.user and options.password:
            options.user = Encryption.decode_credentials(options.user)
            options.password = Encryption.decode_credentials(options.password)

        self.defaultsvalidation(options)

        sys.stdout.write(u'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,\
                                        verbose=self._rdmc.opts.verbose,\
                                        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:
            self.setobj.run("RestoreManufacturingDefaults=Yes "\
                                                "--selector=HpBios. --commit")

        if options.reboot:
            self.rebootobj.run(options.reboot)

        #Return code
        return ReturnCodes.SUCCESS
Exemple #6
0
    def run(self, line):
        """ Main status worker function

        :param line: command line input
        :type line: string.
        """
        try:
            (options, _) = self._parse_arglist(line)
        except:
            if ("-h" in line) or ("--help" in line):
                return ReturnCodes.SUCCESS
            else:
                raise InvalidCommandLineErrorOPTS("")

        if options.encode and options.user and options.password:
            options.user = Encryption.decode_credentials(options.user)
            options.password = Encryption.decode_credentials(options.password)

        self.statusvalidation(options)
        contents = self._rdmc.app.status()
        selector = self._rdmc.app.get_selector()

        if contents:
            self.outputpatches(contents, selector)
        else:
            sys.stdout.write("No changes found\n")

        #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:
            if ("-h" in line) or ("--help" in line):
                return ReturnCodes.SUCCESS
            else:
                raise InvalidCommandLineErrorOPTS("")

        if args:
            raise InvalidCommandLineError("factorydefaults command takes no "\
                                                                "arguments.")

        if options.encode and options.user and options.password:
            options.user = Encryption.decode_credentials(options.user)
            options.password = Encryption.decode_credentials(options.password)

        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.filter(select, None, None)

        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)

        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:
            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.")

        if options.encode and options.user and options.password:
            options.user = Encryption.decode_credentials(options.user)
            options.password = Encryption.decode_credentials(options.password)

        self.pendingvalidation(options)

        self.pendingfunction()

        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:
            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.")

        if options.encode and options.user and options.password:
            options.user = Encryption.decode_credentials(options.user)
            options.password = Encryption.decode_credentials(options.password)

        self.eskmvalidation(options)

        select = self.typepath.defs.hpeskmtype
        results = self._rdmc.app.filter(select, None, None)

        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)

        return ReturnCodes.SUCCESS
Exemple #10
0
    def logoutfunction(self, line):
        """ Main logout worker function

        :param line: command line input
        :type line: string.
        """
        try:
            (options, _) = self._parse_arglist(line)
        except:
            if ("-h" in line) or ("--help" in line):
                return ReturnCodes.SUCCESS
            else:
                raise InvalidCommandLineErrorOPTS("")

        if options.encode and options.user and options.password:
            options.user = Encryption.decode_credentials(options.user)
            options.password = Encryption.decode_credentials(options.password)
            client = self._rdmc.app.get_current_client()
        try:
            if options.user and options.password:
                client = self._rdmc.app.get_current_client()
                if not client.get_username():
                    client.set_username(options.user)
                if not client.get_password():
                    client.set_password(options.password)
        except:
            pass

        self._rdmc.app.logout("")
Exemple #11
0
    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:
            if ("-h" in line) or ("--help" in line):
                return ReturnCodes.SUCCESS
            else:
                raise InvalidCommandLineErrorOPTS("")

        if options.encode and options.user and options.password:
            options.user = Encryption.decode_credentials(options.user)
            options.password = Encryption.decode_credentials(options.password)

        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')

        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:
            if ("-h" in line) or ("--help" in line):
                return ReturnCodes.SUCCESS
            else:
                raise InvalidCommandLineErrorOPTS("")

        if args:
            raise InvalidCommandLineError("Sigrecompute command takes no " \
                                                                "arguments.")

        if options.encode and options.user and options.password:
            options.user = Encryption.decode_credentials(options.user)
            options.password = Encryption.decode_credentials(options.password)

        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.")

        return ReturnCodes.SUCCESS
    def commitfunction(self, options=None):
        """ Main commit worker function

        :param options: command line options
        :type options: list.
        """

        if options.encode and options.user and options.password:
            options.user = Encryption.decode_credentials(options.user)
            options.password = Encryption.decode_credentials(options.password)

        self.commitvalidation(options)

        sys.stdout.write(u"Committing changes...\n")

        if options:
            if options.biospassword:
                self._rdmc.app.update_bios_password(options.biospassword)

        try:
            if not self._rdmc.app.commit(verbose=self._rdmc.opts.verbose):
                raise NoChangesFoundOrMadeError("No changes found or made " \
                                                    "during commit operation.")
        except Exception, excp:
            raise excp
Exemple #14
0
    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:
            if ("-h" in line) or ("--help" in line):
                return ReturnCodes.SUCCESS
            else:
                raise InvalidCommandLineErrorOPTS("")

        if options.encode and options.user and options.password:
            options.user = Encryption.decode_credentials(options.user)
            options.password = Encryption.decode_credentials(options.password)

        self.deletelogicaldrivevalidation(options)

        self.selobj.selectfunction("SmartStorageConfig.")
        content = self._rdmc.app.get_save()

        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 = []

        if options.controller.isdigit() and not options.controller == '0':
            try:
                controllist.append(content[int(options.controller) - 1])
            except:
                pass
        else:
            for control in content:
                if options.controller.lower() == control["Location"].lower():
                    controllist.append(control)

        if not controllist:
            raise InvalidCommandLineError("Selected controller not " \
                                    "found in the current inventory list.")
        else:
            self.deletelogicaldrives(controllist, logicaldrives, options.all,\
                                     options.force)

        #Return code
        return ReturnCodes.SUCCESS
Exemple #15
0
    def loginvalidation(self, options, args):
        """ Login helper function for login validations

        :param options: command line options
        :type options: list.
        :param args: command line arguments
        :type args: list.
        """
        # Fill user name/password from config file
        if not options.user:
            options.user = self._rdmc.app.config.get_username()
        if not options.password:
            options.password = self._rdmc.app.config.get_password()
        if not options.biospassword:
            options.biospassword = self._rdmc.app.config.get_bios_password()

        # Password and user name validation
        if options.user and not options.password:
            # Option for interactive entry of password
            tempinput = getpass.getpass()

            if tempinput:
                options.password = tempinput
            else:
                raise InvalidCommandLineError(
                    "Empty or invalid password was entered.")

        if options.user:
            self.username = options.user

        if options.password:
            self.password = options.password

        if options.encode:
            self.username = Encryption.decode_credentials(self.username)
            self.password = Encryption.decode_credentials(self.password)

        if options.biospassword:
            self.biospassword = options.biospassword

        # Assignment of url in case no url is entered
        self.url = 'blobstore://.'

        if args:
            # Any argument should be treated as an URL
            self.url = args[0]

            # Verify that URL is properly formatted for https://
            if "https://" not in self.url:
                self.url = "https://" + self.url
            if not self.username or not self.password:
                raise InvalidCommandLineError(
                    "Empty username or password was entered.")
        else:
            # Check to see if there is a URL in config file
            if self._rdmc.app.config.get_url():
                self.url = self._rdmc.app.config.get_url()
    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:
            if ("-h" in line) or ("--help" in line):
                return ReturnCodes.SUCCESS
            else:
                raise InvalidCommandLineErrorOPTS("")

        if options.encode and options.user and options.password:
            options.user = Encryption.decode_credentials(options.user)
            options.password = Encryption.decode_credentials(options.password)

        if options.sessionid:
            url = self.sessionvalidation(options)
        else:
            url = None
            self.downloadcomponentvalidation(options)

        if options.sessionid and not url:
            raise InvalidCommandLineError('Url muse be included with ' \
                          'sessionid. Session is not required for local mode.')

        if not options.sessionid and 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 not url and 'blobstore' in self._rdmc.app.get_current_client()\
                                                ._rest_client.get_base_url():
            ret = self.downloadlocally(args[0], options)
        else:
            ret = self.downloadfunction(args[0], options, url)

        sys.stdout.write("%s\n" %
                         human_readable_time(time.time() - start_time))

        if options.logout:
            self.logoutobj.run("")

        return ret
    def uploadcommandvalidation(self, options):
        """ upload command method validation function

        :param options: command line options
        :type options: list.
        """
        inputline = list()
        client = None

        if not options.component:
            raise InvalidCommandLineError("The component option is required"\
                                          " for this operation.")

        if not os.path.exists(options.component):
            raise InvalidPathError("Component not found at specified path.")

        if options.componentsig and (not os.path.exists(options.componentsig)):
            raise InvalidCommandLineError("Component signature not found.")

        try:
            client = self._rdmc.app.current_client
        except:
            if options.user or options.password or options.url:
                if options.url:
                    inputline.extend([options.url])
                if options.user:
                    if options.encode:
                        options.user = Encryption.decode_credentials(
                            options.user)
                    inputline.extend(["-u", options.user])
                if options.password:
                    if options.encode:
                        options.password = Encryption.decode_credentials(
                            options.password)
                    inputline.extend(["-p", options.password])
                if options.https_cert:
                    inputline.extend(["--https", options.https_cert])
            else:
                if self._rdmc.app.config.get_url():
                    inputline.extend([self._rdmc.app.config.get_url()])
                if self._rdmc.app.config.get_username():
                    inputline.extend(
                        ["-u", self._rdmc.app.config.get_username()])
                if self._rdmc.app.config.get_password():
                    inputline.extend(
                        ["-p", self._rdmc.app.config.get_password()])
                if self._rdmc.app.config.get_ssl_cert():
                    inputline.extend(
                        ["--https",
                         self._rdmc.app.config.get_ssl_cert()])

        if not inputline and not client:
            sys.stdout.write('Local login initiated...\n')
        if not client or inputline:
            self.lobobj.loginfunction(inputline)
Exemple #18
0
    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:
            if ("-h" in line) or ("--help" in line):
                return ReturnCodes.SUCCESS
            else:
                raise InvalidCommandLineErrorOPTS("")

        if args:
            raise InvalidCommandLineError("clearrestapistate command takes no "\
                                          "arguments.")

        if options.encode and options.user and options.password:
            options.user = Encryption.decode_credentials(options.user)
            options.password = Encryption.decode_credentials(options.password)

        self.clearrestapistatevalidation(options)

        select = 'Manager.'
        results = self._rdmc.app.filter(select, None, None)

        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)

        return ReturnCodes.SUCCESS
Exemple #19
0
    def run(self, line):
        """ Main firmware update worker function

        :param line: string of arguments passed in
        :type line: str.
        """
        try:
            (options, args) = self._parse_arglist(line)
        except:
            if ("-h" in line) or ("--help" in line):
                return ReturnCodes.SUCCESS
            else:
                raise InvalidCommandLineErrorOPTS("")

        if args:
            raise InvalidCommandLineError('fwintegritycheck command takes no ' \
                                                                    'arguments')

        if options.encode and options.user and options.password:
            options.user = Encryption.decode_credentials(options.user)
            options.password = Encryption.decode_credentials(options.password)

        self.firmwareintegritycheckvalidation(options)

        if self.typepath.defs.isgen9:
            raise IncompatibleiLOVersionError('fwintegritycheck command is ' \
                                                    'only available on iLO 5.')

        licenseres = self._rdmc.app.filter('HpeiLOLicense.', None, None)
        try:
            licenseres = licenseres[0]
        except:
            pass
        if not licenseres.dict['LicenseFeatures']['FWScan']:
            raise IloLicenseError(
                "This command is not available with this iLO license.")

        select = self.typepath.defs.hpilofirmwareupdatetype
        results = self._rdmc.app.filter(select, None, None)

        try:
            results = results[0]
        except:
            pass

        bodydict = results.resp.dict

        path = bodydict['Oem']['Hpe']['Actions']\
            ['#HpeiLOUpdateServiceExt.StartFirmwareIntegrityCheck']['target']

        self._rdmc.app.post_handler(path, {})

        return ReturnCodes.SUCCESS
    def typesvalidation(self, options):
        """ types method validation function

        :param options: command line options
        :type options: list.
        """
        client = None
        inputline = list()
        runlogin = False

        try:
            client = self._rdmc.app.current_client
        except:
            if options.user or options.password or options.url:
                if options.url:
                    inputline.extend([options.url])
                if options.user:
                    if options.encode:
                        options.user = Encryption.decode_credentials(
                            options.user)
                    inputline.extend(["-u", options.user])
                if options.password:
                    if options.encode:
                        options.password = Encryption.decode_credentials(
                            options.password)
                    inputline.extend(["-p", options.password])
                if options.https_cert:
                    inputline.extend(["--https", options.https_cert])
            else:
                if self._rdmc.app.config.get_url():
                    inputline.extend([self._rdmc.app.config.get_url()])
                if self._rdmc.app.config.get_username():
                    inputline.extend(
                        ["-u", self._rdmc.app.config.get_username()])
                if self._rdmc.app.config.get_password():
                    inputline.extend(
                        ["-p", self._rdmc.app.config.get_password()])
                if self._rdmc.app.config.get_ssl_cert():
                    inputline.extend(
                        ["--https",
                         self._rdmc.app.config.get_ssl_cert()])

        if inputline or not client:
            runlogin = True
            if not inputline:
                sys.stdout.write('Local login initiated...\n')
        if options.includelogs:
            inputline.extend(["--includelogs"])
        if options.path:
            inputline.extend(["--path", options.path])

        if runlogin:
            self.lobobj.loginfunction(inputline)
    def statusvalidation(self, options):
        """ Status method validation function """

        if options.encode and options.user and options.password:
            options.user = Encryption.decode_credentials(options.user)
            options.password = Encryption.decode_credentials(options.password)

        try:
            _ = self._rdmc.app.current_client
        except:
            raise NoCurrentSessionEstablished("Please login and make setting" \
                                      " changes before using status command.")
    def run(self, line):
        """ Main iscsi configuration worker function

        :param line: string of arguments passed in
        :type line: str.
        """
        try:
            (options, args) = self._parse_arglist(line)
        except:
            if ("-h" in line) or ("--help" in line):
                return ReturnCodes.SUCCESS
            else:
                raise InvalidCommandLineErrorOPTS("")

        if options.encode and options.user and options.password:
            options.user = Encryption.decode_credentials(options.user)
            options.password = Encryption.decode_credentials(options.password)

        self.iscsiconfigurationvalidation(options)

        if self.typepath.defs.biospath[-1] == '/':
            iscsipath = self.typepath.defs.biospath + 'iScsi/'
            iscsisettingspath = self.typepath.defs.biospath + 'iScsi/settings/'
            bootpath = self.typepath.defs.biospath + 'Boot/'
        else:
            iscsipath = self.typepath.defs.biospath + '/iScsi'
            iscsisettingspath = self.typepath.defs.biospath + '/iScsi/settings'
            bootpath = self.typepath.defs.biospath + '/Boot'

        if options.list:
            self.listoptionhelper(options, iscsipath, iscsisettingspath, \
                                                                    bootpath)
        elif options.modify:
            self.modifyoptionhelper(options, iscsisettingspath)
        elif options.add:
            self.addoptionhelper(options, iscsipath, iscsisettingspath, \
                                                                    bootpath)
        elif options.delete:
            self.deleteoptionhelper(options, iscsisettingspath)
        elif not args:
            self.defaultsoptionhelper(options, iscsipath, bootpath)
        else:
            if len(args) < 2:
                self.iscsiconfigurationvalidation(options)
            else:
                raise InvalidCommandLineError("Invalid number of parameters. " \
                        "Iscsi configuration takes a maximum of 1 parameter.")

        if options.reboot:
            self.rebootobj.run(options.reboot)

        #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:
            if ("-h" in line) or ("--help" in line):
                return ReturnCodes.SUCCESS
            else:
                raise InvalidCommandLineErrorOPTS("")

        if options.encode and options.user and options.password:
            options.user = Encryption.decode_credentials(options.user)
            options.password = Encryption.decode_credentials(options.password)

        self.factoryresetcontrollervalidation(options)

        self.selobj.selectfunction("SmartStorageConfig.")
        content = self._rdmc.app.get_save()

        if options.controller:
            controllist = []

            if options.controller.isdigit() and not options.controller == '0':
                try:
                    controllist.append(content[int(options.controller) - 1])
                except:
                    pass
            else:
                for control in content:
                    if options.controller.lower() == control["Location"].lower(
                    ):
                        controllist.append(control)

            if not controllist:
                raise InvalidCommandLineError("Selected controller not " \
                                        "found in the current inventory list.")
            else:
                for controller in controllist:
                    contentsholder = {"Actions": [{"Action": "FactoryReset"}], \
                                                        "DataGuard": "Disabled"}
                    self._rdmc.app.patch_handler(controller["@odata.id"], \
                                                                contentsholder)
        else:
            for idx, val in enumerate(content):
                sys.stdout.write("[%d]: %s\n" % (idx + 1, val["Location"]))

        #Return code
        return ReturnCodes.SUCCESS
    def bootordervalidation(self, options):
        """ Boot order method validation function

        :param options: command line options
        :type options: list.
        """
        inputline = list()

        if self._rdmc.app.config._ac__commit.lower() == 'true':
            options.commit = True

        try:
            client = self._rdmc.app.current_client
            if options.biospassword:
                client.bios_password = options.biospassword
        except:
            if options.user or options.password or options.url:
                if options.url:
                    inputline.extend([options.url])
                if options.user:
                    if options.encode:
                        options.user = Encryption.decode_credentials(
                            options.user)
                    inputline.extend(["-u", options.user])
                if options.password:
                    if options.encode:
                        options.password = Encryption.decode_credentials(
                            options.password)
                    inputline.extend(["-p", options.password])
                if options.https_cert:
                    inputline.extend(["--https", options.https_cert])
            else:
                if self._rdmc.app.config.get_url():
                    inputline.extend([self._rdmc.app.config.get_url()])
                if self._rdmc.app.config.get_username():
                    inputline.extend(
                        ["-u", self._rdmc.app.config.get_username()])
                if self._rdmc.app.config.get_password():
                    inputline.extend(
                        ["-p", self._rdmc.app.config.get_password()])
                if self._rdmc.app.config.get_ssl_cert():
                    inputline.extend(
                        ["--https",
                         self._rdmc.app.config.get_ssl_cert()])

        if inputline:
            self.lobobj.loginfunction(inputline)

        if options.encode:
            options.biospassword = Encryption.decode_credentials(
                options.biospassword)
Exemple #25
0
    def frcontrollervalidation(self, options):
        """ Factory reset controller validation function

        :param options: command line options
        :type options: list.
        """
        client = None
        inputline = list()
        runlogin = False

        if options.encode and options.user and options.password:
            options.user = Encryption.decode_credentials(options.user)
            options.password = Encryption.decode_credentials(options.password)

        try:
            client = self._rdmc.app.get_current_client()
            if options.user and options.password:
                if not client.get_username():
                    client.set_username(options.user)
                if not client.get_password():
                    client.set_password(options.password)
        except:
            if options.user or options.password or options.url:
                if options.url:
                    inputline.extend([options.url])
                if options.user:
                    inputline.extend(["-u", options.user])
                if options.password:
                    inputline.extend(["-p", options.password])
            else:
                if self._rdmc.app.config.get_url():
                    inputline.extend([self._rdmc.app.config.get_url()])
                if self._rdmc.app.config.get_username():
                    inputline.extend(
                        ["-u", self._rdmc.app.config.get_username()])
                if self._rdmc.app.config.get_password():
                    inputline.extend(
                        ["-p", self._rdmc.app.config.get_password()])

        if inputline or not client:
            runlogin = True
            if not inputline:
                sys.stdout.write('Local login initiated...\n')

        if runlogin:
            self.lobobj.loginfunction(inputline)

        if not options.all and not options.controller:
            raise InvalidCommandLineErrorOPTS(
                "Please specify a controller or use \'--all\'.")
Exemple #26
0
    def fwpkgvalidation(self, options):
        """ fwpkg validation function

        :param options: command line options
        :type options: list.
        """
        inputline = list()
        client = None

        try:
            client = self._rdmc.app.current_client
            if options.user and options.password:
                if not client.get_username():
                    client.set_username(options.user)
                if not client.get_password():
                    client.set_password(options.password)
        except:
            if options.user or options.password or options.url:
                if options.url:
                    inputline.extend([options.url])
                if options.user:
                    if options.encode:
                        options.user = Encryption.decode_credentials(
                            options.user)
                    inputline.extend(["-u", options.user])
                if options.password:
                    if options.encode:
                        options.password = Encryption.decode_credentials(
                            options.password)
                    inputline.extend(["-p", options.password])
                if options.https_cert:
                    inputline.extend(["--https", options.https_cert])
            else:
                if self._rdmc.app.config.get_url():
                    inputline.extend([self._rdmc.app.config.get_url()])
                if self._rdmc.app.config.get_username():
                    inputline.extend(
                        ["-u", self._rdmc.app.config.get_username()])
                if self._rdmc.app.config.get_password():
                    inputline.extend(
                        ["-p", self._rdmc.app.config.get_password()])
                if self._rdmc.app.config.get_ssl_cert():
                    inputline.extend(
                        ["--https",
                         self._rdmc.app.config.get_ssl_cert()])

        if not inputline and not client:
            sys.stdout.write('Local login initiated...\n')
        if not client or inputline:
            self.lobobj.loginfunction(inputline)
Exemple #27
0
    def run(self, line):
        """ Main listcomp worker function

        :param line: string of arguments passed in
        :type line: str.
        """
        try:
            (options, args) = self._parse_arglist(line)
        except:
            if ("-h" in line) or ("--help" in line):
                return ReturnCodes.SUCCESS
            else:
                raise InvalidCommandLineErrorOPTS("")

        if options.encode and options.user and options.password:
            options.user = Encryption.decode_credentials(options.user)
            options.password = Encryption.decode_credentials(options.password)

        self.installsetvalidation(options)

        if self.typepath.defs.isgen9:
            raise IncompatibleiLOVersionError('iLO Repository commands are ' \
                                                    'only available on iLO 5.')

        if args and args[0] in ['delete', 'invoke'] and not options.name:
            raise InvalidCommandLineError('Name option is required for ' \
                                          'delete and invoke commands.')
        if options.name:
            if options.name.startswith('"') and options.name.endswith('"'):
                options.name = options.name[1:-1]
        if options.removeall:
            self.removeinstallsets()
        elif not args:
            self.printinstallsets(options)
        elif args[0].lower() == 'add':
            if not len(args) == 2:
                raise InvalidCommandLineError('add command requires an ' \
                                                            'install set file.')
            else:
                self.addinstallset(args[1], options.name)
        elif args[0].lower() == 'delete':
            self.deleteinstallset(options.name)
        elif args[0].lower() == 'invoke':
            self.invokeinstallset(options)
        else:
            raise InvalidCommandLineError('%s is not a valid command.' %
                                          args[0])

        return ReturnCodes.SUCCESS
    def selectvalidation(self, options):
        """ Select data validation function

        :param options: command line options
        :type options: list.
        """
        client = None
        runlogin = False
        inputline = list()

        if options.encode and options.user and options.password:
            options.user = Encryption.decode_credentials(options.user)
            options.password = Encryption.decode_credentials(options.password)

        try:
            client = self._rdmc.app.get_current_client()
            if options.user and options.password:
                if not client.get_username():
                    client.set_username(options.user)
                if not client.get_password():
                    client.set_password(options.password)
        except:
            if options.user or options.password or options.url:
                if options.url:
                    inputline.extend([options.url])
                if options.user:
                    inputline.extend(["-u", options.user])
                if options.password:
                    inputline.extend(["-p", options.password])
            else:
                if self._rdmc.app.config.get_url():
                    inputline.extend([self._rdmc.app.config.get_url()])
                if self._rdmc.app.config.get_username():
                    inputline.extend(
                        ["-u", self._rdmc.app.config.get_username()])
                if self._rdmc.app.config.get_password():
                    inputline.extend(
                        ["-p", self._rdmc.app.config.get_password()])

        if not inputline and not client:
            sys.stdout.write('Local login initiated...\n')
        if inputline:
            runlogin = True
        if options.includelogs:
            inputline.extend(["--includelogs"])
        if options.path:
            inputline.extend(["--path", options.path])
        if not client or runlogin:
            self.lobobj.loginfunction(inputline)
Exemple #29
0
    def serverinfovalidation(self, options):
        """ serverinfo method validation function.

        :param options: command line options
        :type options: list.
        """
        client = None
        inputline = list()

        try:
            client = self._rdmc.app.current_client
        except:
            if options.user or options.password or options.url:
                if options.url:
                    inputline.extend([options.url])
                if options.user:
                    if options.encode:
                        options.user = Encryption.decode_credentials(
                            options.user)
                    inputline.extend(["-u", options.user])
                if options.password:
                    if options.encode:
                        options.password = Encryption.decode_credentials(
                            options.password)
                    inputline.extend(["-p", options.password])
                if options.https_cert:
                    inputline.extend(["--https", options.https_cert])
            else:
                if self._rdmc.app.config.get_url():
                    inputline.extend([self._rdmc.app.config.get_url()])
                if self._rdmc.app.config.get_username():
                    inputline.extend(
                        ["-u", self._rdmc.app.config.get_username()])
                if self._rdmc.app.config.get_password():
                    inputline.extend(
                        ["-p", self._rdmc.app.config.get_password()])
                if self._rdmc.app.config.get_ssl_cert():
                    inputline.extend(
                        ["--https",
                         self._rdmc.app.config.get_ssl_cert()])

        if inputline or not client:
            if not inputline:
                sys.stdout.write('Local login initiated...\n')
            self.lobobj.loginfunction(inputline)
        elif not client:
            raise InvalidCommandLineError("Please login or pass credentials" \
                                          " to complete the operation.")
    def load_clone(self, filename, options):
        """ load the clone file onto the server

        :param filename: filename containing the clone config data
        :type filename: str
        :param options: command line options
        :type options: list.
        """
        loadcontents = None

        if not filename:
            filename = 'clone.json'

        if not os.path.isfile(filename):
            raise InvalidFileInputError("File '%s' doesn't exist. Please " \
                            "create file by running save command." % file)
        if options.encryption:
            with open(filename, "rb") as myfile:
                data = myfile.read()
                data = Encryption().decrypt_file(data, \
                                                    options.encryption)
        else:
            myfile = open(filename, 'r')
            data = myfile.read()

        myfile.close()

        try:
            loadcontents = json.loads(data)
        except:
            raise InvalidFileFormattingError("Invalid file formatting " \
                                                "found in file %s" % file)

        return loadcontents