Skip to content

Commit

Permalink
fetch_images() method no more needed
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Édouard Thuleau committed Oct 26, 2012
1 parent 549b26a commit 17149f6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 26 deletions.
4 changes: 2 additions & 2 deletions .mailmap
Expand Up @@ -21,7 +21,7 @@
<devin.carlen@gmail.com> <devcamcar@illian.local>
<doug.hellmann@dreamhost.com> <doug.hellmann@gmail.com>
<dprince@redhat.com> <dan.prince@rackspace.com>
<edouard1.thuleau@orange.com> <thuleau@gmail.com>
<edouard.thuleau@orange.com> <thuleau@gmail.com>
<ewan.mellor@citrix.com> <emellor@silver>
<ghe@debian.org> <ghe.rivero@gmail.com>
<ilyaalekseyev@acm.org> <ialekseev@griddynamics.com>
Expand Down Expand Up @@ -85,6 +85,7 @@ Dan Wendlandt <dan@nicira.com> danwent <dan@nicira.com>
Dan Wendlandt <dan@nicira.com> danwent <danwent@dan-xs3-cs>
Dan Wendlandt <dan@nicira.com> danwent@gmail.com <>
Dan Wendlandt <dan@nicira.com> danwent@gmail.com <dan@nicira.com>
Édouard Thuleau <edouard.thuleau@orange.com> Thuleau Édouard <thuleau@gmail.com>
Jake Dahn <jake@ansolabs.com> jakedahn <jake@ansolabs.com>
Jason Koelker <jason@koelker.net> Jason Kölker <jason@koelker.net>
Jay Pipes <jaypipes@gmail.com> jaypipes@gmail.com <>
Expand Down Expand Up @@ -116,4 +117,3 @@ Vishvananda Ishaya <vishvananda@gmail.com> <root@mirror.nasanebula.net>
Vishvananda Ishaya <vishvananda@gmail.com> <root@ubuntu>
Vivek YS <vivek.ys@gmail.com> Vivek YS vivek.ys@gmail.com <>
Zhongyue Luo <zhongyue.nah@intel.com> <lzyeval@gmail.com>
Édouard Thuleau <edouard1.thuleau@orange.com> Thuleau Édouard <thuleau@gmail.com>
30 changes: 7 additions & 23 deletions nova/compute/manager.py
Expand Up @@ -1242,43 +1242,27 @@ def _rotate_backups(self, context, instance, backup_type, rotation):
: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)

Expand Down
2 changes: 1 addition & 1 deletion nova/image/glance.py
Expand Up @@ -177,7 +177,7 @@ def _extract_query_params(self, params):
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
Expand Down

0 comments on commit 17149f6

Please sign in to comment.