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
This commit is contained in:
Anton Arefiev
2015-04-22 16:08:59 +03:00
parent 8ba6242d64
commit 235622bf8e
3 changed files with 14 additions and 2 deletions

View File

@@ -220,6 +220,10 @@ class ShellTest(utils.TestCase):
self.run_command('availability-zone-list') self.run_command('availability-zone-list')
self.assert_called('GET', '/os-availability-zone') 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): def test_show(self):
self.run_command('show 1234') self.run_command('show 1234')
self.assert_called('GET', '/volumes/1234') self.assert_called('GET', '/volumes/1234')

View File

@@ -170,6 +170,11 @@ def _extract_metadata(args):
nargs='?', nargs='?',
metavar='<tenant>', metavar='<tenant>',
help='Display information from single tenant (Admin only).') help='Display information from single tenant (Admin only).')
@utils.arg(
'--limit',
metavar='<limit>',
default=None,
help='Maximum number of volumes to return. OPTIONAL: Default=None.')
@utils.service_type('volume') @utils.service_type('volume')
def do_list(cs, args): def do_list(cs, args):
"""Lists all volumes.""" """Lists all volumes."""
@@ -182,7 +187,7 @@ def do_list(cs, args):
'status': args.status, 'status': args.status,
'metadata': _extract_metadata(args) if args.metadata else None, '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) _translate_volume_keys(volumes)
# Create a list of servers to which the volume is attached # Create a list of servers to which the volume is attached

View File

@@ -190,7 +190,7 @@ class VolumeManager(base.ManagerWithFind):
""" """
return self._get("/volumes/%s" % volume_id, "volume") 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. Get a list of all volumes.
@@ -205,6 +205,9 @@ class VolumeManager(base.ManagerWithFind):
if val: if val:
qparams[opt] = val qparams[opt] = val
if limit:
qparams['limit'] = limit
# Transform the dict to a sequence of two-element tuples in fixed # Transform the dict to a sequence of two-element tuples in fixed
# order, then the encoded string will be consistent in Python 2&3. # order, then the encoded string will be consistent in Python 2&3.
if qparams: if qparams: