File volume-list-all_tenants.patch of Package python-novaclient

From 8ff4e9cdc4d3daa7cd37ffc824cdf73359db506a Mon Sep 17 00:00:00 2001
From: Vincent Untz <vuntz@suse.com>
Date: Wed, 26 Sep 2012 14:54:57 +0200
Subject: [PATCH] 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: I7965a6bb935c875179fc23a105740ca597a3dae7
---
 novaclient/v1_1/shell.py   |   14 ++++++++++++--
 novaclient/v1_1/volumes.py |   14 +++++++++++---
 2 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/novaclient/v1_1/shell.py b/novaclient/v1_1/shell.py
index d7f047a..50a0d75 100644
--- a/novaclient/v1_1/shell.py
+++ b/novaclient/v1_1/shell.py
@@ -917,10 +917,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_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
diff --git a/novaclient/v1_1/volumes.py b/novaclient/v1_1/volumes.py
index adfa57c..caa7de7 100644
--- a/novaclient/v1_1/volumes.py
+++ b/novaclient/v1_1/volumes.py
@@ -17,6 +17,8 @@
 Volume interface (1.1 extension).
 """
 
+import urllib
+
 from novaclient import base
 
 
@@ -71,16 +73,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):
         """
-- 
1.7.10.4

openSUSE Build Service is sponsored by