From 31d97b2a3756c45fc14cd206e2596925cd3b9796 Mon Sep 17 00:00:00 2001 From: Guido Trotter <ultrotter@google.com> Date: Tue, 25 May 2010 16:30:52 +0100 Subject: [PATCH] Support for latin friendly output in node list Signed-off-by: Guido Trotter <ultrotter@google.com> Reviewed-by: Iustin Pop <iustin@google.com> --- lib/cli.py | 7 +++++++ man/gnt-node.sgml | 8 ++++++++ scripts/gnt-node | 17 ++++++++++++++++- 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/lib/cli.py b/lib/cli.py index f598320e6..5ccdfa0ef 100644 --- a/lib/cli.py +++ b/lib/cli.py @@ -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. diff --git a/man/gnt-node.sgml b/man/gnt-node.sgml index eb76deb45..22b89a048 100644 --- a/man/gnt-node.sgml +++ b/man/gnt-node.sgml @@ -253,6 +253,8 @@ <arg>--units=<replaceable>UNITS</replaceable></arg> <arg>-o <replaceable>[+]FIELD,...</replaceable></arg> <sbr> + <arg>--roman</arg> + <sbr> <arg rep="repeat">node</arg> </cmdsynopsis> @@ -285,6 +287,12 @@ cluster (but this might stall the query for a long time). </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: diff --git a/scripts/gnt-node b/scripts/gnt-node index 61c4f2714..8ca09e41b 100755 --- a/scripts/gnt-node +++ b/scripts/gnt-node @@ -28,6 +28,11 @@ 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." % -- GitLab