Revision abefdcff lib/client/gnt_node.py

b/lib/client/gnt_node.py
59 59
  ]
60 60

  
61 61

  
62
#: default list of power commands
63
_LIST_POWER_COMMANDS = ["on", "off", "cycle", "status"]
64

  
65

  
62 66
#: headers (and full field list) for L{ListStorage}
63 67
_LIST_STOR_HEADERS = {
64 68
  constants.SF_NODE: "Node",
......
452 456
  return 0
453 457

  
454 458

  
459
def PowerNode(opts, args):
460
  """Change/ask power state of a node.
461

  
462
  @param opts: the command line options selected by the user
463
  @type args: list
464
  @param args: should contain only one element, the name of
465
      the node to be removed
466
  @rtype: int
467
  @return: the desired exit code
468

  
469
  """
470
  command = args[0]
471
  node = args[1]
472

  
473
  if command not in _LIST_POWER_COMMANDS:
474
    ToStderr("power subcommand %s not supported." % command)
475
    return constants.EXIT_FAILURE
476

  
477
  oob_command = "power-%s" % command
478

  
479
  op = opcodes.OpOutOfBand(node_name=node, command=oob_command)
480
  result = SubmitOpCode(op, opts=opts)
481
  if result:
482
    if oob_command == constants.OOB_POWER_STATUS:
483
      text = "The machine is %spowered"
484
      if result[constants.OOB_POWER_STATUS_POWERED]:
485
        result = text % ""
486
      else:
487
        result = text % "not "
488
    ToStderr(result)
489

  
490
  return constants.EXIT_SUCCESS
491

  
492

  
455 493
def ListVolumes(opts, args):
456 494
  """List logical volumes on node(s).
457 495

  
......
693 731
    PowercycleNode, ARGS_ONE_NODE,
694 732
    [FORCE_OPT, CONFIRM_OPT, DRY_RUN_OPT, PRIORITY_OPT],
695 733
    "<node_name>", "Tries to forcefully powercycle a node"),
734
  'power': (
735
    PowerNode,
736
    [ArgChoice(min=1, max=1, choices=_LIST_POWER_COMMANDS),
737
     ArgNode(min=1, max=1)],
738
    [], "on|off|cycle|status <node>",
739
    "Change power state of node by calling out-of-band helper."),
696 740
  'remove': (
697 741
    RemoveNode, ARGS_ONE_NODE, [DRY_RUN_OPT, PRIORITY_OPT],
698 742
    "<node_name>", "Removes a node from the cluster"),

Also available in: Unified diff