Commit 130a6a6f authored by Iustin Pop's avatar Iustin Pop
Browse files

Add a ‘tags’ field to instance and node listing

Currently there isn't any easy way to list all nodes or instance and
their tags; you have to query each node in turn, or list all the tags
via something like “gnt-cluster search-tags '.*'”. Of course, this is
not optimal.

The patch adds a new fields to “gnt-instance list” and “gnt-node list”
called ‘tags’, that will list the tags of the object in comma-separated
form. This field will be empty if there are no tags (when using a
separator this output can still be parsed by other scripts).

At opcode level, there is a new fields called ‘tags’ that returns a
(python) list of the object tags.

Reviewed-by: ultrotter
parent 03a8dbdc
......@@ -1271,7 +1271,7 @@ class LUQueryNodes(NoHooksLU):
_CheckOutputFields(static=["name", "pinst_cnt", "sinst_cnt",
"pinst_list", "sinst_list",
"pip", "sip"],
"pip", "sip", "tags"],
dynamic=self.dynamic_fields,
selected=self.op.output_fields)
......@@ -1342,6 +1342,8 @@ class LUQueryNodes(NoHooksLU):
val = node.primary_ip
elif field == "sip":
val = node.secondary_ip
elif field == "tags":
val = list(node.GetTags())
elif field in self.dynamic_fields:
val = live_data[node.name].get(field, None)
else:
......@@ -2488,7 +2490,7 @@ class LUQueryInstances(NoHooksLU):
_CheckOutputFields(static=["name", "os", "pnode", "snodes",
"admin_state", "admin_ram",
"disk_template", "ip", "mac", "bridge",
"sda_size", "sdb_size", "vcpus"],
"sda_size", "sdb_size", "vcpus", "tags"],
dynamic=self.dynamic_fields,
selected=self.op.output_fields)
......@@ -2581,6 +2583,8 @@ class LUQueryInstances(NoHooksLU):
val = disk.size
elif field == "vcpus":
val = instance.vcpus
elif field == "tags":
val = list(instance.GetTags())
else:
raise errors.ParameterError(field)
iout.append(val)
......
......@@ -575,6 +575,13 @@
instance</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>tags</term>
<listitem>
<simpara>comma-separated list of the instances's
tags</simpara>
</listitem>
</varlistentry>
</variablelist>
</para>
......
......@@ -326,6 +326,13 @@
changes in this value)</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>tags</term>
<listitem>
<simpara>comma-separated list of the node's
tags</simpara>
</listitem>
</varlistentry>
</variablelist>
</para>
......
......@@ -188,7 +188,7 @@ def ListInstances(opts, args):
"ip": "IP Address", "mac": "MAC Address",
"bridge": "Bridge", "vcpus": "VCPUs",
"sda_size": "Disk/0", "sdb_size": "Disk/1",
"status": "Status",
"status": "Status", "tags": "Tags",
}
else:
headers = None
......@@ -200,6 +200,7 @@ def ListInstances(opts, args):
numfields = ["admin_ram", "oper_ram", "sda_size", "sdb_size", "vcpus"]
list_type_fields = ("tags",)
# change raw values to nicer strings
for row in output:
for idx, field in enumerate(selected_fields):
......@@ -224,6 +225,8 @@ def ListInstances(opts, args):
elif field == "sda_size" or field == "sdb_size":
if val is None:
val = "N/A"
elif field in list_type_fields:
val = ",".join(val)
row[idx] = str(val)
data = GenerateTable(separator=opts.separator, headers=headers,
......
......@@ -70,6 +70,7 @@ def ListNodes(opts, args):
"mtotal": "MTotal", "mnode": "MNode", "mfree": "MFree",
"bootid": "BootID",
"ctotal": "CTotal",
"tags": "Tags",
}
else:
headers = None
......@@ -84,13 +85,12 @@ def ListNodes(opts, args):
"pinst_cnt", "sinst_cnt",
"ctotal"]
list_type_fields = ("pinst_list", "sinst_list", "tags")
# change raw values to nicer strings
for row in output:
for idx, field in enumerate(selected_fields):
val = row[idx]
if field == "pinst_list":
val = ",".join(val)
elif field == "sinst_list":
if field in list_type_fields:
val = ",".join(val)
elif val is None:
val = "?"
......
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