Convert call_blockdev_addchildren to new result
[ganeti-local] / scripts / gnt-node
index 40bf594..c60ab41 100755 (executable)
@@ -77,7 +77,7 @@ def AddNode(opts, args):
 
   try:
     output = cl.QueryNodes(names=[node], fields=['name', 'sip'],
-                           use_locking=True)
+                           use_locking=False)
     node_exists, sip = output[0]
   except (errors.OpPrereqError, errors.OpExecError):
     node_exists = ""
@@ -142,7 +142,7 @@ def ListNodes(opts, args):
   else:
     selected_fields = opts.output.split(",")
 
-  output = GetClient().QueryNodes([], selected_fields, opts.do_locking)
+  output = GetClient().QueryNodes(args, selected_fields, opts.do_locking)
 
   if not opts.no_headers:
     headers = _LIST_HEADERS
@@ -206,7 +206,7 @@ def EvacuateNode(opts, args):
   src_node = args[0]
 
   result = cl.QueryNodes(names=[src_node], fields=selected_fields,
-                         use_locking=True)
+                         use_locking=False)
   src_node, sinst = result[0]
 
   if not sinst:
@@ -214,7 +214,8 @@ def EvacuateNode(opts, args):
     return constants.EXIT_SUCCESS
 
   if dst_node is not None:
-    result = cl.QueryNodes(names=[dst_node], fields=["name"], use_locking=True)
+    result = cl.QueryNodes(names=[dst_node], fields=["name"],
+                           use_locking=False)
     dst_node = result[0][0]
 
     if src_node == dst_node:
@@ -263,7 +264,7 @@ def FailoverNode(opts, args):
   # these fields are static data anyway, so it doesn't matter, but
   # locking=True should be safer
   result = cl.QueryNodes(names=args, fields=selected_fields,
-                         use_locking=True)
+                         use_locking=False)
   node, pinst = result[0]
 
   if not pinst:
@@ -301,7 +302,7 @@ def MigrateNode(opts, args):
   force = opts.force
   selected_fields = ["name", "pinst_list"]
 
-  result = cl.QueryNodes(names=args, fields=selected_fields, use_locking=True)
+  result = cl.QueryNodes(names=args, fields=selected_fields, use_locking=False)
   node, pinst = result[0]
 
   if not pinst:
@@ -348,7 +349,7 @@ def ShowNodeConfig(opts, args):
   result = cl.QueryNodes(fields=["name", "pip", "sip",
                                  "pinst_list", "sinst_list",
                                  "master_candidate", "drained", "offline"],
-                         names=args, use_locking=True)
+                         names=args, use_locking=False)
 
   for (name, primary_ip, secondary_ip, pinst, sinst,
        is_mc, drained, offline) in result:
@@ -390,6 +391,28 @@ def RemoveNode(opts, args):
   return 0
 
 
+def PowercycleNode(opts, args):
+  """Remove a node from the cluster.
+
+  @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
+
+  """
+  node = args[0]
+  if (not opts.confirm and
+      not AskUser("Are you sure you want to hard powercycle node %s?" % node)):
+    return 2
+
+  op = opcodes.OpPowercycleNode(node_name=node, force=opts.force)
+  result = SubmitOpCode(op)
+  ToStderr(result)
+  return 0
+
+
 def ListVolumes(opts, args):
   """List logical volumes on node(s).
 
@@ -528,10 +551,10 @@ commands = {
                " (only for instances of type drbd)"),
   'info': (ShowNodeConfig, ARGS_ANY, [DEBUG_OPT],
            "[<node_name>...]", "Show information about the node(s)"),
-  'list': (ListNodes, ARGS_NONE,
-           [DEBUG_OPT, NOHDR_OPT, SEP_OPT, USEUNITS_OPT, FIELDS_OPT,
-            SUBMIT_OPT, SYNC_OPT],
-           "", "Lists the nodes in the cluster. The available fields"
+  'list': (ListNodes, ARGS_ANY,
+           [DEBUG_OPT, NOHDR_OPT, SEP_OPT, USEUNITS_OPT, FIELDS_OPT, SYNC_OPT],
+           "[nodes...]",
+           "Lists the nodes in the cluster. The available fields"
            " are (see the man page for details): %s"
            " The default field list is (in order): %s." %
            (", ".join(_LIST_HEADERS), ", ".join(_LIST_DEF_FIELDS))),
@@ -540,15 +563,19 @@ commands = {
               SUBMIT_OPT,
               make_option("-C", "--master-candidate", dest="master_candidate",
                           choices=('yes', 'no'), default=None,
+                          metavar="yes|no",
                           help="Set the master_candidate flag on the node"),
-              make_option("-O", "--offline", dest="offline",
+
+              make_option("-O", "--offline", dest="offline", metavar="yes|no",
                           choices=('yes', 'no'), default=None,
                           help="Set the offline flag on the node"),
-              make_option("-D", "--drained", dest="drained",
+              make_option("-D", "--drained", dest="drained", metavar="yes|no",
                           choices=('yes', 'no'), default=None,
                           help="Set the drained flag on the node"),
               ],
              "<instance>", "Alters the parameters of an instance"),
+  'powercycle': (PowercycleNode, ARGS_ONE, [DEBUG_OPT, FORCE_OPT, CONFIRM_OPT],
+                 "<node_name>", "Tries to forcefully powercycle a node"),
   'remove': (RemoveNode, ARGS_ONE, [DEBUG_OPT],
              "<node_name>", "Removes a node from the cluster"),
   'volumes': (ListVolumes, ARGS_ANY,