From 03cda5571ab55763d54f952d29a591a80e4c9e84 Mon Sep 17 00:00:00 2001 From: Lucas Alvares Gomes Date: Mon, 9 May 2016 14:15:13 +0100 Subject: [PATCH] "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 --- virtualbmc/cmd/vbmc.py | 7 ++++--- virtualbmc/tests/unit/cmd/test_vbmc.py | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/virtualbmc/cmd/vbmc.py b/virtualbmc/cmd/vbmc.py index 714ab0b..4e3e0e5 100644 --- a/virtualbmc/cmd/vbmc.py +++ b/virtualbmc/cmd/vbmc.py @@ -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) diff --git a/virtualbmc/tests/unit/cmd/test_vbmc.py b/virtualbmc/tests/unit/cmd/test_vbmc.py index a2870f7..3fa39a7 100644 --- a/virtualbmc/tests/unit/cmd/test_vbmc.py +++ b/virtualbmc/tests/unit/cmd/test_vbmc.py @@ -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)