Fix column names for server list --no-name-lookup

When --long is not present change the 'Image Name' column to
'Image' and add the 'Flavor' column.  These columns will contain
Names unless --no-name-lookup is specified when they will contain IDs.

Change-Id: I92cfb22136aee32616894e60e9227b4da185da99
This commit is contained in:
Dean Troyer 2017-07-17 16:03:49 -05:00
parent 2c57f7bfb2
commit 2689984ba7
4 changed files with 36 additions and 26 deletions

View File

@ -330,7 +330,7 @@ List servers
[--all-projects]
[--project <project> [--project-domain <project-domain>]]
[--long]
[-n | --no-name-lookup]
[--no-name-lookup | -n]
[--marker <server>]
[--limit <num-servers>]
[--deleted]
@ -402,6 +402,8 @@ List servers
Skips image and flavor names lookup
``-n`` may be used as an alias for this option.
.. option:: --marker <server>
The last server of the previous page. Display list of servers

View File

@ -1060,26 +1060,33 @@ class ListServer(command.Lister):
'OS-EXT-AZ:availability_zone',
'OS-EXT-SRV-ATTR:host',
]
elif parsed_args.no_name_lookup:
columns = (
'ID',
'Name',
'Status',
'Image ID',
'Flavor ID',
)
column_headers = tuple(columns)
mixed_case_fields = []
else:
columns = (
if parsed_args.no_name_lookup:
columns = (
'ID',
'Name',
'Status',
'Networks',
'Image ID',
'Flavor ID',
)
else:
columns = (
'ID',
'Name',
'Status',
'Networks',
'Image Name',
'Flavor Name',
)
column_headers = (
'ID',
'Name',
'Status',
'Networks',
'Image Name',
'Image',
'Flavor',
)
column_headers = tuple(columns)
mixed_case_fields = []
marker_id = None

View File

@ -1441,7 +1441,8 @@ class TestServerList(TestServer):
'Name',
'Status',
'Networks',
'Image Name',
'Image',
'Flavor',
)
columns_long = (
'ID',
@ -1459,14 +1460,6 @@ class TestServerList(TestServer):
'Properties',
)
columns_no_name_lookup = (
'ID',
'Name',
'Status',
'Image ID',
'Flavor ID',
)
def setUp(self):
super(TestServerList, self).setUp()
@ -1546,6 +1539,7 @@ class TestServerList(TestServer):
s.status,
server._format_servers_list_networks(s.networks),
self.image.name,
self.flavor.name,
))
self.data_long.append((
s.id,
@ -1568,6 +1562,7 @@ class TestServerList(TestServer):
s.id,
s.name,
s.status,
server._format_servers_list_networks(s.networks),
s.image['id'],
s.flavor['id']
))
@ -1616,7 +1611,7 @@ class TestServerList(TestServer):
columns, data = self.cmd.take_action(parsed_args)
self.servers_mock.list.assert_called_with(**self.kwargs)
self.assertEqual(self.columns_no_name_lookup, columns)
self.assertEqual(self.columns, columns)
self.assertEqual(tuple(self.data_no_name_lookup), tuple(data))
def test_server_list_n_option(self):
@ -1632,7 +1627,7 @@ class TestServerList(TestServer):
columns, data = self.cmd.take_action(parsed_args)
self.servers_mock.list.assert_called_with(**self.kwargs)
self.assertEqual(self.columns_no_name_lookup, columns)
self.assertEqual(self.columns, columns)
self.assertEqual(tuple(self.data_no_name_lookup), tuple(data))
def test_server_list_with_image(self):

View File

@ -0,0 +1,6 @@
---
features:
- |
Add ``--no-name-lookup`` option to ``server list`` command to skip the lookup of
flavor and image names. This can save a significant amount of time on clouds with
a large number of images. ``-n`` is an alias for this option.