summaryrefslogtreecommitdiffstats
path: root/nova/api
diff options
context:
space:
mode:
Diffstat (limited to 'nova/api')
-rw-r--r--nova/api/openstack/compute/contrib/volumes.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/nova/api/openstack/compute/contrib/volumes.py b/nova/api/openstack/compute/contrib/volumes.py
index abdef3a7d..9564921f4 100644
--- a/nova/api/openstack/compute/contrib/volumes.py
+++ b/nova/api/openstack/compute/contrib/volumes.py
@@ -26,6 +26,7 @@ from nova.api.openstack import xmlutil
from nova import compute
from nova import exception
from nova.openstack.common import log as logging
+from nova.openstack.common import uuidutils
from nova import utils
from nova import volume
@@ -365,6 +366,12 @@ class VolumeAttachmentController(wsgi.Controller):
instance['uuid'],
assigned_mountpoint)}
+ def _validate_volume_id(self, volume_id):
+ if not uuidutils.is_uuid_like(volume_id):
+ msg = _("Bad volumeId format: volumeId is "
+ "not in proper format (%s)") % volume_id
+ raise exc.HTTPBadRequest(explanation=msg)
+
@wsgi.serializers(xml=VolumeAttachmentTemplate)
def create(self, req, server_id, body):
"""Attach a volume to an instance."""
@@ -377,6 +384,8 @@ class VolumeAttachmentController(wsgi.Controller):
volume_id = body['volumeAttachment']['volumeId']
device = body['volumeAttachment'].get('device')
+ self._validate_volume_id(volume_id)
+
msg = _("Attach volume %(volume_id)s to instance %(server_id)s"
" at %(device)s") % locals()
LOG.audit(msg, context=context)