Commit 31d97b2a authored by Guido Trotter's avatar Guido Trotter
Browse files

Support for latin friendly output in node list


Signed-off-by: default avatarGuido Trotter <ultrotter@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 7678409f
......@@ -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.
......
......@@ -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:
......
......@@ -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." %
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment