Merge "Nova aggregate-details should be more human friendly"
This commit is contained in:
commit
a1391b2ead
@ -163,3 +163,23 @@ class PrintResultTestCase(test_utils.TestCase):
|
||||
'| k3 | 3 |\n'
|
||||
'| k2 | 2 |\n'
|
||||
'+------+-------+\n')
|
||||
|
||||
def test_pretty_choice_list(self):
|
||||
l = []
|
||||
r = utils.pretty_choice_list(l)
|
||||
self.assertEqual(r, "")
|
||||
|
||||
l = ["v1", "v2", "v3"]
|
||||
r = utils.pretty_choice_list(l)
|
||||
self.assertEqual(r, "'v1', 'v2', 'v3'")
|
||||
|
||||
def test_pretty_choice_dict(self):
|
||||
d = {}
|
||||
r = utils.pretty_choice_dict(d)
|
||||
self.assertEqual(r, "")
|
||||
|
||||
d = {"k1": "v1",
|
||||
"k2": "v2",
|
||||
"k3": "v3"}
|
||||
r = utils.pretty_choice_dict(d)
|
||||
self.assertEqual(r, "'k1=v1', 'k2=v2', 'k3=v3'")
|
||||
|
@ -143,6 +143,11 @@ def pretty_choice_list(l):
|
||||
return ', '.join("'%s'" % i for i in l)
|
||||
|
||||
|
||||
def pretty_choice_dict(d):
|
||||
"""Returns a formatted dict as 'key=value'."""
|
||||
return pretty_choice_list(['%s=%s' % (k, d[k]) for k in sorted(d.keys())])
|
||||
|
||||
|
||||
def print_list(objs, fields, formatters={}, sortby_index=None):
|
||||
if sortby_index is None:
|
||||
sortby = None
|
||||
|
@ -2687,7 +2687,17 @@ def do_aggregate_details(cs, args):
|
||||
|
||||
def _print_aggregate_details(aggregate):
|
||||
columns = ['Id', 'Name', 'Availability Zone', 'Hosts', 'Metadata']
|
||||
utils.print_list([aggregate], columns)
|
||||
|
||||
parser_metadata = lambda o: utils.pretty_choice_dict(
|
||||
getattr(o, 'metadata', {}) or {})
|
||||
parser_hosts = lambda o: utils.pretty_choice_list(
|
||||
getattr(o, 'hosts', []))
|
||||
|
||||
formatters = {
|
||||
'Metadata': parser_metadata,
|
||||
'Hosts': parser_hosts,
|
||||
}
|
||||
utils.print_list([aggregate], columns, formatters=formatters)
|
||||
|
||||
|
||||
@utils.arg('server', metavar='<server>', help='Name or ID of server.')
|
||||
|
@ -2517,7 +2517,16 @@ def do_aggregate_details(cs, args):
|
||||
|
||||
def _print_aggregate_details(aggregate):
|
||||
columns = ['Id', 'Name', 'Availability Zone', 'Hosts', 'Metadata']
|
||||
utils.print_list([aggregate], columns)
|
||||
parser_metadata = lambda o: utils.pretty_choice_dict(
|
||||
getattr(o, 'metadata', {}) or {})
|
||||
parser_hosts = lambda o: utils.pretty_choice_list(
|
||||
getattr(o, 'hosts', []))
|
||||
|
||||
formatters = {
|
||||
'Metadata': parser_metadata,
|
||||
'Hosts': parser_hosts,
|
||||
}
|
||||
utils.print_list([aggregate], columns, formatters=formatters)
|
||||
|
||||
|
||||
@utils.arg('server', metavar='<server>', help='Name or ID of server.')
|
||||
|
Loading…
Reference in New Issue
Block a user