Commit 48c4dfa8 authored by Iustin Pop's avatar Iustin Pop

Improve the gnt-* list field selection

This patch allows the '-o' option to the list subcommands to add more
fields to the default list instead of replacing the default list by
prefixing the fields list with '+'.

The patch also moves the listing (in the help output) of the default
field list from hardcoded to built at runtime from the actual list.

Reviewed-by: ultrotter
parent e8a4c138
...@@ -374,7 +374,7 @@ ...@@ -374,7 +374,7 @@
<command>list</command> <command>list</command>
<arg>--no-headers</arg> <arg>--no-headers</arg>
<arg>--separator=<replaceable>SEPARATOR</replaceable></arg> <arg>--separator=<replaceable>SEPARATOR</replaceable></arg>
<arg>-o <replaceable>FIELD,...</replaceable></arg> <arg>-o <replaceable>[+]FIELD,...</replaceable></arg>
</cmdsynopsis> </cmdsynopsis>
<para> <para>
...@@ -516,6 +516,14 @@ ...@@ -516,6 +516,14 @@
</variablelist> </variablelist>
</para> </para>
<para>
If the value of the option starts with the character
<constant>+</constant>, the new fields will be added to the
default list. This allows to quickly see the default list
plus a few other fields, instead of retyping the entire list
of fields.
</para>
<para> <para>
There is a subtle grouping about the available output There is a subtle grouping about the available output
fields: all fields except for <option>oper_state</option> fields: all fields except for <option>oper_state</option>
......
...@@ -210,7 +210,7 @@ ...@@ -210,7 +210,7 @@
<command>list</command> <command>list</command>
<arg>--no-headers</arg> <arg>--no-headers</arg>
<arg>--separator=<replaceable>SEPARATOR</replaceable></arg> <arg>--separator=<replaceable>SEPARATOR</replaceable></arg>
<arg>-o <replaceable>FIELD,...</replaceable></arg> <arg>-o <replaceable>[+]FIELD,...</replaceable></arg>
</cmdsynopsis> </cmdsynopsis>
<para> <para>
...@@ -329,6 +329,14 @@ ...@@ -329,6 +329,14 @@
</variablelist> </variablelist>
</para> </para>
<para>
If the value of the option starts with the character
<constant>+</constant>, the new fields will be added to the
default list. This allows to quickly see the default list plus
a few other fields, instead of retyping the entire list of
fields.
</para>
<para> <para>
Note that some of this fields are known from the configuration Note that some of this fields are known from the configuration
of the cluster (<simplelist type="inline"> of the cluster (<simplelist type="inline">
......
...@@ -40,6 +40,10 @@ _SHUTDOWN_NODES_SEC = "nodes-sec" ...@@ -40,6 +40,10 @@ _SHUTDOWN_NODES_SEC = "nodes-sec"
_SHUTDOWN_INSTANCES = "instances" _SHUTDOWN_INSTANCES = "instances"
_LIST_DEF_FIELDS = [
"name", "os", "pnode", "status", "oper_ram",
]
def _ExpandMultiNames(mode, names): def _ExpandMultiNames(mode, names):
"""Expand the given names using the passed mode. """Expand the given names using the passed mode.
...@@ -163,7 +167,9 @@ def ListInstances(opts, args): ...@@ -163,7 +167,9 @@ def ListInstances(opts, args):
""" """
if opts.output is None: if opts.output is None:
selected_fields = ["name", "os", "pnode", "status", "oper_ram"] selected_fields = _LIST_DEF_FIELDS
elif opts.output.startswith("+"):
selected_fields = _LIST_DEF_FIELDS + opts.output[1:].split(",")
else: else:
selected_fields = opts.output.split(",") selected_fields = opts.output.split(",")
...@@ -816,8 +822,8 @@ commands = { ...@@ -816,8 +822,8 @@ commands = {
" (see the man page for details): status, oper_state, oper_ram," " (see the man page for details): status, oper_state, oper_ram,"
" name, os, pnode, snodes, admin_state, admin_ram, disk_template," " name, os, pnode, snodes, admin_state, admin_ram, disk_template,"
" ip, mac, bridge, sda_size, sdb_size, vcpus. The default field" " ip, mac, bridge, sda_size, sdb_size, vcpus. The default field"
" list is (in order): name, os, pnode, status," " list is (in order): %s." % ", ".join(_LIST_DEF_FIELDS),
" oper_ram."), ),
'reinstall': (ReinstallInstance, ARGS_ONE, [DEBUG_OPT, FORCE_OPT, os_opt], 'reinstall': (ReinstallInstance, ARGS_ONE, [DEBUG_OPT, FORCE_OPT, os_opt],
"[-f] <instance>", "Reinstall a stopped instance"), "[-f] <instance>", "Reinstall a stopped instance"),
'remove': (RemoveInstance, ARGS_ONE, 'remove': (RemoveInstance, ARGS_ONE,
......
...@@ -30,6 +30,12 @@ from ganeti import constants ...@@ -30,6 +30,12 @@ from ganeti import constants
from ganeti import errors from ganeti import errors
_LIST_DEF_FIELDS = [
"name", "dtotal", "dfree",
"mtotal", "mnode", "mfree",
"pinst_cnt", "sinst_cnt",
]
def AddNode(opts, args): def AddNode(opts, args):
"""Add node cli-to-processor bridge.""" """Add node cli-to-processor bridge."""
logger.ToStderr("-- WARNING -- \n" logger.ToStderr("-- WARNING -- \n"
...@@ -46,9 +52,9 @@ def ListNodes(opts, args): ...@@ -46,9 +52,9 @@ def ListNodes(opts, args):
""" """
if opts.output is None: if opts.output is None:
selected_fields = ["name", "dtotal", "dfree", selected_fields = _LIST_DEF_FIELDS
"mtotal", "mnode", "mfree", elif opts.output.startswith("+"):
"pinst_cnt", "sinst_cnt"] selected_fields = _LIST_DEF_FIELDS + opts.output[1:].split(",")
else: else:
selected_fields = opts.output.split(",") selected_fields = opts.output.split(",")
...@@ -314,8 +320,8 @@ commands = { ...@@ -314,8 +320,8 @@ commands = {
" are (see the man page for details): name, pinst_cnt, pinst_list," " are (see the man page for details): name, pinst_cnt, pinst_list,"
" sinst_cnt, sinst_list, pip, sip, dtotal, dfree, mtotal, mnode," " sinst_cnt, sinst_list, pip, sip, dtotal, dfree, mtotal, mnode,"
" mfree, bootid, cpu_count. The default field list is" " mfree, bootid, cpu_count. The default field list is"
" (in order): name," " (in order): %s." % ", ".join(_LIST_DEF_FIELDS),
" dtotal, dfree, mtotal, mnode, mfree, pinst_cnt, sinst_cnt."), ),
'remove': (RemoveNode, ARGS_ONE, [DEBUG_OPT], 'remove': (RemoveNode, ARGS_ONE, [DEBUG_OPT],
"<node_name>", "Removes a node from the cluster"), "<node_name>", "Removes a node from the cluster"),
'volumes': (ListVolumes, ARGS_ANY, 'volumes': (ListVolumes, ARGS_ANY,
......
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