From 17149f688d22e4f4938674f7179a03caeafbfc93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89douard=20Thuleau?= Date: Wed, 24 Oct 2012 18:08:49 +0200 Subject: [PATCH] fetch_images() method no more needed The Nova Glance wrapper returns all images metadata if the parameter 'limit' is not define. It doesn't split the image metadata list. So the sub method fetch_image is no more needed. We can delete it. I added a check in Nova Glance wrapper to be sure the parameter 'marker' or another one aren't set to 'None' (like in bug #1065053). Fixes LP bug #1070904 Change-Id: I24ecc4adf158401f60b508aa3a20bd4c91bfa92b --- .mailmap | 4 ++-- nova/compute/manager.py | 30 +++++++----------------------- nova/image/glance.py | 2 +- 3 files changed, 10 insertions(+), 26 deletions(-) diff --git a/.mailmap b/.mailmap index 832af7d8badf..ac6f75f88fa6 100644 --- a/.mailmap +++ b/.mailmap @@ -21,7 +21,7 @@ - + @@ -85,6 +85,7 @@ Dan Wendlandt danwent Dan Wendlandt danwent Dan Wendlandt danwent@gmail.com <> Dan Wendlandt danwent@gmail.com +Édouard Thuleau Thuleau Édouard Jake Dahn jakedahn Jason Koelker Jason Kölker Jay Pipes jaypipes@gmail.com <> @@ -116,4 +117,3 @@ Vishvananda Ishaya Vishvananda Ishaya Vivek YS Vivek YS vivek.ys@gmail.com <> Zhongyue Luo -Édouard Thuleau Thuleau Édouard diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 300b2dfeb32a..4ff144cab0aa 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -1242,43 +1242,27 @@ class ComputeManager(manager.SchedulerDependentManager): :param rotation: int representing how many backups to keep around; None if rotation shouldn't be used (as in the case of snapshots) """ - # NOTE(jk0): Eventually extract this out to the ImageService? - def fetch_images(): - images = [] - marker = None - while True: - if marker is not None: - batch = image_service.detail(context, filters=filters, - marker=marker, sort_key='created_at', - sort_dir='desc') - else: - batch = image_service.detail(context, filters=filters, - sort_key='created_at', sort_dir='desc') - if not batch: - break - images += batch - marker = batch[-1]['id'] - return images - image_service = glance.get_default_image_service() filters = {'property-image_type': 'backup', 'property-backup_type': backup_type, 'property-instance_uuid': instance['uuid']} - images = fetch_images() + images = image_service.detail(context, filters=filters, + sort_key='created_at', sort_dir='desc') num_images = len(images) - LOG.debug(_("Found %(num_images)d images (rotation: %(rotation)d)") - % locals(), instance=instance) + LOG.debug(_("Found %(num_images)d images (rotation: %(rotation)d)"), + locals(), instance=instance) + if num_images > rotation: # NOTE(sirp): this deletes all backups that exceed the rotation # limit excess = len(images) - rotation - LOG.debug(_("Rotating out %d backups") % excess, + LOG.debug(_("Rotating out %d backups"), excess, instance=instance) for i in xrange(excess): image = images.pop() image_id = image['id'] - LOG.debug(_("Deleting image %s") % image_id, + LOG.debug(_("Deleting image %s"), image_id, instance=instance) image_service.delete(context, image_id) diff --git a/nova/image/glance.py b/nova/image/glance.py index 9282a1545e2a..c55ec51187ae 100644 --- a/nova/image/glance.py +++ b/nova/image/glance.py @@ -177,7 +177,7 @@ class GlanceImageService(object): accepted_params = ('filters', 'marker', 'limit', 'sort_key', 'sort_dir') for param in accepted_params: - if param in params: + if params.get(param): _params[param] = params.get(param) # ensure filters is a dict