diff --git a/glanceclient/v2/images.py b/glanceclient/v2/images.py index e5de052..0da8ceb 100644 --- a/glanceclient/v2/images.py +++ b/glanceclient/v2/images.py @@ -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 diff --git a/tests/v2/test_images.py b/tests/v2/test_images.py index 471c9ee..298d5c1 100644 --- a/tests/v2/test_images.py +++ b/tests/v2/test_images.py @@ -62,7 +62,8 @@ class TestController(unittest.TestCase): self.controller = images.Controller(self.api, FakeModel) def test_list_images(self): - images = self.controller.list() + #NOTE(bcwaldon): cast to list since the controller returns a generator + images = list(self.controller.list()) self.assertEqual(images[0].id, '3a4560a1-e585-443e-9b39-553b46ec92d1') self.assertEqual(images[0].name, 'image-1') self.assertEqual(images[1].id, '6f99bf80-2ee6-47cf-acfe-1f1fabb7e810')