gnt-cluster {init, modify} --file-storage-dir
[ganeti-local] / lib / client / gnt_node.py
index e15a6d8..48ed7dd 100644 (file)
@@ -40,7 +40,6 @@ from ganeti import netutils
 from ganeti import pathutils
 from ganeti import ssh
 from ganeti import compat
-from cStringIO import StringIO
 
 from ganeti import confd
 from ganeti.confd import client as confd_client
@@ -303,7 +302,7 @@ def ListNodes(opts, args):
   fmtoverride = dict.fromkeys(["pinst_list", "sinst_list", "tags"],
                               (",".join, False))
 
-  cl = GetClient(query=False)
+  cl = GetClient(query=True)
 
   return GenericList(constants.QR_NODE, selected_fields, args, opts.units,
                      opts.separator, not opts.no_headers,
@@ -517,6 +516,38 @@ def MigrateNode(opts, args):
   return rcode
 
 
+def _FormatNodeInfo(node_info):
+  """Format node information for L{cli.PrintGenericInfo()}.
+
+  """
+  (name, primary_ip, secondary_ip, pinst, sinst, is_mc, drained, offline,
+   master_capable, vm_capable, powered, ndparams, ndparams_custom) = node_info
+  info = [
+    ("Node name", name),
+    ("primary ip", primary_ip),
+    ("secondary ip", secondary_ip),
+    ("master candidate", is_mc),
+    ("drained", drained),
+    ("offline", offline),
+    ]
+  if powered is not None:
+    info.append(("powered", powered))
+  info.extend([
+    ("master_capable", master_capable),
+    ("vm_capable", vm_capable),
+    ])
+  if vm_capable:
+    info.extend([
+      ("primary for instances",
+       [iname for iname in utils.NiceSort(pinst)]),
+      ("secondary for instances",
+       [iname for iname in utils.NiceSort(sinst)]),
+      ])
+  info.append(("node parameters",
+               FormatParamsDictInfo(ndparams_custom, ndparams)))
+  return info
+
+
 def ShowNodeConfig(opts, args):
   """Show node information.
 
@@ -529,8 +560,6 @@ def ShowNodeConfig(opts, args):
   @return: the desired exit code
 
   """
-  # note: if this starts using RPC fields, and we haven't yet fixed
-  # hconfd, then we should revert to query=False
   cl = GetClient(query=True)
   result = cl.QueryNodes(fields=["name", "pip", "sip",
                                  "pinst_list", "sinst_list",
@@ -538,38 +567,10 @@ def ShowNodeConfig(opts, args):
                                  "master_capable", "vm_capable", "powered",
                                  "ndparams", "custom_ndparams"],
                          names=args, use_locking=False)
-
-  for (name, primary_ip, secondary_ip, pinst, sinst, is_mc, drained, offline,
-       master_capable, vm_capable, powered, ndparams,
-       ndparams_custom) in result:
-    ToStdout("Node name: %s", name)
-    ToStdout("  primary ip: %s", primary_ip)
-    ToStdout("  secondary ip: %s", secondary_ip)
-    ToStdout("  master candidate: %s", is_mc)
-    ToStdout("  drained: %s", drained)
-    ToStdout("  offline: %s", offline)
-    if powered is not None:
-      ToStdout("  powered: %s", powered)
-    ToStdout("  master_capable: %s", master_capable)
-    ToStdout("  vm_capable: %s", vm_capable)
-    if vm_capable:
-      if pinst:
-        ToStdout("  primary for instances:")
-        for iname in utils.NiceSort(pinst):
-          ToStdout("    - %s", iname)
-      else:
-        ToStdout("  primary for no instances")
-      if sinst:
-        ToStdout("  secondary for instances:")
-        for iname in utils.NiceSort(sinst):
-          ToStdout("    - %s", iname)
-      else:
-        ToStdout("  secondary for no instances")
-    ToStdout("  node parameters:")
-    buf = StringIO()
-    FormatParameterDict(buf, ndparams_custom, ndparams, level=2)
-    ToStdout(buf.getvalue().rstrip("\n"))
-
+  PrintGenericInfo([
+    _FormatNodeInfo(node_info)
+    for node_info in result
+    ])
   return 0
 
 
@@ -1089,7 +1090,7 @@ commands = {
   "evacuate": (
     EvacuateNode, ARGS_ONE_NODE,
     [FORCE_OPT, IALLOCATOR_OPT, NEW_SECONDARY_OPT, EARLY_RELEASE_OPT,
-     PRIORITY_OPT, PRIMARY_ONLY_OPT, SECONDARY_ONLY_OPT, SUBMIT_OPT],
+     PRIORITY_OPT, PRIMARY_ONLY_OPT, SECONDARY_ONLY_OPT] + SUBMIT_OPTS,
     "[-f] {-I <iallocator> | -n <dst>} [-p | -s] [options...] <node>",
     "Relocate the primary and/or secondary instances from a node"),
   "failover": (
@@ -1102,7 +1103,7 @@ commands = {
     MigrateNode, ARGS_ONE_NODE,
     [FORCE_OPT, NONLIVE_OPT, MIGRATION_MODE_OPT, DST_NODE_OPT,
      IALLOCATOR_OPT, PRIORITY_OPT, IGNORE_IPOLICY_OPT,
-     NORUNTIME_CHGS_OPT, SUBMIT_OPT],
+     NORUNTIME_CHGS_OPT] + SUBMIT_OPTS,
     "[-f] <node>",
     "Migrate all the primary instance on a node away from it"
     " (only for instances of type drbd)"),
@@ -1125,21 +1126,24 @@ commands = {
     "Lists all available fields for nodes"),
   "modify": (
     SetNodeParams, ARGS_ONE_NODE,
-    [FORCE_OPT, SUBMIT_OPT, MC_OPT, DRAINED_OPT, OFFLINE_OPT,
+    [FORCE_OPT] + SUBMIT_OPTS +
+    [MC_OPT, DRAINED_OPT, OFFLINE_OPT,
      CAPAB_MASTER_OPT, CAPAB_VM_OPT, SECONDARY_IP_OPT,
      AUTO_PROMOTE_OPT, DRY_RUN_OPT, PRIORITY_OPT, NODE_PARAMS_OPT,
      NODE_POWERED_OPT, HV_STATE_OPT, DISK_STATE_OPT],
     "<node_name>", "Alters the parameters of a node"),
   "powercycle": (
     PowercycleNode, ARGS_ONE_NODE,
-    [FORCE_OPT, CONFIRM_OPT, DRY_RUN_OPT, PRIORITY_OPT, SUBMIT_OPT],
+    [FORCE_OPT, CONFIRM_OPT, DRY_RUN_OPT, PRIORITY_OPT] + SUBMIT_OPTS,
     "<node_name>", "Tries to forcefully powercycle a node"),
   "power": (
     PowerNode,
     [ArgChoice(min=1, max=1, choices=_LIST_POWER_COMMANDS),
      ArgNode()],
-    [SUBMIT_OPT, AUTO_PROMOTE_OPT, PRIORITY_OPT, IGNORE_STATUS_OPT,
-     FORCE_OPT, NOHDR_OPT, SEP_OPT, OOB_TIMEOUT_OPT, POWER_DELAY_OPT],
+    SUBMIT_OPTS +
+    [AUTO_PROMOTE_OPT, PRIORITY_OPT,
+     IGNORE_STATUS_OPT, FORCE_OPT, NOHDR_OPT, SEP_OPT, OOB_TIMEOUT_OPT,
+     POWER_DELAY_OPT],
     "on|off|cycle|status [nodes...]",
     "Change power state of node by calling out-of-band helper."),
   "remove": (
@@ -1161,14 +1165,14 @@ commands = {
     [ArgNode(min=1, max=1),
      ArgChoice(min=1, max=1, choices=_MODIFIABLE_STORAGE_TYPES),
      ArgFile(min=1, max=1)],
-    [ALLOCATABLE_OPT, DRY_RUN_OPT, PRIORITY_OPT, SUBMIT_OPT],
+    [ALLOCATABLE_OPT, DRY_RUN_OPT, PRIORITY_OPT] + SUBMIT_OPTS,
     "<node_name> <storage_type> <name>", "Modify storage volume on a node"),
   "repair-storage": (
     RepairStorage,
     [ArgNode(min=1, max=1),
      ArgChoice(min=1, max=1, choices=_REPAIRABLE_STORAGE_TYPES),
      ArgFile(min=1, max=1)],
-    [IGNORE_CONSIST_OPT, DRY_RUN_OPT, PRIORITY_OPT, SUBMIT_OPT],
+    [IGNORE_CONSIST_OPT, DRY_RUN_OPT, PRIORITY_OPT] + SUBMIT_OPTS,
     "<node_name> <storage_type> <name>",
     "Repairs a storage volume on a node"),
   "list-tags": (
@@ -1176,11 +1180,11 @@ commands = {
     "<node_name>", "List the tags of the given node"),
   "add-tags": (
     AddTags, [ArgNode(min=1, max=1), ArgUnknown()],
-    [TAG_SRC_OPT, PRIORITY_OPT, SUBMIT_OPT],
+    [TAG_SRC_OPT, PRIORITY_OPT] + SUBMIT_OPTS,
     "<node_name> tag...", "Add tags to the given node"),
   "remove-tags": (
     RemoveTags, [ArgNode(min=1, max=1), ArgUnknown()],
-    [TAG_SRC_OPT, PRIORITY_OPT, SUBMIT_OPT],
+    [TAG_SRC_OPT, PRIORITY_OPT] + SUBMIT_OPTS,
     "<node_name> tag...", "Remove tags from the given node"),
   "health": (
     Health, ARGS_MANY_NODES,
@@ -1192,7 +1196,7 @@ commands = {
     "[<node_name>]", "Query the list of used DRBD minors on the given node"),
   "restricted-command": (
     RestrictedCommand, [ArgUnknown(min=1, max=1)] + ARGS_MANY_NODES,
-    [SYNC_OPT, PRIORITY_OPT, SUBMIT_OPT, SHOW_MACHINE_OPT, NODEGROUP_OPT],
+    [SYNC_OPT, PRIORITY_OPT] + SUBMIT_OPTS + [SHOW_MACHINE_OPT, NODEGROUP_OPT],
     "<command> <node_name> [<node_name>...]",
     "Executes a restricted command on node(s)"),
   }