summaryrefslogtreecommitdiffstats
path: root/nova/api
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2013-01-17 18:49:28 +0000
committerGerrit Code Review <review@openstack.org>2013-01-17 18:49:28 +0000
commitc3cf7ea354983dad7a7eed17ff35980997167c72 (patch)
treee0880bfcd1bbd2ee434557116c9564da680c1753 /nova/api
parent1d8dc1eca40c7cb28dac622a81655576d4a43f3f (diff)
parent3b5679e44754ad5138e1697ba233d91776199853 (diff)
Merge "Validated device_name value in block device map"
Diffstat (limited to 'nova/api')
-rw-r--r--nova/api/openstack/compute/servers.py22
1 files changed, 17 insertions, 5 deletions
diff --git a/nova/api/openstack/compute/servers.py b/nova/api/openstack/compute/servers.py
index f0fdb5a15..308530b8e 100644
--- a/nova/api/openstack/compute/servers.py
+++ b/nova/api/openstack/compute/servers.py
@@ -561,17 +561,28 @@ class Controller(wsgi.Controller):
req.cache_db_instance(instance)
return instance
- def _validate_server_name(self, value):
+ def _check_string_length(self, value, name, max_length=None):
if not isinstance(value, basestring):
- msg = _("Server name is not a string or unicode")
+ msg = _("%s is not a string or unicode") % name
raise exc.HTTPBadRequest(explanation=msg)
if not value.strip():
- msg = _("Server name is an empty string")
+ msg = _("%s is an empty string") % name
+ raise exc.HTTPBadRequest(explanation=msg)
+
+ if max_length and len(value) > max_length:
+ msg = _("%(name)s can be at most %(max_length)s "
+ "characters.") % locals()
raise exc.HTTPBadRequest(explanation=msg)
- if not len(value) < 256:
- msg = _("Server name must be less than 256 characters.")
+ def _validate_server_name(self, value):
+ self._check_string_length(value, 'Server name', max_length=255)
+
+ def _validate_device_name(self, value):
+ self._check_string_length(value, 'Device name', max_length=255)
+
+ if ' ' in value:
+ msg = _("Device name cannot include spaces.")
raise exc.HTTPBadRequest(explanation=msg)
def _get_injected_files(self, personality):
@@ -809,6 +820,7 @@ class Controller(wsgi.Controller):
if self.ext_mgr.is_loaded('os-volumes'):
block_device_mapping = server_dict.get('block_device_mapping', [])
for bdm in block_device_mapping:
+ self._validate_device_name(bdm["device_name"])
if 'delete_on_termination' in bdm:
bdm['delete_on_termination'] = utils.bool_from_str(
bdm['delete_on_termination'])