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