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: