From 235622bf8eb84f45462a78ff2b976df34d85fac5 Mon Sep 17 00:00:00 2001 From: Anton Arefiev Date: Wed, 22 Apr 2015 16:08:59 +0300 Subject: [PATCH] Support pagination param limit in volume list in V1 Since v1 api supports limit param in volume list, cinderclient should support it too. Change-Id: I60ffe0190a61dee354de5bc60ea3210c666bf6f2 Closes-Bug: #1447162 --- cinderclient/tests/unit/v1/test_shell.py | 4 ++++ cinderclient/v1/shell.py | 7 ++++++- cinderclient/v1/volumes.py | 5 ++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/cinderclient/tests/unit/v1/test_shell.py b/cinderclient/tests/unit/v1/test_shell.py index 72d743503..4eb749daf 100644 --- a/cinderclient/tests/unit/v1/test_shell.py +++ b/cinderclient/tests/unit/v1/test_shell.py @@ -220,6 +220,10 @@ class ShellTest(utils.TestCase): self.run_command('availability-zone-list') self.assert_called('GET', '/os-availability-zone') + def test_list_limit(self): + self.run_command('list --limit=10') + self.assert_called('GET', '/volumes/detail?limit=10') + def test_show(self): self.run_command('show 1234') self.assert_called('GET', '/volumes/1234') diff --git a/cinderclient/v1/shell.py b/cinderclient/v1/shell.py index a64f621c3..63aa19eb2 100644 --- a/cinderclient/v1/shell.py +++ b/cinderclient/v1/shell.py @@ -170,6 +170,11 @@ def _extract_metadata(args): nargs='?', metavar='', help='Display information from single tenant (Admin only).') +@utils.arg( + '--limit', + metavar='', + default=None, + help='Maximum number of volumes to return. OPTIONAL: Default=None.') @utils.service_type('volume') def do_list(cs, args): """Lists all volumes.""" @@ -182,7 +187,7 @@ def do_list(cs, args): 'status': args.status, 'metadata': _extract_metadata(args) if args.metadata else None, } - volumes = cs.volumes.list(search_opts=search_opts) + volumes = cs.volumes.list(search_opts=search_opts, limit=args.limit) _translate_volume_keys(volumes) # Create a list of servers to which the volume is attached diff --git a/cinderclient/v1/volumes.py b/cinderclient/v1/volumes.py index e1ff72c7a..73600d646 100644 --- a/cinderclient/v1/volumes.py +++ b/cinderclient/v1/volumes.py @@ -190,7 +190,7 @@ class VolumeManager(base.ManagerWithFind): """ return self._get("/volumes/%s" % volume_id, "volume") - def list(self, detailed=True, search_opts=None): + def list(self, detailed=True, search_opts=None, limit=None): """ Get a list of all volumes. @@ -205,6 +205,9 @@ class VolumeManager(base.ManagerWithFind): if val: qparams[opt] = val + if limit: + qparams['limit'] = limit + # Transform the dict to a sequence of two-element tuples in fixed # order, then the encoded string will be consistent in Python 2&3. if qparams: