Merge "Make list flavor show extra specs optional."

This commit is contained in:
Jenkins 2013-04-22 19:19:29 +00:00 committed by Gerrit Code Review
commit b9f27f6d94
2 changed files with 25 additions and 9 deletions

View File

@ -391,10 +391,10 @@ def _print_flavor_extra_specs(flavor):
return "N/A"
def _print_flavor_list(cs, flavors):
def _print_flavor_list(cs, flavors, show_extra_specs=False):
_translate_flavor_keys(flavors)
formatters = {'extra_specs': _print_flavor_extra_specs}
utils.print_list(flavors, [
headers = [
'ID',
'Name',
'Memory_MB',
@ -404,13 +404,26 @@ def _print_flavor_list(cs, flavors):
'VCPUs',
'RXTX_Factor',
'Is_Public',
'extra_specs'], formatters)
]
if show_extra_specs:
formatters = {'extra_specs': _print_flavor_extra_specs}
headers.append('extra_specs')
else:
formatters = {}
utils.print_list(flavors, headers, formatters)
def do_flavor_list(cs, _args):
@utils.arg('--extra-specs',
dest='extra_specs',
action='store_true',
default=False,
help='Get extra-specs of each flavor.')
def do_flavor_list(cs, args):
"""Print a list of available 'flavors' (sizes of servers)."""
flavors = cs.flavors.list()
_print_flavor_list(cs, flavors)
_print_flavor_list(cs, flavors, args.extra_specs)
@utils.arg('flavor',

View File

@ -390,6 +390,10 @@ class ShellTest(utils.TestCase):
def test_flavor_list(self):
self.run_command('flavor-list')
self.assert_called_anytime('GET', '/flavors/detail')
def test_flavor_list_with_extra_specs(self):
self.run_command('flavor-list --extra-specs')
self.assert_called('GET', '/flavors/aa1/os-extra_specs')
self.assert_called_anytime('GET', '/flavors/detail')
@ -771,9 +775,8 @@ class ShellTest(utils.TestCase):
self.run_command("flavor-create flavorcreate "
"1234 512 10 1 --swap 1024 --ephemeral 10 "
"--is-public true")
self.assert_called('POST', '/flavors', pos=-3)
self.assert_called('GET', '/flavors/1', pos=-2)
self.assert_called('GET', '/flavors/1/os-extra_specs', pos=-1)
self.assert_called('POST', '/flavors', pos=-2)
self.assert_called('GET', '/flavors/1', pos=-1)
def test_aggregate_list(self):
self.run_command('aggregate-list')