summaryrefslogtreecommitdiffstats
path: root/nova/api
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2013-01-02 19:50:18 +0000
committerGerrit Code Review <review@openstack.org>2013-01-02 19:50:18 +0000
commitfdcf843a4885b69fdaffe60437b462a1ea44ae5b (patch)
treec59e4c602d882817bd3f8437c54c395b86f59068 /nova/api
parentc66755f0edfe803653e5e278dc078a7a7e82b6e4 (diff)
parent2b619e271624eb84947a9a9596745d06efe81b08 (diff)
downloadnova-fdcf843a4885b69fdaffe60437b462a1ea44ae5b.tar.gz
nova-fdcf843a4885b69fdaffe60437b462a1ea44ae5b.tar.xz
nova-fdcf843a4885b69fdaffe60437b462a1ea44ae5b.zip
Merge "Adds os-volume_attachments 'volume_id' validation"
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)