From 84b73cf3d46200fef6521d79c8aa59ccb7a96224 Mon Sep 17 00:00:00 2001 From: Joe Gordon Date: Fri, 8 Mar 2013 02:17:22 +0000 Subject: Prevent volume-attach/detach from instances in rescue state Rescue is supposed to just be a way to log into a wayward instance if something goes wrong with the base image that may have had some data (logfiles etc.) and make it possible to grab that - block devices are assumed to be accessible by re-attaching them, and are considered persistant so no need for rescue there. Since there is no need to attach a volume in rescue mode, and detaching a volume that was previously attached doesn't work, just ban volume attach/detach in rescue state. Fixes bug 1126187 Change-Id: Ifdf164155942cdeb2bbdfcd1dce0dd2e125b507c --- nova/api/openstack/compute/contrib/volumes.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/compute/contrib/volumes.py b/nova/api/openstack/compute/contrib/volumes.py index 760dc953a..b58a7b442 100644 --- a/nova/api/openstack/compute/contrib/volumes.py +++ b/nova/api/openstack/compute/contrib/volumes.py @@ -402,6 +402,9 @@ class VolumeAttachmentController(wsgi.Controller): volume_id, device) except exception.NotFound: raise exc.HTTPNotFound() + except exception.InstanceInvalidState as state_error: + common.raise_http_conflict_for_instance_invalid_state(state_error, + 'attach_volume') # The attach is async attachment = {} @@ -446,12 +449,16 @@ class VolumeAttachmentController(wsgi.Controller): raise exc.HTTPNotFound() found = False - for bdm in bdms: - if bdm['volume_id'] == volume_id: - self.compute_api.detach_volume(context, - volume_id=volume_id) - found = True - break + try: + for bdm in bdms: + if bdm['volume_id'] == volume_id: + self.compute_api.detach_volume(context, + volume_id=volume_id) + found = True + break + except exception.InstanceInvalidState as state_error: + common.raise_http_conflict_for_instance_invalid_state(state_error, + 'detach_volume') if not found: raise exc.HTTPNotFound() -- cgit