"vbmc list" to sort the result by domain name

This patch is making the result of "vbmc list" command to sort the table
by the domain name, that's visually easier to follow.

This patch also makes use of the PrettyTable's get_string() method when
printing a table for the "list" and "show" commands.

Change-Id: I6bd6d0d9f5a9d2eeaa791d1e9d56bb3dc4131da2
This commit is contained in:
Lucas Alvares Gomes 2016-05-09 14:15:13 +01:00
parent b14ae0b9ee
commit 03cda5571a
2 changed files with 5 additions and 4 deletions

View File

@ -132,18 +132,19 @@ def main():
manager.stop(domain)
elif args.command == 'list':
ptable = PrettyTable(['Domain name', 'Status', 'Address', 'Port'])
fields = ('Domain name', 'Status', 'Address', 'Port')
ptable = PrettyTable(fields)
for bmc in manager.list():
ptable.add_row([bmc['domain_name'], bmc['status'],
bmc['address'], bmc['port']])
print(ptable)
print(ptable.get_string(sortby=fields[0]))
elif args.command == 'show':
ptable = PrettyTable(['Property', 'Value'])
bmc = manager.show(args.domain_name)
for key, val in sorted(bmc.items()):
ptable.add_row([key, val])
print(ptable)
print(ptable.get_string())
except exception.VirtualBMCError as e:
print(e, file=sys.stderr)

View File

@ -108,8 +108,8 @@ class VBMCTestCase(base.TestCase):
+-------------+---------+---------+------+
| Domain name | Status | Address | Port |
+-------------+---------+---------+------+
| node-1 | running | :: | 321 |
| node-0 | running | :: | 123 |
| node-1 | running | :: | 321 |
+-------------+---------+---------+------+
"""
self.assertEqual(expected_output, out)