Commit 00430f8e authored by Iustin Pop's avatar Iustin Pop
Browse files

Make cli.py use FieldSet for matching fields

This changes cli.py to FieldSet usage so that gnt-instance list will
format nicely the disk.size/*, and the count of disks/nics.

Reviewed-by: ultrotter
parent a2d2e1a7
......@@ -764,6 +764,9 @@ def GenerateTable(headers, fields, separator, data,
if unitfields is None:
unitfields = []
numfields = utils.FieldSet(*numfields)
unitfields = utils.FieldSet(*unitfields)
format_fields = []
for field in fields:
if headers and field not in headers:
......@@ -773,7 +776,7 @@ def GenerateTable(headers, fields, separator, data,
headers[field] = field
if separator is not None:
format_fields.append("%s")
elif field in numfields:
elif numfields.Matches(field):
format_fields.append("%*s")
else:
format_fields.append("%-*s")
......@@ -786,7 +789,7 @@ def GenerateTable(headers, fields, separator, data,
for row in data:
for idx, val in enumerate(row):
if fields[idx] in unitfields:
if unitfields.Matches(fields[idx]):
try:
val = int(val)
except ValueError:
......
......@@ -221,17 +221,19 @@ def ListInstances(opts, args):
"be/memory": "Configured_memory",
"be/vcpus": "VCPUs",
"be/auto_balance": "Auto_balance",
"disk.count": "Disks",
"nic.count": "NICs",
}
else:
headers = None
if opts.human_readable:
unitfields = ["be/memory", "oper_ram", "sda_size", "sdb_size"]
unitfields = ["be/memory", "oper_ram", "sd(a|b)_size", "disk.size/.*"]
else:
unitfields = None
numfields = ["be/memory", "oper_ram", "sda_size", "sdb_size", "be/vcpus",
"serial_no"]
numfields = ["be/memory", "oper_ram", "sd(a|b)_size", "be/vcpus",
"serial_no", "(disk|nic).count", "disk.size/.*"]
list_type_fields = ("tags",)
# change raw values to nicer strings
......
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