Merge "Support pagination param limit in volume list in V1"

This commit is contained in:
Jenkins 2015-04-28 20:15:26 +00:00 committed by Gerrit Code Review
commit c82723660d
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.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')

View File

@ -170,6 +170,11 @@ def _extract_metadata(args):
nargs='?',
metavar='<tenant>',
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')
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

View File

@ -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: