diff --git a/lib/client/gnt_node.py b/lib/client/gnt_node.py index 86d277db78ac531e98c7eda60c04772ea6d3e55c..830e8784b3d3e4d02d65744f03d7ab1ad3b9b336 100644 --- a/lib/client/gnt_node.py +++ b/lib/client/gnt_node.py @@ -59,6 +59,10 @@ _LIST_STOR_DEF_FIELDS = [ ] +#: default list of power commands +_LIST_POWER_COMMANDS = ["on", "off", "cycle", "status"] + + #: headers (and full field list) for L{ListStorage} _LIST_STOR_HEADERS = { constants.SF_NODE: "Node", @@ -452,6 +456,40 @@ def PowercycleNode(opts, args): return 0 +def PowerNode(opts, args): + """Change/ask power state of a node. + + @param opts: the command line options selected by the user + @type args: list + @param args: should contain only one element, the name of + the node to be removed + @rtype: int + @return: the desired exit code + + """ + command = args[0] + node = args[1] + + if command not in _LIST_POWER_COMMANDS: + ToStderr("power subcommand %s not supported." % command) + return constants.EXIT_FAILURE + + oob_command = "power-%s" % command + + op = opcodes.OpOutOfBand(node_name=node, command=oob_command) + result = SubmitOpCode(op, opts=opts) + if result: + if oob_command == constants.OOB_POWER_STATUS: + text = "The machine is %spowered" + if result[constants.OOB_POWER_STATUS_POWERED]: + result = text % "" + else: + result = text % "not " + ToStderr(result) + + return constants.EXIT_SUCCESS + + def ListVolumes(opts, args): """List logical volumes on node(s). @@ -693,6 +731,12 @@ commands = { PowercycleNode, ARGS_ONE_NODE, [FORCE_OPT, CONFIRM_OPT, DRY_RUN_OPT, PRIORITY_OPT], "", "Tries to forcefully powercycle a node"), + 'power': ( + PowerNode, + [ArgChoice(min=1, max=1, choices=_LIST_POWER_COMMANDS), + ArgNode(min=1, max=1)], + [], "on|off|cycle|status ", + "Change power state of node by calling out-of-band helper."), 'remove': ( RemoveNode, ARGS_ONE_NODE, [DRY_RUN_OPT, PRIORITY_OPT], "", "Removes a node from the cluster"), diff --git a/man/gnt-node.rst b/man/gnt-node.rst index 0bb3c0791d137df6b9c988c78cb69253af22bd7e..da5722f7cb67accbf51e0c9e4da390895ebecedb 100644 --- a/man/gnt-node.rst +++ b/man/gnt-node.rst @@ -593,3 +593,12 @@ enabled. The ``--yes`` option can be used to skip confirmation, while the ``--force`` option is needed if the target node is the master node. + +POWER +~~~~~ + +**power** on|off|cycle|status {*node*} + +This commands calls out to out-of-band management to change the power +state of given node. With ``status`` you get the power status as reported +by the out-of-band managment script.