summaryrefslogtreecommitdiffstats
path: root/nova/api
diff options
context:
space:
mode:
Diffstat (limited to 'nova/api')
-rw-r--r--nova/api/openstack/common.py15
-rw-r--r--nova/api/openstack/compute/contrib/admin_actions.py2
-rw-r--r--nova/api/openstack/compute/image_metadata.py8
-rw-r--r--nova/api/openstack/compute/servers.py2
4 files changed, 21 insertions, 6 deletions
diff --git a/nova/api/openstack/common.py b/nova/api/openstack/common.py
index 0d419f205..01787712a 100644
--- a/nova/api/openstack/common.py
+++ b/nova/api/openstack/common.py
@@ -269,7 +269,7 @@ def get_version_from_href(href):
return '2'
-def check_img_metadata_quota_limit(context, metadata):
+def check_img_metadata_properties_quota(context, metadata):
if metadata is None:
return
num_metadata = len(metadata)
@@ -279,6 +279,19 @@ def check_img_metadata_quota_limit(context, metadata):
raise webob.exc.HTTPRequestEntityTooLarge(explanation=expl,
headers={'Retry-After': 0})
+ # check the key length.
+ if isinstance(metadata, dict):
+ for key, value in metadata.iteritems():
+ if len(key) == 0:
+ expl = _("Image metadata key cannot be blank")
+ raise webob.exc.HTTPBadRequest(explanation=expl)
+ if len(key) > 255:
+ expl = _("Image metadata key too long")
+ raise webob.exc.HTTPBadRequest(explanation=expl)
+ else:
+ expl = _("Invalid image metadata")
+ raise webob.exc.HTTPBadRequest(explanation=expl)
+
def dict_to_query_str(params):
# TODO(throughnothing): we should just use urllib.urlencode instead of this
diff --git a/nova/api/openstack/compute/contrib/admin_actions.py b/nova/api/openstack/compute/contrib/admin_actions.py
index f7908f758..f9e661062 100644
--- a/nova/api/openstack/compute/contrib/admin_actions.py
+++ b/nova/api/openstack/compute/contrib/admin_actions.py
@@ -231,7 +231,7 @@ class AdminActionsController(wsgi.Controller):
props = {}
metadata = entity.get('metadata', {})
- common.check_img_metadata_quota_limit(context, metadata)
+ common.check_img_metadata_properties_quota(context, metadata)
try:
props.update(metadata)
except ValueError:
diff --git a/nova/api/openstack/compute/image_metadata.py b/nova/api/openstack/compute/image_metadata.py
index d79692f22..145e0395e 100644
--- a/nova/api/openstack/compute/image_metadata.py
+++ b/nova/api/openstack/compute/image_metadata.py
@@ -64,7 +64,8 @@ class Controller(object):
if 'metadata' in body:
for key, value in body['metadata'].iteritems():
image['properties'][key] = value
- common.check_img_metadata_quota_limit(context, image['properties'])
+ common.check_img_metadata_properties_quota(context,
+ image['properties'])
self.image_service.update(context, image_id, image, None)
return dict(metadata=image['properties'])
@@ -88,7 +89,8 @@ class Controller(object):
image = self._get_image(context, image_id)
image['properties'][id] = meta[id]
- common.check_img_metadata_quota_limit(context, image['properties'])
+ common.check_img_metadata_properties_quota(context,
+ image['properties'])
self.image_service.update(context, image_id, image, None)
return dict(meta=meta)
@@ -98,7 +100,7 @@ class Controller(object):
context = req.environ['nova.context']
image = self._get_image(context, image_id)
metadata = body.get('metadata', {})
- common.check_img_metadata_quota_limit(context, metadata)
+ common.check_img_metadata_properties_quota(context, metadata)
image['properties'] = metadata
self.image_service.update(context, image_id, image, None)
return dict(metadata=metadata)
diff --git a/nova/api/openstack/compute/servers.py b/nova/api/openstack/compute/servers.py
index 635123fff..9aa637cc9 100644
--- a/nova/api/openstack/compute/servers.py
+++ b/nova/api/openstack/compute/servers.py
@@ -1093,7 +1093,7 @@ class Controller(wsgi.Controller):
props = {}
metadata = entity.get('metadata', {})
- common.check_img_metadata_quota_limit(context, metadata)
+ common.check_img_metadata_properties_quota(context, metadata)
try:
props.update(metadata)
except ValueError: