Adds filter support to images.list().

This existed in glance.client, and should exist in the new
client as well! :-)

Change-Id: Iea8c55fcb0f0d30d6dc138072354c3f20d1288cf
This commit is contained in:
Gabriel Hurley 2012-04-12 16:35:36 -07:00 committed by Brian Waldon
parent 1f106a3bd9
commit 3344eac545
3 changed files with 9 additions and 1 deletions

View File

@ -2,3 +2,4 @@ Brian Waldon <bcwaldon@gmail.com>
Jay Pipes <jaypipes@gmail.com>
Monty Taylor <mordred@inaugust.com>
Dean Troyer <dtroyer@gmail.com>
Gabriel Hurley <gabriel@strikeawe.com>

View File

@ -71,7 +71,7 @@ class ImageManager(base.Manager):
meta = self._image_meta_from_headers(resp)
return Image(self, meta)
def list(self, limit=None, marker=None):
def list(self, limit=None, marker=None, filters=None):
"""Get a list of images.
:param limit: maximum number of images to return. Used for pagination.
@ -83,6 +83,8 @@ class ImageManager(base.Manager):
params['limit'] = int(limit)
if marker:
params['marker'] = marker
if filters:
params.update(filters)
query = '?%s' % urllib.urlencode(params) if params else ''
return self._list('/v1/images/detail%s' % query, "images")

View File

@ -32,6 +32,11 @@ class ImageManagerTest(unittest.TestCase):
expect = [('GET', '/v1/images/detail?marker=20', {}, None)]
self.assertEqual(self.api.calls, expect)
def test_list_with_filter(self):
self.mgr.list(filters={'name': "foo"})
expect = [('GET', '/v1/images/detail?name=foo', {}, None)]
self.assertEqual(self.api.calls, expect)
def test_get(self):
image = self.mgr.get('1')
expect = [('HEAD', '/v1/images/1', {}, None)]