Added limit to image-list in a preparatory step toward addressing bug 1001345.
Currently novaclient doesn't use the limit or marker params. As a step to addressing bug 1001345 which requires pagination, this patch introduces the use of limit as an option passed to the image-list function. Change-Id: Ia32f9e923b4eb9bcdde3b7bc1722c59d7791d104
This commit is contained in:
parent
67b3db2bbc
commit
8811ced007
@ -2,6 +2,7 @@
|
|||||||
"""
|
"""
|
||||||
Image interface.
|
Image interface.
|
||||||
"""
|
"""
|
||||||
|
import urllib
|
||||||
|
|
||||||
from novaclient import base
|
from novaclient import base
|
||||||
|
|
||||||
@ -37,16 +38,21 @@ class ImageManager(base.ManagerWithFind):
|
|||||||
"""
|
"""
|
||||||
return self._get("/images/%s" % base.getid(image), "image")
|
return self._get("/images/%s" % base.getid(image), "image")
|
||||||
|
|
||||||
def list(self, detailed=True):
|
def list(self, detailed=True, limit=None):
|
||||||
"""
|
"""
|
||||||
Get a list of all images.
|
Get a list of all images.
|
||||||
|
|
||||||
:rtype: list of :class:`Image`
|
:rtype: list of :class:`Image`
|
||||||
|
:param limit: maximum number of images to return.
|
||||||
"""
|
"""
|
||||||
if detailed is True:
|
params = {}
|
||||||
return self._list("/images/detail", "images")
|
detail = ''
|
||||||
else:
|
if detailed:
|
||||||
return self._list("/images", "images")
|
detail = '/detail'
|
||||||
|
if limit:
|
||||||
|
params['limit'] = int(limit)
|
||||||
|
query = '?%s' % urllib.urlencode(params) if params else ''
|
||||||
|
return self._list('/images%s%s' % (detail, query), 'images')
|
||||||
|
|
||||||
def delete(self, image):
|
def delete(self, image):
|
||||||
"""
|
"""
|
||||||
|
@ -712,9 +712,14 @@ def do_network_create(cs, args):
|
|||||||
cs.networks.create(**kwargs)
|
cs.networks.create(**kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
@utils.arg('--limit',
|
||||||
|
dest="limit",
|
||||||
|
metavar="<limit>",
|
||||||
|
help='number of images to return per request')
|
||||||
def do_image_list(cs, _args):
|
def do_image_list(cs, _args):
|
||||||
"""Print a list of available images to boot from."""
|
"""Print a list of available images to boot from."""
|
||||||
image_list = cs.images.list()
|
limit = _args.limit
|
||||||
|
image_list = cs.images.list(limit=limit)
|
||||||
|
|
||||||
def parse_server_name(image):
|
def parse_server_name(image):
|
||||||
try:
|
try:
|
||||||
|
@ -18,6 +18,10 @@ class ImagesTest(utils.TestCase):
|
|||||||
cs.assert_called('GET', '/images')
|
cs.assert_called('GET', '/images')
|
||||||
[self.assertTrue(isinstance(i, images.Image)) for i in il]
|
[self.assertTrue(isinstance(i, images.Image)) for i in il]
|
||||||
|
|
||||||
|
def test_list_images_with_limit(self):
|
||||||
|
il = cs.images.list(limit=4)
|
||||||
|
cs.assert_called('GET', '/images/detail?limit=4')
|
||||||
|
|
||||||
def test_get_image_details(self):
|
def test_get_image_details(self):
|
||||||
i = cs.images.get(1)
|
i = cs.images.get(1)
|
||||||
cs.assert_called('GET', '/images/1')
|
cs.assert_called('GET', '/images/1')
|
||||||
|
Loading…
Reference in New Issue
Block a user