Make list flavor show extra specs optional.

Flavor list will get each flavors extra_specs by making fresh requests to nova.
When there are lots of flavors, the flavor list will take a while to run. So
let us make show extra-specs optional.

Fix bug: #1166455

Change-Id: I86aef1035be6a88b8d9fb49a89f5a608a72589dd
This commit is contained in:
Ubuntu 2013-04-17 13:12:36 +00:00 committed by gtt116
parent 74132e5078
commit 339689483d
2 changed files with 25 additions and 9 deletions
novaclient/v1_1
tests/v1_1

@ -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',

@ -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')