summaryrefslogtreecommitdiff
path: root/openstackclient
diff options
context:
space:
mode:
authorSteve Martinelli <stevemar@ca.ibm.com>2015-01-05 20:02:53 -0500
committerSteve Martinelli <stevemar@ca.ibm.com>2015-01-08 21:03:47 +0000
commit55b85403744840e8327a6184ab3464d602e93e3f (patch)
treef0fefb22f3e3b64a2ee2eae305bf2bd7c686b390 /openstackclient
parent32c15633f4cf23cf1469ce20e6e478214eef85ff (diff)
downloadpython-openstackclient-55b85403744840e8327a6184ab3464d602e93e3f.tar.gz
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
Diffstat (limited to 'openstackclient')
-rw-r--r--openstackclient/volume/v1/backup.py54
1 files changed, 45 insertions, 9 deletions
diff --git a/openstackclient/volume/v1/backup.py b/openstackclient/volume/v1/backup.py
index 8c16ba25..eab388a5 100644
--- a/openstackclient/volume/v1/backup.py
+++ b/openstackclient/volume/v1/backup.py
@@ -15,6 +15,7 @@
"""Volume v1 Backup action implementations"""
+import copy
import logging
import six
@@ -102,20 +103,55 @@ class ListBackup(lister.Lister):
log = logging.getLogger(__name__ + '.ListBackup')
+ def get_parser(self, prog_name):
+ parser = super(ListBackup, self).get_parser(prog_name)
+ parser.add_argument(
+ '--long',
+ action='store_true',
+ default=False,
+ help='List additional fields in output',
+ )
+ return parser
+
def take_action(self, parsed_args):
self.log.debug('take_action(%s)', parsed_args)
- columns = (
- 'ID',
- 'Display Name',
- 'Display Description',
- 'Status',
- 'Size'
- )
+
+ def _format_volume_id(volume_id):
+ """Return a volume name if available
+
+ :param volume_id: a volume ID
+ :rtype: either the volume ID or name
+ """
+
+ volume = volume_id
+ if volume_id in volume_cache.keys():
+ volume = volume_cache[volume_id].display_name
+ return volume
+
+ if parsed_args.long:
+ columns = ['ID', 'Name', 'Description', 'Status', 'Size',
+ 'Availability Zone', 'Volume ID', 'Container']
+ column_headers = copy.deepcopy(columns)
+ column_headers[6] = 'Volume'
+ else:
+ columns = ['ID', 'Name', 'Description', 'Status', 'Size']
+ column_headers = columns
+
+ # Cache the volume list
+ volume_cache = {}
+ try:
+ for s in self.app.client_manager.volume.volumes.list():
+ volume_cache[s.id] = s
+ except Exception:
+ # Just forget it if there's any trouble
+ pass
+
data = self.app.client_manager.volume.backups.list()
- return (columns,
+
+ return (column_headers,
(utils.get_item_properties(
s, columns,
- formatters={},
+ formatters={'Volume ID': _format_volume_id},
) for s in data))