From eddcf4c6e982335d8acb8f3b408b2bb841890af8 Mon Sep 17 00:00:00 2001 From: Zane Bitter Date: Thu, 16 May 2013 13:18:18 +0200 Subject: [PATCH] Rename handle_snapshot and pass state Rename handle_snapshot() to handle_snapshot_delete() to better reflect what it needs to do (both take a snapshot of the resource and then delete the resource). Also, pass the state of the resource prior to delete being invoked, since the resource may want to use different error handling in the snapshot phase depending on e.g. whether the resource was created successfully or not. Change-Id: I1e5aaab4f13e42333c1f2f39bfeb0ebf2ac89ed8 --- heat/engine/resource.py | 8 +++++--- heat/engine/resources/volume.py | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/heat/engine/resource.py b/heat/engine/resource.py index 47d72fe5..b34a3c67 100644 --- a/heat/engine/resource.py +++ b/heat/engine/resource.py @@ -415,7 +415,7 @@ class Resource(object): msg = 'Invalid DeletionPolicy %s' % deletion_policy raise exception.StackValidationFailed(message=msg) elif deletion_policy == 'Snapshot': - if not callable(getattr(cls, 'handle_snapshot', None)): + if not callable(getattr(cls, 'handle_snapshot_delete', None)): msg = 'Snapshot DeletionPolicy not supported' raise exception.StackValidationFailed(message=msg) @@ -432,6 +432,8 @@ class Resource(object): if self.state is None: return + initial_state = self.state + logger.info('deleting %s' % str(self)) try: @@ -442,8 +444,8 @@ class Resource(object): if callable(getattr(self, 'handle_delete', None)): self.handle_delete() elif deletion_policy == 'Snapshot': - if callable(getattr(self, 'handle_snapshot', None)): - self.handle_snapshot() + if callable(getattr(self, 'handle_snapshot_delete', None)): + self.handle_snapshot_delete(initial_state) except Exception as ex: logger.exception('Delete %s', str(self)) failure = exception.ResourceFailure(ex) diff --git a/heat/engine/resources/volume.py b/heat/engine/resources/volume.py index c1a4ae4c..63aeb6e8 100644 --- a/heat/engine/resources/volume.py +++ b/heat/engine/resources/volume.py @@ -79,7 +79,7 @@ class Volume(resource.Resource): return self.UPDATE_REPLACE if volume_backups is not None: - def handle_snapshot(self): + def handle_snapshot_delete(self, state): if self.resource_id is not None: # We use backups as snapshots are not independent of volumes backup = self.cinder().backups.create(self.resource_id) -- 2.45.2