Skip to content

Commit

Permalink
Added limit to image-list in a preparatory step toward addressing bug…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
anteaya committed Feb 18, 2013
1 parent 67b3db2 commit 8811ced
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
16 changes: 11 additions & 5 deletions novaclient/v1_1/images.py
Expand Up @@ -2,6 +2,7 @@
"""
Image interface.
"""
import urllib

from novaclient import base

Expand Down Expand Up @@ -37,16 +38,21 @@ def get(self, 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.
:rtype: list of :class:`Image`
:param limit: maximum number of images to return.
"""
if detailed is True:
return self._list("/images/detail", "images")
else:
return self._list("/images", "images")
params = {}
detail = ''
if detailed:
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):
"""
Expand Down
7 changes: 6 additions & 1 deletion novaclient/v1_1/shell.py
Expand Up @@ -712,9 +712,14 @@ def do_network_create(cs, args):
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):
"""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):
try:
Expand Down
4 changes: 4 additions & 0 deletions tests/v1_1/test_images.py
Expand Up @@ -18,6 +18,10 @@ def test_list_images_undetailed(self):
cs.assert_called('GET', '/images')
[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):
i = cs.images.get(1)
cs.assert_called('GET', '/images/1')
Expand Down

0 comments on commit 8811ced

Please sign in to comment.