Support for latin friendly output in node list
authorGuido Trotter <ultrotter@google.com>
Tue, 25 May 2010 15:30:52 +0000 (16:30 +0100)
committerGuido Trotter <ultrotter@google.com>
Tue, 25 May 2010 15:57:17 +0000 (16:57 +0100)
Signed-off-by: Guido Trotter <ultrotter@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>

lib/cli.py
man/gnt-node.sgml
scripts/gnt-node

index f598320..5ccdfa0 100644 (file)
@@ -114,6 +114,7 @@ __all__ = [
   "READD_OPT",
   "REBOOT_TYPE_OPT",
   "REMOVE_UIDS_OPT",
+  "ROMAN_OPT",
   "SECONDARY_IP_OPT",
   "SELECT_OS_OPT",
   "SEP_OPT",
@@ -950,6 +951,12 @@ REMOVE_UIDS_OPT = cli_option("--remove-uids", default=None,
                                    " ranges separated by commas, to be"
                                    " removed from the user-id pool"))
 
+ROMAN_OPT = cli_option("--roman",
+                       dest="roman_integers", default=False,
+                       action="store_true",
+                       help="Use roman numbers for positive integers")
+
+
 
 def _ParseArgs(argv, commands, aliases):
   """Parser for the command line arguments.
index eb76deb..22b89a0 100644 (file)
         <arg>--units=<replaceable>UNITS</replaceable></arg>
         <arg>-o <replaceable>[+]FIELD,...</replaceable></arg>
         <sbr>
+        <arg>--roman</arg>
+        <sbr>
         <arg rep="repeat">node</arg>
       </cmdsynopsis>
 
       </para>
 
       <para>
+        Passing the <option>--roman</option> option gnt-node list will try to
+        output some of its fields in a latin-friendly way. This is not the
+        default for backwards compatibility.
+      </para>
+
+      <para>
         The <option>-o</option> option takes a comma-separated list of
         output fields. The available fields and their meaning are:
         <variablelist>
index 61c4f27..8ca09e4 100755 (executable)
 
 import sys
 
+try:
+  import roman
+except ImportError:
+  roman = None
+
 from ganeti.cli import *
 from ganeti import opcodes
 from ganeti import utils
@@ -207,6 +212,10 @@ def ListNodes(opts, args):
                "pinst_cnt", "sinst_cnt",
                "ctotal", "serial_no"]
 
+  latinfriendlyfields = ["pinst_cnt", "sinst_cnt",
+                         "ctotal", "cnodes", "csockets",
+                         "serial_no"]
+
   list_type_fields = ("pinst_list", "sinst_list", "tags")
   # change raw values to nicer strings
   for row in output:
@@ -223,6 +232,12 @@ def ListNodes(opts, args):
         val = utils.FormatTime(val)
       elif val is None:
         val = "?"
+      elif (roman is not None and opts.roman_integers
+            and field in latinfriendlyfields):
+        try:
+          val = roman.toRoman(val)
+        except roman.RomanError:
+          pass
       row[idx] = str(val)
 
   data = GenerateTable(separator=opts.separator, headers=headers,
@@ -662,7 +677,7 @@ commands = {
     "[<node_name>...]", "Show information about the node(s)"),
   'list': (
     ListNodes, ARGS_MANY_NODES,
-    [NOHDR_OPT, SEP_OPT, USEUNITS_OPT, FIELDS_OPT, SYNC_OPT],
+    [NOHDR_OPT, SEP_OPT, USEUNITS_OPT, FIELDS_OPT, SYNC_OPT, ROMAN_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." %