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