Merge ""server list": "Image Name", "Image ID" columns"
This commit is contained in:
commit
719c5d79ce
@ -833,6 +833,8 @@ class ListServer(command.Lister):
|
||||
'OS-EXT-STS:task_state',
|
||||
'OS-EXT-STS:power_state',
|
||||
'Networks',
|
||||
'Image Name',
|
||||
'Image ID',
|
||||
'OS-EXT-AZ:availability_zone',
|
||||
'OS-EXT-SRV-ATTR:host',
|
||||
'Metadata',
|
||||
@ -844,6 +846,8 @@ class ListServer(command.Lister):
|
||||
'Task State',
|
||||
'Power State',
|
||||
'Networks',
|
||||
'Image Name',
|
||||
'Image ID',
|
||||
'Availability Zone',
|
||||
'Host',
|
||||
'Properties',
|
||||
@ -860,12 +864,14 @@ class ListServer(command.Lister):
|
||||
'Name',
|
||||
'Status',
|
||||
'Networks',
|
||||
'Image Name',
|
||||
)
|
||||
column_headers = (
|
||||
'ID',
|
||||
'Name',
|
||||
'Status',
|
||||
'Networks',
|
||||
'Image Name',
|
||||
)
|
||||
mixed_case_fields = []
|
||||
|
||||
@ -877,7 +883,31 @@ class ListServer(command.Lister):
|
||||
data = compute_client.servers.list(search_opts=search_opts,
|
||||
marker=marker_id,
|
||||
limit=parsed_args.limit)
|
||||
return (column_headers,
|
||||
|
||||
images = {}
|
||||
# Create a dict that maps image_id to image object.
|
||||
# Needed so that we can display the "Image Name" column.
|
||||
# "Image Name" is not crucial, so we swallow any exceptions.
|
||||
try:
|
||||
images_list = self.app.client_manager.image.images.list()
|
||||
for i in images_list:
|
||||
images[i.id] = i
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Populate image_name and image_id attributes of server objects
|
||||
# so that we can display "Image Name" and "Image ID" columns.
|
||||
for s in data:
|
||||
if 'id' in s.image:
|
||||
image = images.get(s.image['id'])
|
||||
if image:
|
||||
s.image_name = image.name
|
||||
s.image_id = s.image['id']
|
||||
else:
|
||||
s.image_name = ''
|
||||
s.image_id = ''
|
||||
|
||||
table = (column_headers,
|
||||
(utils.get_item_properties(
|
||||
s, columns,
|
||||
mixed_case_fields=mixed_case_fields,
|
||||
@ -888,6 +918,7 @@ class ListServer(command.Lister):
|
||||
'Metadata': utils.format_dict,
|
||||
},
|
||||
) for s in data))
|
||||
return table
|
||||
|
||||
|
||||
class LockServer(command.Command):
|
||||
|
@ -12,6 +12,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
import collections
|
||||
import getpass
|
||||
import mock
|
||||
from mock import call
|
||||
@ -598,6 +599,7 @@ class TestServerList(TestServer):
|
||||
'Name',
|
||||
'Status',
|
||||
'Networks',
|
||||
'Image Name',
|
||||
)
|
||||
columns_long = (
|
||||
'ID',
|
||||
@ -606,6 +608,8 @@ class TestServerList(TestServer):
|
||||
'Task State',
|
||||
'Power State',
|
||||
'Networks',
|
||||
'Image Name',
|
||||
'Image ID',
|
||||
'Availability Zone',
|
||||
'Host',
|
||||
'Properties',
|
||||
@ -668,12 +672,19 @@ class TestServerList(TestServer):
|
||||
self.data = []
|
||||
self.data_long = []
|
||||
|
||||
Image = collections.namedtuple('Image', 'id name')
|
||||
self.images_mock.list.return_value = [
|
||||
Image(id=s.image['id'], name=self.image.name)
|
||||
for s in self.servers
|
||||
]
|
||||
|
||||
for s in self.servers:
|
||||
self.data.append((
|
||||
s.id,
|
||||
s.name,
|
||||
s.status,
|
||||
server._format_servers_list_networks(s.networks),
|
||||
self.image.name,
|
||||
))
|
||||
self.data_long.append((
|
||||
s.id,
|
||||
@ -684,6 +695,8 @@ class TestServerList(TestServer):
|
||||
getattr(s, 'OS-EXT-STS:power_state')
|
||||
),
|
||||
server._format_servers_list_networks(s.networks),
|
||||
self.image.name,
|
||||
s.image['id'],
|
||||
getattr(s, 'OS-EXT-AZ:availability_zone'),
|
||||
getattr(s, 'OS-EXT-SRV-ATTR:host'),
|
||||
s.Metadata,
|
||||
@ -731,7 +744,7 @@ class TestServerList(TestServer):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.cimages_mock.get.assert_called_with(self.image.id)
|
||||
self.cimages_mock.get.assert_any_call(self.image.id)
|
||||
|
||||
self.search_opts['image'] = self.image.id
|
||||
self.servers_mock.list.assert_called_with(**self.kwargs)
|
||||
|
Loading…
Reference in New Issue
Block a user