summaryrefslogtreecommitdiffstats
path: root/nova/api
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2013-03-22 14:51:37 +0000
committerGerrit Code Review <review@openstack.org>2013-03-22 14:51:37 +0000
commitc21016c26749f4efb0978d5e4fea9560fc4d0603 (patch)
tree92f3e01fc64c336c4c4e3dce0ee4799d179f59d4 /nova/api
parent127b32c00ca5e99439431d30d03775fd0e462f0a (diff)
parent26aa01094a79939320d58f2fe2d5731f169987b1 (diff)
Merge "Change arguments to volume_detach()"
Diffstat (limited to 'nova/api')
-rw-r--r--nova/api/ec2/cloud.py12
-rw-r--r--nova/api/openstack/compute/contrib/volumes.py15
2 files changed, 22 insertions, 5 deletions
diff --git a/nova/api/ec2/cloud.py b/nova/api/ec2/cloud.py
index a35460576..206a72679 100644
--- a/nova/api/ec2/cloud.py
+++ b/nova/api/ec2/cloud.py
@@ -897,14 +897,24 @@ class CloudController(object):
'status': volume['attach_status'],
'volumeId': ec2utils.id_to_ec2_vol_id(volume_id)}
+ def _get_instance_from_volume(self, context, volume):
+ if volume['instance_uuid']:
+ try:
+ return db.instance_get_by_uuid(context,
+ volume['instance_uuid'])
+ except exception.InstanceNotFound:
+ pass
+ raise exception.VolumeUnattached(volume_id=volume['id'])
+
def detach_volume(self, context, volume_id, **kwargs):
validate_ec2_id(volume_id)
volume_id = ec2utils.ec2_vol_id_to_uuid(volume_id)
LOG.audit(_("Detach volume %s"), volume_id, context=context)
volume = self.volume_api.get(context, volume_id)
+ instance = self._get_instance_from_volume(context, volume)
try:
- self.compute_api.detach_volume(context, volume_id=volume_id)
+ self.compute_api.detach_volume(context, instance, volume)
except exception.InvalidVolume:
raise exception.EC2APIError(_('Detach Volume Failed.'))
diff --git a/nova/api/openstack/compute/contrib/volumes.py b/nova/api/openstack/compute/contrib/volumes.py
index b16d61852..27f5e4050 100644
--- a/nova/api/openstack/compute/contrib/volumes.py
+++ b/nova/api/openstack/compute/contrib/volumes.py
@@ -326,6 +326,7 @@ class VolumeAttachmentController(wsgi.Controller):
def __init__(self):
self.compute_api = compute.API()
+ self.volume_api = volume.API()
super(VolumeAttachmentController, self).__init__()
@wsgi.serializers(xml=VolumeAttachmentsTemplate)
@@ -442,8 +443,9 @@ class VolumeAttachmentController(wsgi.Controller):
except exception.NotFound:
raise exc.HTTPNotFound()
- bdms = self.compute_api.get_instance_bdms(context, instance)
+ volume = self.volume_api.get(context, volume_id)
+ bdms = self.compute_api.get_instance_bdms(context, instance)
if not bdms:
LOG.debug(_("Instance %s is not attached."), server_id)
raise exc.HTTPNotFound()
@@ -451,11 +453,16 @@ class VolumeAttachmentController(wsgi.Controller):
found = False
try:
for bdm in bdms:
- if bdm['volume_id'] == volume_id:
- self.compute_api.detach_volume(context,
- volume_id=volume_id)
+ if bdm['volume_id'] != volume_id:
+ continue
+ try:
+ self.compute_api.detach_volume(context, instance, volume)
found = True
break
+ except exception.VolumeUnattached:
+ # The volume is not attached. Treat it as NotFound
+ # by falling through.
+ pass
except exception.InstanceInvalidState as state_error:
common.raise_http_conflict_for_instance_invalid_state(state_error,
'detach_volume')