diff options
| author | Johannes Erdfelt <johannes.erdfelt@rackspace.com> | 2011-09-07 22:59:13 +0000 |
|---|---|---|
| committer | Johannes Erdfelt <johannes.erdfelt@rackspace.com> | 2011-09-07 22:59:13 +0000 |
| commit | 4968aade5ce77d1068a014baf5d520b94fd668dc (patch) | |
| tree | 2e248f6d9453b10f86c5d20b99b45ddb6f929dd6 | |
| parent | 7b73ecf540b9bd14bdc97306018eed170b0959eb (diff) | |
Make sure instance is deleted before allowing restore or forceDelete
| -rw-r--r-- | nova/compute/api.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/nova/compute/api.py b/nova/compute/api.py index 7c8b3cbfe..6ff8d96a1 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -92,6 +92,18 @@ def _is_able_to_shutdown(instance, instance_id): return True +def _is_delete_queued(instance, instance_id): + vm_state = instance["vm_state"] + task_state = instance["task_state"] + + if vm_state != vm_states.DELETED: + LOG.warn(_("Instance %(instance_id)s is not in a 'deleted' state. It " + "is currently %(vm_state)s. Action aborted.") % locals()) + return False + + return True + + class API(base.Base): """API for interacting with the compute manager.""" @@ -786,6 +798,9 @@ class API(base.Base): """Restore a previously deleted (but not reclaimed) instance.""" instance = self._get_instance(context, instance_id, 'restore') + if not _is_delete_queued(instance, instance_id): + return + self.update(context, instance_id, vm_state=vm_states.ACTIVE, @@ -803,6 +818,9 @@ class API(base.Base): """Force delete a previously deleted (but not reclaimed) instance.""" instance = self._get_instance(context, instance_id, 'force delete') + if not _is_delete_queued(instance, instance_id): + return + self.update(context, instance_id, task_state=task_states.DELETING) |
