summaryrefslogtreecommitdiffstats
path: root/nova/api
diff options
context:
space:
mode:
Diffstat (limited to 'nova/api')
-rw-r--r--nova/api/openstack/compute/contrib/volumes.py19
1 files changed, 13 insertions, 6 deletions
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()