From 48572c4af3f6c41d31bd77797ebd3dd25fbbc36a Mon Sep 17 00:00:00 2001 From: Russell Bryant Date: Wed, 1 Aug 2012 12:18:33 -0400 Subject: Pass a full instance to rotate_backups(). This patch renames rotate_backups() to _rotate_backups(), as this method has never been used over rpc since it was first introduced in 75a87df739effe840e6cb39c976002e99b49c796. The name change makes it more clear that it's a private method. The change also makes it so this method takes an instance dict instead of just the instance_uuid as an argument. This is mainly for consistency with the rest of this file, where things are moving toward passing the full instance dict around instead to avoid any potential need for db access. In passing, this also fixes up some uses of instance_uuid in snapshot_instance() where instance_uuid is most likely None. Part of blueprint no-db-messaging. Change-Id: I275f71384e77eb038aa1140bbfde108b91cd2f83 --- nova/compute/manager.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 134983f01..a7e936955 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -1132,7 +1132,7 @@ class ComputeManager(manager.SchedulerDependentManager): power_state=current_power_state) LOG.audit(_('instance snapshotting'), context=context, - instance_uuid=instance_uuid) + instance=instance) if instance['power_state'] != power_state.RUNNING: state = instance['power_state'] @@ -1140,7 +1140,7 @@ class ComputeManager(manager.SchedulerDependentManager): LOG.warn(_('trying to snapshot a non-running ' 'instance: (state: %(state)s ' 'expected: %(running)s)') % locals(), - instance_uuid=instance_uuid) + instance=instance) self._notify_about_instance_usage( context, instance, "snapshot.start") @@ -1155,7 +1155,7 @@ class ComputeManager(manager.SchedulerDependentManager): raise exception.ImageRotationNotAllowed() elif image_type == 'backup' and rotation: - self.rotate_backups(context, instance_uuid, backup_type, rotation) + self._rotate_backups(context, instance, backup_type, rotation) elif image_type == 'backup': raise exception.RotationRequiredForBackup() @@ -1164,7 +1164,7 @@ class ComputeManager(manager.SchedulerDependentManager): context, instance, "snapshot.end") @wrap_instance_fault - def rotate_backups(self, context, instance_uuid, backup_type, rotation): + def _rotate_backups(self, context, instance, backup_type, rotation): """Delete excess backups associated to an instance. Instances are allowed a fixed number of backups (the rotation number); @@ -1172,7 +1172,7 @@ class ComputeManager(manager.SchedulerDependentManager): threshold. :param context: security context - :param instance_uuid: string representing uuid of instance + :param instance: Instance dict :param backup_type: daily | weekly :param rotation: int representing how many backups to keep around; None if rotation shouldn't be used (as in the case of snapshots) @@ -1193,23 +1193,23 @@ class ComputeManager(manager.SchedulerDependentManager): image_service = glance.get_default_image_service() filters = {'property-image_type': 'backup', 'property-backup_type': backup_type, - 'property-instance_uuid': instance_uuid} + 'property-instance_uuid': instance['uuid']} images = fetch_images() num_images = len(images) LOG.debug(_("Found %(num_images)d images (rotation: %(rotation)d)") - % locals(), instance_uuid=instance_uuid) + % 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, - instance_uuid=instance_uuid) + instance=instance) for i in xrange(excess): image = images.pop() image_id = image['id'] LOG.debug(_("Deleting image %s") % image_id, - instance_uuid=instance_uuid) + instance=instance) image_service.delete(context, image_id) @exception.wrap_exception(notifier=notifier, publisher_id=publisher_id()) -- cgit