diff options
| author | jiahui.qiang <jiahui.qiang@easystack.cn> | 2016-11-22 17:27:34 +0800 |
|---|---|---|
| committer | jiahui.qiang <jiahui.qiang@easystack.cn> | 2016-11-26 23:13:50 +0800 |
| commit | 6ca4dc3533d009866f82515c34cb3881f993c750 (patch) | |
| tree | 385f7e38a0523da415e3bbccfb86e0290fbc6fe7 /openstackclient/volume | |
| parent | e05c8d7bb04f477797e46e5728e93a35c104809a (diff) | |
| download | python-openstackclient-6ca4dc3533d009866f82515c34cb3881f993c750.tar.gz | |
Add options to "volume snapshot list" command
Add "--name", "--status" and "--volume" options
to "volume snapshot list" command for filtering results.
Change-Id: I72db1abce7701f31598deec34801a4d1f5713870
Closes-Bug:#1645252
Diffstat (limited to 'openstackclient/volume')
| -rw-r--r-- | openstackclient/volume/v1/volume_snapshot.py | 34 | ||||
| -rw-r--r-- | openstackclient/volume/v2/volume_snapshot.py | 34 |
2 files changed, 64 insertions, 4 deletions
diff --git a/openstackclient/volume/v1/volume_snapshot.py b/openstackclient/volume/v1/volume_snapshot.py index c2ecf75b..77c93ad4 100644 --- a/openstackclient/volume/v1/volume_snapshot.py +++ b/openstackclient/volume/v1/volume_snapshot.py @@ -135,9 +135,31 @@ class ListVolumeSnapshot(command.Lister): default=False, help=_('List additional fields in output'), ) + parser.add_argument( + '--name', + metavar='<name>', + default=None, + help=_('Filters results by a name.') + ) + parser.add_argument( + '--status', + metavar='<status>', + choices=['available', 'error', 'creating', 'deleting', + 'error-deleting'], + help=_("Filters results by a status. " + "('available', 'error', 'creating', 'deleting'" + " or 'error-deleting')") + ) + parser.add_argument( + '--volume', + metavar='<volume>', + default=None, + help=_('Filters results by a volume (name or ID).') + ) return parser def take_action(self, parsed_args): + volume_client = self.app.client_manager.volume def _format_volume_id(volume_id): """Return a volume name if available @@ -169,17 +191,25 @@ class ListVolumeSnapshot(command.Lister): # Cache the volume list volume_cache = {} try: - for s in self.app.client_manager.volume.volumes.list(): + for s in volume_client.volumes.list(): volume_cache[s.id] = s except Exception: # Just forget it if there's any trouble pass + volume_id = None + if parsed_args.volume: + volume_id = utils.find_resource( + volume_client.volumes, parsed_args.volume).id + search_opts = { 'all_tenants': parsed_args.all_projects, + 'display_name': parsed_args.name, + 'status': parsed_args.status, + 'volume_id': volume_id, } - data = self.app.client_manager.volume.volume_snapshots.list( + data = volume_client.volume_snapshots.list( search_opts=search_opts) return (column_headers, (utils.get_item_properties( diff --git a/openstackclient/volume/v2/volume_snapshot.py b/openstackclient/volume/v2/volume_snapshot.py index 43f30326..86af6d8c 100644 --- a/openstackclient/volume/v2/volume_snapshot.py +++ b/openstackclient/volume/v2/volume_snapshot.py @@ -151,9 +151,31 @@ class ListVolumeSnapshot(command.Lister): metavar='<limit>', help=_('Maximum number of snapshots to display'), ) + parser.add_argument( + '--name', + metavar='<name>', + default=None, + help=_('Filters results by a name.') + ) + parser.add_argument( + '--status', + metavar='<status>', + choices=['available', 'error', 'creating', 'deleting', + 'error-deleting'], + help=_("Filters results by a status. " + "('available', 'error', 'creating', 'deleting'" + " or 'error-deleting')") + ) + parser.add_argument( + '--volume', + metavar='<volume>', + default=None, + help=_('Filters results by a volume (name or ID).') + ) return parser def take_action(self, parsed_args): + volume_client = self.app.client_manager.volume def _format_volume_id(volume_id): """Return a volume name if available @@ -180,17 +202,25 @@ class ListVolumeSnapshot(command.Lister): # Cache the volume list volume_cache = {} try: - for s in self.app.client_manager.volume.volumes.list(): + for s in volume_client.volumes.list(): volume_cache[s.id] = s except Exception: # Just forget it if there's any trouble pass + volume_id = None + if parsed_args.volume: + volume_id = utils.find_resource( + volume_client.volumes, parsed_args.volume).id + search_opts = { 'all_tenants': parsed_args.all_projects, + 'name': parsed_args.name, + 'status': parsed_args.status, + 'volume_id': volume_id, } - data = self.app.client_manager.volume.volume_snapshots.list( + data = volume_client.volume_snapshots.list( search_opts=search_opts, marker=parsed_args.marker, limit=parsed_args.limit, |
