Add --all-tenants option to volume-list

The list and secgroup-list commands have this option, and
nova-volume/cinder respect this search option too nowadays.

Change-Id: Ie95432727dec9702e09a0ce314bf418f6a36b799
This commit is contained in:
Vincent Untz 2012-09-26 14:54:57 +02:00
parent cdebf729b0
commit c01fae7370
2 changed files with 28 additions and 5 deletions

View File

@ -1080,10 +1080,25 @@ 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.arg('--all_tenants',
nargs='?',
type=int,
const=1,
help=argparse.SUPPRESS)
@utils.service_type('volume')
def do_volume_list(cs, _args):
def do_volume_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

View File

@ -17,6 +17,8 @@
Volume interface (1.1 extension).
"""
import urllib
from novaclient import base
@ -76,16 +78,22 @@ 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`
"""
search_opts = search_opts or {}
qparams = dict((k, v) for (k, v) in search_opts.iteritems() if v)
query_string = '?%s' % urllib.urlencode(qparams) if qparams else ''
if detailed is True:
return self._list("/volumes/detail", "volumes")
return self._list("/volumes/detail%s" % query_string, "volumes")
else:
return self._list("/volumes", "volumes")
return self._list("/volumes%s" % query_string, "volumes")
def delete(self, volume):
"""