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
This commit is contained in:
Zane Bitter 2013-05-16 13:18:18 +02:00
parent 5b82e2db04
commit eddcf4c6e9
2 changed files with 6 additions and 4 deletions

View File

@ -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)

View File

@ -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)