Skip to content

Commit

Permalink
Novaclient shell list command should support a minimal server list
Browse files Browse the repository at this point in the history
The Nova API supports both a basic (id and name) and detailed server
list, and this is supported in the client by the "detailed=True"
argument to servers.list().  However the shell do_list() method always
leaves this to its default value.  For administrators on a large
system, or where the tenants has a lot of instances a detailed list
can be painfully slow.

This change adds support for a --minimal option to list.

Fixes bug: 1228137

Change-Id: I3126ee6b372606a98f0d7a4e344556f8c05ae224
  • Loading branch information
Phil Day committed Sep 20, 2013
1 parent cafd5bf commit 8deaf37
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
4 changes: 4 additions & 0 deletions novaclient/tests/v1_1/test_shell.py
Expand Up @@ -679,6 +679,10 @@ def test_list(self):
self.run_command('list')
self.assert_called('GET', '/servers/detail')

def test_list_minimal(self):
self.run_command('list --minimal')
self.assert_called('GET', '/servers')

def test_list_with_images(self):
self.run_command('list --image 1')
self.assert_called('GET', '/servers/detail?image=1')
Expand Down
16 changes: 14 additions & 2 deletions novaclient/v1_1/shell.py
Expand Up @@ -1091,6 +1091,11 @@ def do_image_delete(cs, args):
metavar='<fields>',
help='Comma-separated list of fields to display. '
'Use the show command to see which fields are available.')
@utils.arg('--minimal',
dest='minimal',
action="store_true",
default=False,
help='Get only uuid and name.')
def do_list(cs, args):
"""List active servers."""
imageid = None
Expand Down Expand Up @@ -1126,15 +1131,22 @@ def do_list(cs, args):

id_col = 'ID'

servers = cs.servers.list(search_opts=search_opts)
detailed = not args.minimal

servers = cs.servers.list(detailed=detailed,
search_opts=search_opts)
convert = [('OS-EXT-SRV-ATTR:host', 'host'),
('OS-EXT-STS:task_state', 'task_state'),
('OS-EXT-SRV-ATTR:instance_name', 'instance_name'),
('OS-EXT-STS:power_state', 'power_state'),
('hostId', 'host_id')]
_translate_keys(servers, convert)
_translate_extended_states(servers)
if field_titles:
if args.minimal:
columns = [
id_col,
'Name']
elif field_titles:
columns = [id_col] + field_titles
else:
columns = [
Expand Down
16 changes: 14 additions & 2 deletions novaclient/v3/shell.py
Expand Up @@ -975,6 +975,11 @@ def do_image_delete(cs, args):
metavar='<fields>',
help='Comma-separated list of fields to display. '
'Use the show command to see which fields are available.')
@utils.arg('--minimal',
dest='minimal',
action="store_true",
default=False,
help='Get only uuid and name.')
def do_list(cs, args):
"""List active servers."""
imageid = None
Expand Down Expand Up @@ -1010,15 +1015,22 @@ def do_list(cs, args):

id_col = 'ID'

servers = cs.servers.list(search_opts=search_opts)
detailed = not args.minimal

servers = cs.servers.list(detailed=detailed,
search_opts=search_opts)
convert = [('OS-EXT-SRV-ATTR:host', 'host'),
('OS-EXT-STS:task_state', 'task_state'),
('OS-EXT-SRV-ATTR:instance_name', 'instance_name'),
('OS-EXT-STS:power_state', 'power_state'),
('hostId', 'host_id')]
_translate_keys(servers, convert)
_translate_extended_states(servers)
if field_titles:
if args.minimal:
columns = [
id_col,
'Name']
elif field_titles:
columns = [id_col] + field_titles
else:
columns = [
Expand Down

0 comments on commit 8deaf37

Please sign in to comment.