The code is more modular, and the output is YAML-compliant. QA has been
updated to reflect the new format.

Signed-off-by: Bernardo Dal Seno <bdals...@google.com>
---
 lib/client/gnt_node.py | 71 ++++++++++++++++++++++++++------------------------
 qa/qa_utils.py         | 18 ++-----------
 2 files changed, 39 insertions(+), 50 deletions(-)

diff --git a/lib/client/gnt_node.py b/lib/client/gnt_node.py
index e893b5e..8fd28df 100644
--- a/lib/client/gnt_node.py
+++ b/lib/client/gnt_node.py
@@ -1,7 +1,7 @@
 #
 #
 
-# Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012 Google Inc.
+# Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Google Inc.
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -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
@@ -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.
 
@@ -536,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
 
 
diff --git a/qa/qa_utils.py b/qa/qa_utils.py
index 7f49675..e8b49bd 100644
--- a/qa/qa_utils.py
+++ b/qa/qa_utils.py
@@ -434,20 +434,6 @@ def BackupFile(node, path):
   return result
 
 
-def _ResolveName(cmd, key):
-  """Helper function.
-
-  """
-  master = qa_config.GetMasterNode()
-
-  output = GetCommandOutput(master.primary, utils.ShellQuoteArgs(cmd))
-  for line in output.splitlines():
-    (lkey, lvalue) = line.split(":", 1)
-    if lkey == key:
-      return lvalue.lstrip()
-  raise KeyError("Key not found")
-
-
 def ResolveInstanceName(instance):
   """Gets the full name of an instance.
 
@@ -463,8 +449,8 @@ def ResolveNodeName(node):
   """Gets the full name of a node.
 
   """
-  return _ResolveName(["gnt-node", "info", node.primary],
-                      "Node name")
+  info = GetObjectInfo(["gnt-node", "info", node.primary])
+  return info[0]["Node name"]
 
 
 def GetNodeInstances(node, secondaries=False):
-- 
1.8.1.3

Reply via email to