Merge "Adds missing flavor information in the server list long command"

This commit is contained in:
Jenkins 2017-03-20 17:57:38 +00:00 committed by Gerrit Code Review
commit 495d013431
2 changed files with 35 additions and 2 deletions

View File

@ -917,6 +917,8 @@ class ListServer(command.Lister):
'Networks',
'Image Name',
'Image ID',
'Flavor Name',
'Flavor ID',
'OS-EXT-AZ:availability_zone',
'OS-EXT-SRV-ATTR:host',
'Metadata',
@ -930,6 +932,8 @@ class ListServer(command.Lister):
'Networks',
'Image Name',
'Image ID',
'Flavor Name',
'Flavor ID',
'Availability Zone',
'Host',
'Properties',
@ -977,8 +981,19 @@ class ListServer(command.Lister):
except Exception:
pass
# Populate image_name and image_id attributes of server objects
# so that we can display "Image Name" and "Image ID" columns.
flavors = {}
# Create a dict that maps flavor_id to flavor object.
# Needed so that we can display the "Flavor Name" column.
# "Flavor Name" is not crucial, so we swallow any exceptions.
try:
flavors_list = compute_client.flavors.list()
for i in flavors_list:
flavors[i.id] = i
except Exception:
pass
# Populate image_name, image_id, flavor_name and flavor_id attributes
# of server objects so that we can display those columns.
for s in data:
if 'id' in s.image:
image = images.get(s.image['id'])
@ -988,6 +1003,14 @@ class ListServer(command.Lister):
else:
s.image_name = ''
s.image_id = ''
if 'id' in s.flavor:
flavor = flavors.get(s.flavor['id'])
if flavor:
s.flavor_name = flavor.name
s.flavor_id = s.flavor['id']
else:
s.flavor_name = ''
s.flavor_id = ''
table = (column_headers,
(utils.get_item_properties(

View File

@ -957,6 +957,8 @@ class TestServerList(TestServer):
'Networks',
'Image Name',
'Image ID',
'Flavor Name',
'Flavor ID',
'Availability Zone',
'Host',
'Properties',
@ -1027,6 +1029,12 @@ class TestServerList(TestServer):
for s in self.servers
]
Flavor = collections.namedtuple('Flavor', 'id name')
self.flavors_mock.list.return_value = [
Flavor(id=s.flavor['id'], name=self.flavor.name)
for s in self.servers
]
for s in self.servers:
self.data.append((
s.id,
@ -1046,6 +1054,8 @@ class TestServerList(TestServer):
server._format_servers_list_networks(s.networks),
self.image.name,
s.image['id'],
self.flavor.name,
s.flavor['id'],
getattr(s, 'OS-EXT-AZ:availability_zone'),
getattr(s, 'OS-EXT-SRV-ATTR:host'),
s.Metadata,