Merge "Improve hypervisor-show print list"

This commit is contained in:
Jenkins 2015-07-24 22:38:18 +00:00 committed by Gerrit Code Review
commit 169b8a08ce
2 changed files with 19 additions and 1 deletions

View File

@ -266,6 +266,20 @@ class PrintResultTestCase(test_utils.TestCase):
'+----------+----------------+\n',
sys.stdout.getvalue())
@mock.patch('sys.stdout', six.StringIO())
def test_print_large_dict_list(self):
dict = {'k': ['foo1', 'bar1', 'foo2', 'bar2',
'foo3', 'bar3', 'foo4', 'bar4']}
utils.print_dict(dict, wrap=40)
self.assertEqual(
'+----------+------------------------------------------+\n'
'| Property | Value |\n'
'+----------+------------------------------------------+\n'
'| k | ["foo1", "bar1", "foo2", "bar2", "foo3", |\n'
'| | "bar3", "foo4", "bar4"] |\n'
'+----------+------------------------------------------+\n',
sys.stdout.getvalue())
class FlattenTestCase(test_utils.TestCase):
def test_flattening(self):

View File

@ -3667,10 +3667,14 @@ def do_hypervisor_servers(cs, args):
'hypervisor',
metavar='<hypervisor>',
help=_('Name or ID of the hypervisor to show the details of.'))
@cliutils.arg(
'--wrap', dest='wrap', metavar='<integer>', default=40,
help=_('Wrap the output to a specified length. '
'Default is 40 or 0 to disable'))
def do_hypervisor_show(cs, args):
"""Display the details of the specified hypervisor."""
hyper = _find_hypervisor(cs, args.hypervisor)
utils.print_dict(utils.flatten_dict(hyper._info))
utils.print_dict(utils.flatten_dict(hyper._info), wrap=int(args.wrap))
@cliutils.arg(