def rpower(self, nodesinfo, args): # 1, parse args rpower_usage = """ Usage: rpower [-V|--verbose] [boot|bmcreboot|bmcstate|off|on|reset|softoff|stat|state|status] Options: -V --verbose rpower verbose mode. """ try: opts = docopt(rpower_usage, argv=args) self.verbose = opts.pop('--verbose') action = [k for k, v in opts.items() if v][0] except Exception as e: # It will not be here as perl has validation for args self.messager.error("Failed to parse arguments for rpower: %s" % args) return # 2, validate the args if action not in (POWER_GET_OPTIONS + POWER_SET_OPTIONS + POWER_REBOOT_OPTIONS): self.messager.error("Not supported subcommand for rpower: %s" % action) return # 3, run the subcommands runner = RedfishPowerTask(nodesinfo, callback=self.messager, debugmode=self.debugmode, verbose=self.verbose) DefaultPowerManager().get_power_state(runner)
def power_bmc_reboot(self): """Reboot BMC. :rtype: json :return: all nodes' data and retrun code """ runner = self._get_runner('power') self.result_dict = DefaultPowerManager().reboot_bmc(runner) return self._get_result()
def power_bmc_state(self): """Get BMC status. :rtype: json :return: all nodes' data and retrun code """ runner = self._get_runner('power') self.result_dict = DefaultPowerManager().get_bmc_state(runner) return self._get_result()
def power_boot(self): """Boot host.. :rtype: json :return: all nodes' data and retrun code """ runner = self._get_runner('power') self.result_dict = DefaultPowerManager().reboot(runner, optype='boot') return self._get_result()
def power_softoff(self): """Set host power status off(soft). :rtype: json :return: all nodes' data and retrun code """ runner = self._get_runner('power') self.result_dict = DefaultPowerManager().set_power_state( runner, power_state='softoff') return self._get_result()
def rpower(self, nodesinfo, args): # 1, parse args parser = argparse.ArgumentParser( description='Handle rpower operations.') parser.add_argument('--action', help="rpower subcommand.") parser.add_argument('-V', '--verbose', action='store_true', help="rpower verbose mode.") args.insert(0, '--action') opts = parser.parse_args(args) # 2, validate the args if opts.action is None: self.messager.error("Not specify the subcommand for rpower") return if opts.action not in (POWER_GET_OPTIONS + POWER_SET_OPTIONS + POWER_REBOOT_OPTIONS): self.messager.error("Not supported subcommand for rpower: %s" % opts.action) return # 3, run the subcommands runner = OpenBMCPowerTask(nodesinfo, callback=self.messager, debugmode=self.debugmode, verbose=opts.verbose) if opts.action == 'bmcstate': DefaultPowerManager().get_bmc_state(runner) elif opts.action == 'bmcreboot': DefaultPowerManager().reboot_bmc(runner) elif opts.action in POWER_GET_OPTIONS: DefaultPowerManager().get_power_state(runner) elif opts.action in POWER_REBOOT_OPTIONS: DefaultPowerManager().reboot(runner, optype=opts.action) else: DefaultPowerManager().set_power_state(runner, power_state=opts.action)