示例#1
0
    def rinv(self, nodesinfo, args):

        # 1, parse agrs
        if not args or (len(args) == 1 and args[0] in ['-V', '--verbose']):
            args.append('all')

        # We are not using a standard Python options (with - or --) because
        # of that, we need to specify multiple identical choices. If only
        # one optional choice is specified - [all|cpu|dimm|firm|model|serial]
        # only one option at a time is allowed.
        # If specified - [all][cpu][dimm][firm][model][serial], then multiple
        # options are accepted, but they are required to be ordered,
        # e.g "cpu dimm" will work, but not "dimm cpu"
        rinv_usage = """
        Usage:
            rinv [-V|--verbose] [all|cpu|dimm|firm|model|serial] [all|cpu|dimm|firm|model|serial] [all|cpu|dimm|firm|model|serial] [all|cpu|dimm|firm|model|serial] [all|cpu|dimm|firm|model|serial]

        Options:
            -V --verbose   rinv verbose mode.
        """

        try:
            opts = docopt(rinv_usage, argv=args)

            self.verbose = opts.pop('--verbose')
            actions = [k for k,v in opts.items() if v]
        except Exception as e:
            self.messager.error("Failed to parse arguments for rinv: %s" % args)
            return

        # 2, validate the args
        run_firmware_inventory = 0
        run_other_inventory = 0
        for action in actions:
            # Check if each action is valid
            if action not in INVENTORY_OPTIONS:
                self.messager.error("Not supported subcommand for rinv: %s" % action)
                return
            else:
                # Valid action, set flags for which calls to make later
                if action == 'all':
                    run_firmware_inventory = 0
                    run_other_inventory = 1
                    break # get all inventory, nothing else matters
                elif action == 'firm':
                    run_firmware_inventory = 1
                else:
                    run_other_inventory = 1

        # 3, run the subcommands
        runner = OpenBMCInventoryTask(nodesinfo, callback=self.messager, debugmode=self.debugmode, verbose=self.verbose)
        if run_firmware_inventory == 1:
            DefaultInventoryManager().get_firm_info(runner)
            actions.remove('firm') # Remove element from actions array
        if run_other_inventory == 1:
            DefaultInventoryManager().get_inventory_info(runner, actions)
示例#2
0
    def rflash(self, nodesinfo, args):

        # 1, parse agrs
        rflash_usage = """
        Usage:
            rflash [[-a|--activate <arg>] | [-c|--check <arg>] | [-d <arg> [--no-host-reboot]] | [--delete <arg>] | [-l|--list] |  [-u|--upload <arg>]] [-V|--verbose]

        Options:
            -V,--verbose          Show verbose message
            -a,--activate <arg>   Activate firmware
            -c,--check            Check firmware info
            -d <arg>              Upload and activate all firmware files under directory
            -l,--list             List firmware info
            -u,--upload <arg>     Upload firmware file
            --delete <arg>        Delete firmware
            --no-host-reboot      Not reboot host after activate
        """

        try:
            opts = docopt(rflash_usage, argv=args)
            self.verbose = opts.pop('--verbose')
        except DocoptExit as e:
            self.messager.error("Failed to parse args by docopt: %s" % e)
            return
        except Exception as e:
            self.messager.error("Failed to parse arguments for rflash: %s" %
                                args)
            return

        if opts['--check']:
            check_arg = None
            if opts['<arg>']:
                check_arg = opts['<arg>']
            runner = runner = OpenBMCInventoryTask(nodesinfo,
                                                   callback=self.messager,
                                                   debugmode=self.debugmode,
                                                   verbose=self.verbose,
                                                   cwd=self.cwd[0])
            DefaultInventoryManager().get_firm_info(runner, check_arg)
            return

        runner = OpenBMCFlashTask(nodesinfo,
                                  callback=self.messager,
                                  debugmode=self.debugmode,
                                  verbose=self.verbose,
                                  cwd=self.cwd[0])
        if opts['--activate']:
            DefaultFlashManager().activate_firm(runner, opts['--activate'][0])
        elif opts['--list']:
            DefaultFlashManager().list_firm_info(runner)
        elif opts['-d']:
            DefaultFlashManager().flash_process(runner, opts['-d'],
                                                opts['--no-host-reboot'])
        elif opts['--delete']:
            DefaultFlashManager().delete_firm(runner, opts['--delete'])
        elif opts['--upload']:
            DefaultFlashManager().upload_firm(runner, opts['--upload'][0])
示例#3
0
    def firm(self):
        """Get FIRM information

        :rtype: json
        :return: all nodes' data and retrun code
        """
        runner = self._get_runner('rinv')
        self.result_dict = DefaultInventoryManager().get_firm_info(runner)
        return self._get_result()
示例#4
0
    def inv_dimm(self):
        """Get DIMM information

        :rtype: json
        :return: all nodes' data and retrun code
        """
        runner = self._get_runner('rinv')
        self.result_dict = DefaultInventoryManager().get_inventory_info(
            runner, ['dimm'])
        return self._get_result()
示例#5
0
    def rinv(self, nodesinfo, args):

        # 1, parse agrs
        if not args:
            args = ['all']

        rinv_usage = """
        Usage:
            rinv [-V|--verbose] [all|cpu|dimm|firm|model|serial]

        Options:
            -V --verbose   rinv verbose mode.
        """

        try:
            opts = docopt(rinv_usage, argv=args)

            self.verbose = opts.pop('--verbose')
            action = [k for k, v in opts.items() if v][0]
        except Exception as e:
            self.messager.error("Failed to parse arguments for rinv: %s" %
                                args)
            return

        # 2, validate the args
        if action not in INVENTORY_OPTIONS:
            self.messager.error("Not supported subcommand for rinv: %s" %
                                action)
            return

        # 3, run the subcommands
        runner = OpenBMCInventoryTask(nodesinfo,
                                      callback=self.messager,
                                      debugmode=self.debugmode,
                                      verbose=self.verbose)
        if action == 'firm':
            DefaultInventoryManager().get_firm_info(runner)
        else:
            DefaultInventoryManager().get_inventory_info(runner, action)