Skip to content

Commit 55b8540

Browse files
author
Steve Martinelli
committed
Fixup backup list output
Name and Description were not appearing at all, and we didn't have a --long alternative, which had a bunch of useful information. Closes-Bug: #1408585 Change-Id: I7ca42a8d23ad60f6b9cc862799cb08a3e491b6e8
1 parent 32c1563 commit 55b8540

1 file changed

Lines changed: 45 additions & 9 deletions

File tree

‎openstackclient/volume/v1/backup.py‎

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
"""Volume v1 Backup action implementations"""
1717

18+
import copy
1819
import logging
1920
import six
2021

@@ -102,20 +103,55 @@ class ListBackup(lister.Lister):
102103

103104
log = logging.getLogger(__name__ + '.ListBackup')
104105

106+
def get_parser(self, prog_name):
107+
parser = super(ListBackup, self).get_parser(prog_name)
108+
parser.add_argument(
109+
'--long',
110+
action='store_true',
111+
default=False,
112+
help='List additional fields in output',
113+
)
114+
return parser
115+
105116
def take_action(self, parsed_args):
106117
self.log.debug('take_action(%s)', parsed_args)
107-
columns = (
108-
'ID',
109-
'Display Name',
110-
'Display Description',
111-
'Status',
112-
'Size'
113-
)
118+
119+
def _format_volume_id(volume_id):
120+
"""Return a volume name if available
121+
122+
:param volume_id: a volume ID
123+
:rtype: either the volume ID or name
124+
"""
125+
126+
volume = volume_id
127+
if volume_id in volume_cache.keys():
128+
volume = volume_cache[volume_id].display_name
129+
return volume
130+
131+
if parsed_args.long:
132+
columns = ['ID', 'Name', 'Description', 'Status', 'Size',
133+
'Availability Zone', 'Volume ID', 'Container']
134+
column_headers = copy.deepcopy(columns)
135+
column_headers[6] = 'Volume'
136+
else:
137+
columns = ['ID', 'Name', 'Description', 'Status', 'Size']
138+
column_headers = columns
139+
140+
# Cache the volume list
141+
volume_cache = {}
142+
try:
143+
for s in self.app.client_manager.volume.volumes.list():
144+
volume_cache[s.id] = s
145+
except Exception:
146+
# Just forget it if there's any trouble
147+
pass
148+
114149
data = self.app.client_manager.volume.backups.list()
115-
return (columns,
150+
151+
return (column_headers,
116152
(utils.get_item_properties(
117153
s, columns,
118-
formatters={},
154+
formatters={'Volume ID': _format_volume_id},
119155
) for s in data))
120156

121157

0 commit comments

Comments
 (0)