From f29d1c8349069a39776cf8ec5cc27ecc7e8d150a Mon Sep 17 00:00:00 2001 From: jakedahn Date: Sun, 5 Aug 2012 17:32:00 -0700 Subject: [PATCH] Add all_tenants flag to snapshots and volumes. Adds search_opts functionality for the following branches: * https://review.openstack.org/#/c/10750/ * https://review.openstack.org/#/c/10855/ Change-Id: I8eb69574d3a0510bb6ac8b14b3e2a50a33542f11 --- cinderclient/v1/shell.py | 26 ++++++++++++++++++++++++-- cinderclient/v1/volume_snapshots.py | 24 +++++++++++++++++++----- cinderclient/v1/volumes.py | 24 +++++++++++++++++++----- 3 files changed, 62 insertions(+), 12 deletions(-) diff --git a/cinderclient/v1/shell.py b/cinderclient/v1/shell.py index 385d4e7e2..6eb159ecd 100644 --- a/cinderclient/v1/shell.py +++ b/cinderclient/v1/shell.py @@ -15,6 +15,7 @@ # License for the specific language governing permissions and limitations # under the License. +import os import sys import time @@ -89,10 +90,20 @@ def _translate_volume_snapshot_keys(collection): setattr(item, to_key, item._info[from_key]) +@utils.arg('--all_tenants', + dest='all_tenants', + metavar='<0|1>', + nargs='?', + type=int, + const=1, + default=0, + help='Display information from all tenants (Admin only).') @utils.service_type('volume') def do_list(cs, args): """List all the volumes.""" - volumes = cs.volumes.list() + all_tenants = int(os.environ.get("ALL_TENANTS", args.all_tenants)) + search_opts = {'all_tenants': all_tenants} + volumes = cs.volumes.list(search_opts=search_opts) _translate_volume_keys(volumes) # Create a list of servers to which the volume is attached @@ -148,10 +159,21 @@ def do_delete(cs, args): volume.delete() +@utils.arg('--all_tenants', + dest='all_tenants', + metavar='<0|1>', + nargs='?', + type=int, + const=1, + default=0, + help='Display information from all tenants (Admin only).') @utils.service_type('volume') def do_snapshot_list(cs, args): """List all the snapshots.""" - snapshots = cs.volume_snapshots.list() + all_tenants = int(os.environ.get("ALL_TENANTS", args.all_tenants)) + search_opts = {'all_tenants': all_tenants} + + snapshots = cs.volume_snapshots.list(search_opts=search_opts) _translate_volume_snapshot_keys(snapshots) utils.print_list(snapshots, ['ID', 'Volume ID', 'Status', 'Display Name', 'Size']) diff --git a/cinderclient/v1/volume_snapshots.py b/cinderclient/v1/volume_snapshots.py index c943607b3..f283fdc9e 100644 --- a/cinderclient/v1/volume_snapshots.py +++ b/cinderclient/v1/volume_snapshots.py @@ -76,16 +76,30 @@ class SnapshotManager(base.ManagerWithFind): """ return self._get("/snapshots/%s" % snapshot_id, "snapshot") - def list(self, detailed=True): + def list(self, detailed=True, search_opts=None): """ Get a list of all snapshots. :rtype: list of :class:`Snapshot` """ - if detailed is True: - return self._list("/snapshots/detail", "snapshots") - else: - return self._list("/snapshots", "snapshots") + + if search_opts is None: + search_opts = {} + + qparams = {} + + for opt, val in search_opts.iteritems(): + if val: + qparams[opt] = val + + query_string = "?%s" % urllib.urlencode(qparams) if qparams else "" + + detail = "" + if detailed: + detail = "/detail" + + return self._list("/snapshots%s%s" % (detail, query_string), + "snapshots") def delete(self, snapshot): """ diff --git a/cinderclient/v1/volumes.py b/cinderclient/v1/volumes.py index 984952c6d..2ef19b805 100644 --- a/cinderclient/v1/volumes.py +++ b/cinderclient/v1/volumes.py @@ -17,6 +17,7 @@ Volume interface (1.1 extension). """ +import urllib from cinderclient import base @@ -136,16 +137,29 @@ class VolumeManager(base.ManagerWithFind): """ return self._get("/volumes/%s" % volume_id, "volume") - def list(self, detailed=True): + def list(self, detailed=True, search_opts=None): """ Get a list of all volumes. :rtype: list of :class:`Volume` """ - if detailed is True: - return self._list("/volumes/detail", "volumes") - else: - return self._list("/volumes", "volumes") + if search_opts is None: + search_opts = {} + + qparams = {} + + for opt, val in search_opts.iteritems(): + if val: + qparams[opt] = val + + query_string = "?%s" % urllib.urlencode(qparams) if qparams else "" + + detail = "" + if detailed: + detail = "/detail" + + return self._list("/volumes%s%s" % (detail, query_string), + "volumes") def delete(self, volume): """