Convert v2 images list method to generator

We will want this to be a generator as soon as we implement
pagination. Let's establish the interface now.

Related to bp glance-client-v2

Change-Id: Ib98e912a7af0bb570b4fd738733edd9b837d1a07
This commit is contained in:
Brian Waldon
2012-07-14 01:16:31 +00:00
parent c398af18b0
commit e5f038b62a
2 changed files with 7 additions and 4 deletions
+5 -3
View File
@@ -20,14 +20,16 @@ class Controller(object):
self.model = model
def list(self):
"""Retrieve a listing of Image objects
:returns generator over list of Images
"""
resp, body = self.http_client.json_request('GET', '/v2/images')
images = []
for image in body['images']:
#NOTE(bcwaldon): remove 'self' for now until we have an elegant
# way to pass it into the model constructor without conflict
image.pop('self', None)
images.append(self.model(**image))
return images
yield self.model(**image)
def get(self, image_id):
url = '/v2/images/%s' % image_id