Commit d8052456 authored by Iustin Pop's avatar Iustin Pop
Browse files

Modify the default output of gnt-instance list

This patch adds a new field available for selection in gnt-instance list
names "status" which represents the combined value of "admin_state" and
"oper_state". Since this is much easier to parse (e.g. gnt-instance list
|grep ERROR), we also modify the default field list to use this instead
of the admin/oper state fields.

Reviewed-by: imsnah
parent c68d1f43
......@@ -2418,7 +2418,7 @@ class LUQueryInstances(NoHooksLU):
This checks that the fields required are valid output fields.
"""
self.dynamic_fields = frozenset(["oper_state", "oper_ram"])
self.dynamic_fields = frozenset(["oper_state", "oper_ram", "status"])
_CheckOutputFields(static=["name", "os", "pnode", "snodes",
"admin_state", "admin_ram",
"disk_template", "ip", "mac", "bridge",
......@@ -2475,6 +2475,21 @@ class LUQueryInstances(NoHooksLU):
val = None
else:
val = bool(live_data.get(instance.name))
elif field == "status":
if instance.primary_node in bad_nodes:
val = "ERROR_nodedown"
else:
running = bool(live_data.get(instance.name))
if running:
if instance.status != "down":
val = "running"
else:
val = "ERROR_up"
else:
if instance.status != "down":
val = "ERROR_down"
else:
val = "ADMIN_down"
elif field == "admin_ram":
val = instance.memory
elif field == "oper_ram":
......
......@@ -405,8 +405,27 @@
<varlistentry>
<term>oper_state</term>
<listitem>
<simpara>the actual state of the instance; can take of
the values "running", "stopped", "(node down)"</simpara>
<simpara>the actual state of the instance; can be
one of the values "running", "stopped", "(node
down)"</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>status</term>
<listitem>
<simpara>combined form of admin_state and oper_stat;
this can be one of:
<computeroutput>ERROR_nodedown</computeroutput> if the
node of the instance is down,
<computeroutput>ERROR_down</computeroutput> if the
instance should run but is down,
<computeroutput>ERROR_up</computeroutput> if the
instance should be stopped but is actually running,
<computeroutput>ADMIN_down</computeroutput> if the
instance has been stopped (and is stopped) and
<computeroutput>running</computeroutput> if the
instance is set to be running (and is
running)</simpara>
</listitem>
</varlistentry>
<varlistentry>
......
......@@ -162,8 +162,7 @@ def ListInstances(opts, args):
"""
if opts.output is None:
selected_fields = ["name", "os", "pnode", "admin_state",
"oper_state", "oper_ram"]
selected_fields = ["name", "os", "pnode", "status", "oper_ram"]
else:
selected_fields = opts.output.split(",")
......@@ -171,13 +170,16 @@ def ListInstances(opts, args):
output = SubmitOpCode(op)
if not opts.no_headers:
headers = {"name": "Instance", "os": "OS", "pnode": "Primary_node",
"snodes": "Secondary_Nodes", "admin_state": "Autostart",
"oper_state": "Status", "admin_ram": "Configured_memory",
"oper_ram": "Memory", "disk_template": "Disk_template",
"ip": "IP Address", "mac": "MAC Address",
"bridge": "Bridge", "vcpus": "VCPUs",
"sda_size": "Disk/0", "sdb_size": "Disk/1"}
headers = {
"name": "Instance", "os": "OS", "pnode": "Primary_node",
"snodes": "Secondary_Nodes", "admin_state": "Autostart",
"oper_state": "Running", "admin_ram": "Configured_memory",
"oper_ram": "Memory", "disk_template": "Disk_template",
"ip": "IP Address", "mac": "MAC Address",
"bridge": "Bridge", "vcpus": "VCPUs",
"sda_size": "Disk/0", "sdb_size": "Disk/1",
"status": "Status",
}
else:
headers = None
......@@ -810,12 +812,12 @@ commands = {
'info': (ShowInstanceConfig, ARGS_ANY, [DEBUG_OPT], "[<instance>...]",
"Show information on the specified instance"),
'list': (ListInstances, ARGS_NONE,
[DEBUG_OPT, NOHDR_OPT, SEP_OPT, USEUNITS_OPT, FIELDS_OPT],
"", "Lists the instances and their status. The available fields"
" are (see the man page for details): oper_state, oper_ram,"
[DEBUG_OPT, NOHDR_OPT, SEP_OPT, USEUNITS_OPT, FIELDS_OPT], "",
"Lists the instances and their status. The available fields are"
" (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, admin_state, oper_state,"
" list is (in order): name, os, pnode, status,"
" oper_ram."),
'reinstall': (ReinstallInstance, ARGS_ONE, [DEBUG_OPT, FORCE_OPT, os_opt],
"[-f] <instance>", "Reinstall the instance"),
......
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