cyclades: Limit the number of Volumes metadata

* Add a setting in 20-snf-cyclades-app-api.conf to limit the number of
metadata items for volumes. The default value is set to 10.
* Add checks in volume create and update functions to enforce the above
setting.
parent 1abbcc12
......@@ -176,3 +176,6 @@
#
## The maximum allowed size(GB) for a Cyclades Volume
#CYCLADES_VOLUME_MAX_SIZE = 200
#
## The maximum allowed metadata items for a Cyclades Volume
#CYCLADES_VOLUME_MAX_METADATA = 10
......@@ -174,3 +174,6 @@ CYCLADES_VNCAUTHPROXY_OPTS = {
# The maximum allowed size(GB) for a Cyclades Volume
CYCLADES_VOLUME_MAX_SIZE = 200
# The maximum allowed metadata items for a Cyclades Volume
CYCLADES_VOLUME_MAX_METADATA = 10
......@@ -245,10 +245,22 @@ def update_volume_metadata(request, volume_id, reset=False):
volume = util.get_volume(request.user_uniq, volume_id, for_update=True,
non_deleted=True)
if reset:
if len(meta_dict) > settings.CYCLADES_VOLUME_MAX_METADATA:
raise faults.BadRequest("Volumes cannot have more than %s metadata "
"items" %
settings.CYCLADES_VOLUME_MAX_METADATA)
volume.metadata.all().delete()
for key, value in meta_dict.items():
volume.metadata.create(key=key, value=value)
else:
if len(meta_dict) + len(volume.metadata.all()) - \
len(volume.metadata.all().filter(key__in=meta_dict.keys())) > \
settings.CYCLADES_VOLUME_MAX_METADATA:
raise faults.BadRequest("Volumes cannot have more than %s metadata"
" items" %
settings.CYCLADES_VOLUME_MAX_METADATA)
for key, value in meta_dict.items():
try:
# Update existing metadata
......
......@@ -73,6 +73,12 @@ def create(user_id, size, server_id, name=None, description=None,
if project is None:
project = user_id
if metadata is not None and \
len(metadata) > settings.CYCLADES_VOLUME_MAX_METADATA:
raise faults.BadRequest("Volumes cannot have more than %s metadata "
"items" %
settings.CYCLADES_VOLUME_MAX_METADATA)
volume = _create_volume(server, user_id, project, size,
source_type, source_uuid,
volume_type=volume_type, name=name,
......
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