diff --git a/doc/source/cli/command-objects/server.rst b/doc/source/cli/command-objects/server.rst index dee2721943..1118282204 100644 --- a/doc/source/cli/command-objects/server.rst +++ b/doc/source/cli/command-objects/server.rst @@ -330,7 +330,7 @@ List servers [--all-projects] [--project [--project-domain ]] [--long] - [-n | --no-name-lookup] + [--no-name-lookup | -n] [--marker ] [--limit ] [--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 The last server of the previous page. Display list of servers diff --git a/openstackclient/compute/v2/server.py b/openstackclient/compute/v2/server.py index cb520d620e..a991ed4531 100644 --- a/openstackclient/compute/v2/server.py +++ b/openstackclient/compute/v2/server.py @@ -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 diff --git a/openstackclient/tests/unit/compute/v2/test_server.py b/openstackclient/tests/unit/compute/v2/test_server.py index 3e71ce0771..b02b149119 100644 --- a/openstackclient/tests/unit/compute/v2/test_server.py +++ b/openstackclient/tests/unit/compute/v2/test_server.py @@ -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): diff --git a/releasenotes/notes/skip-name-lookups-9f499927173c1eee.yaml b/releasenotes/notes/skip-name-lookups-9f499927173c1eee.yaml new file mode 100644 index 0000000000..69ca0f99f5 --- /dev/null +++ b/releasenotes/notes/skip-name-lookups-9f499927173c1eee.yaml @@ -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.