Merge "Properly format 'attached to' column list when listing volumes"
This commit is contained in:
commit
457f4c8998
@ -223,6 +223,25 @@ class ListVolume(lister.Lister):
|
|||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
self.log.debug('take_action(%s)', parsed_args)
|
self.log.debug('take_action(%s)', parsed_args)
|
||||||
|
|
||||||
|
volume_client = self.app.client_manager.volume
|
||||||
|
compute_client = self.app.client_manager.compute
|
||||||
|
|
||||||
|
def _format_attach(attachments):
|
||||||
|
"""Return a formatted string of a volume's attached instances
|
||||||
|
|
||||||
|
:param volume: a volume.attachments field
|
||||||
|
:rtype: a string of formatted instances
|
||||||
|
"""
|
||||||
|
|
||||||
|
msg = ''
|
||||||
|
for attachment in attachments:
|
||||||
|
server = attachment['server_id']
|
||||||
|
if server in server_cache.keys():
|
||||||
|
server = server_cache[server].name
|
||||||
|
device = attachment['device']
|
||||||
|
msg += 'Attached to %s on %s ' % (server, device)
|
||||||
|
return msg
|
||||||
|
|
||||||
if parsed_args.long:
|
if parsed_args.long:
|
||||||
columns = (
|
columns = (
|
||||||
'ID',
|
'ID',
|
||||||
@ -231,7 +250,7 @@ class ListVolume(lister.Lister):
|
|||||||
'Size',
|
'Size',
|
||||||
'Volume Type',
|
'Volume Type',
|
||||||
'Bootable',
|
'Bootable',
|
||||||
'Attached to',
|
'Attachments',
|
||||||
'Metadata',
|
'Metadata',
|
||||||
)
|
)
|
||||||
column_headers = (
|
column_headers = (
|
||||||
@ -241,7 +260,7 @@ class ListVolume(lister.Lister):
|
|||||||
'Size',
|
'Size',
|
||||||
'Type',
|
'Type',
|
||||||
'Bootable',
|
'Bootable',
|
||||||
'Attached',
|
'Attached to',
|
||||||
'Properties',
|
'Properties',
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
@ -250,28 +269,38 @@ class ListVolume(lister.Lister):
|
|||||||
'Display Name',
|
'Display Name',
|
||||||
'Status',
|
'Status',
|
||||||
'Size',
|
'Size',
|
||||||
'Attached to',
|
'Attachments',
|
||||||
)
|
)
|
||||||
column_headers = (
|
column_headers = (
|
||||||
'ID',
|
'ID',
|
||||||
'Display Name',
|
'Display Name',
|
||||||
'Status',
|
'Status',
|
||||||
'Size',
|
'Size',
|
||||||
'Attached',
|
'Attached to',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Cache the server list
|
||||||
|
server_cache = {}
|
||||||
|
try:
|
||||||
|
for s in compute_client.servers.list():
|
||||||
|
server_cache[s.id] = s
|
||||||
|
except Exception:
|
||||||
|
# Just forget it if there's any trouble
|
||||||
|
pass
|
||||||
|
|
||||||
search_opts = {
|
search_opts = {
|
||||||
'all_tenants': parsed_args.all_projects,
|
'all_tenants': parsed_args.all_projects,
|
||||||
'display_name': parsed_args.name,
|
'display_name': parsed_args.name,
|
||||||
'status': parsed_args.status,
|
'status': parsed_args.status,
|
||||||
}
|
}
|
||||||
|
|
||||||
volume_client = self.app.client_manager.volume
|
|
||||||
data = volume_client.volumes.list(search_opts=search_opts)
|
data = volume_client.volumes.list(search_opts=search_opts)
|
||||||
|
|
||||||
return (column_headers,
|
return (column_headers,
|
||||||
(utils.get_item_properties(
|
(utils.get_item_properties(
|
||||||
s, columns,
|
s, columns,
|
||||||
formatters={'Metadata': utils.format_dict},
|
formatters={'Metadata': utils.format_dict,
|
||||||
|
'Attachments': _format_attach},
|
||||||
) for s in data))
|
) for s in data))
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user