cyclades: Limit the number of VM metadata items

* Add a setting in 20-snf-cyclades-app-api.conf to limit the number of
metadata items for Virtual Machines. The default value is set to 10.
* Add checks in VM create and update functions to enforce the above
setting.
parent 0d498b6e
......@@ -92,6 +92,10 @@ Cyclades
--------
* Add support for snf-vncauthproxy 1.6 (configurable VNC console types)
* Add setting `CYCLADES_VM_MAX_METADATA` to limit the maximum number of Virtual
Machine metadata items
* Add setting `CYCLADES_VOLUME_MAX_METADATA` to limit the maximum number of
Volume metadata items
Cyclades UI
-----------
......
......@@ -179,3 +179,6 @@
#
## The maximum allowed metadata items for a Cyclades Volume
#CYCLADES_VOLUME_MAX_METADATA = 10
#
## The maximum allowed metadata items for a Cyclades Virtual Machine
#CYCLADES_VM_MAX_METADATA = 10
......@@ -686,6 +686,13 @@ def update_metadata(request, server_id):
metadata = utils.get_attribute(req, "metadata", required=True,
attr_type=dict)
if len(metadata) + len(vm.metadata.all()) - \
len(vm.metadata.all().filter(meta_key__in=metadata.keys())) > \
settings.CYCLADES_VM_MAX_METADATA:
raise faults.BadRequest("Virtual Machines cannot have more than %s "
"metadata items" %
settings.CYCLADES_VM_MAX_METADATA)
for key, val in metadata.items():
if not isinstance(key, (basestring, int)) or\
not isinstance(val, (basestring, int)):
......
......@@ -177,3 +177,6 @@ CYCLADES_VOLUME_MAX_SIZE = 200
# The maximum allowed metadata items for a Cyclades Volume
CYCLADES_VOLUME_MAX_METADATA = 10
# The maximmum allowed metadata items for a Cyclades Virtual Machine
CYCLADES_VM_MAX_METADATA = 10
......@@ -67,6 +67,10 @@ def create(userid, name, password, flavor, image_id, metadata={},
raise faults.BadRequest("You need to specify either an image or a"
" block device mapping.")
if len(metadata) > settings.CYCLADES_VM_MAX_METADATA:
raise faults.BadRequest("Virtual Machines cannot have more than %s "
"metadata items" %
settings.CYCLADES_VM_MAX_METADATA)
# Get image info
image = util.get_image_dict(image_id, userid)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment