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
This commit is contained in:
jakedahn
2012-08-05 17:32:00 -07:00
parent 778d2d9022
commit f29d1c8349
3 changed files with 62 additions and 12 deletions

View File

@@ -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'])

View File

@@ -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):
"""

View File

@@ -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):
"""