Commit fa999091 authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

cyclades: Validate length of fields

parent c736bef3
......@@ -409,8 +409,10 @@ class VirtualMachine(models.Model):
class VirtualMachineMetadata(models.Model):
meta_key = models.CharField(max_length=50)
meta_value = models.CharField(max_length=500)
KEY_LENGTH = 50
VALUE_LENGTH = 500
meta_key = models.CharField(max_length=KEY_LENGTH)
meta_value = models.CharField(max_length=VALUE_LENGTH)
vm = models.ForeignKey(VirtualMachine, related_name='metadata',
on_delete=models.CASCADE)
......@@ -1004,12 +1006,15 @@ class Volume(models.Model):
" volume")
)
NAME_LENGTH = 255
DESCRIPTION_LENGTH = 255
SOURCE_IMAGE_PREFIX = "image:"
SOURCE_SNAPSHOT_PREFIX = "snapshot:"
SOURCE_VOLUME_PREFIX = "volume:"
name = models.CharField("Name", max_length=255, null=True)
description = models.CharField("Description", max_length=256, null=True)
name = models.CharField("Name", max_length=NAME_LENGTH, null=True)
description = models.CharField("Description",
max_length=DESCRIPTION_LENGTH, null=True)
userid = models.CharField("Owner's UUID", max_length=100, null=False,
db_index=True)
size = models.IntegerField("Volume size in GB", null=False)
......@@ -1099,8 +1104,10 @@ class Volume(models.Model):
class Metadata(models.Model):
key = models.CharField("Metadata Key", max_length=64)
value = models.CharField("Metadata Value", max_length=255)
KEY_LENGTH = 64
VALUE_LENGTH = 255
key = models.CharField("Metadata Key", max_length=KEY_LENGTH)
value = models.CharField("Metadata Value", max_length=VALUE_LENGTH)
class Meta:
abstract = True
......
......@@ -132,6 +132,10 @@ def create(userid, name, password, flavor, image_id, metadata={},
server_volumes.append(v)
for key, val in metadata.items():
utils.check_name_length(key, VirtualMachineMetadata.KEY_LENGTH,
"Metadata key is too long")
utils.check_name_length(val, VirtualMachineMetadata.VALUE_LENGTH,
"Metadata value is too long")
VirtualMachineMetadata.objects.create(
meta_key=key,
meta_value=val,
......
......@@ -3,9 +3,9 @@ import logging
from django.db import transaction
from django.conf import settings
from snf_django.lib.api import faults
from synnefo.db.models import Volume
from synnefo.db.models import Volume, VolumeMetadata
from synnefo.volume import util
from synnefo.logic import server_attachments
from synnefo.logic import server_attachments, utils
log = logging.getLogger(__name__)
......@@ -45,6 +45,10 @@ def create(user_id, size, server_id, name=None, description=None,
if metadata is not None:
for meta_key, meta_val in metadata.items():
utils.check_name_length(meta_key, VolumeMetadata.KEY_LENGTH,
"Metadata key is too long")
utils.check_name_length(meta_val, VolumeMetadata.VALUE_LENGTH,
"Metadata key is too long")
volume.metadata.create(key=meta_key, value=meta_val)
server_attachments.attach_volume(server, volume)
......@@ -56,6 +60,10 @@ def _create_volume(server, user_id, size, source_type, source_uuid,
name=None, description=None, index=None,
delete_on_termination=True):
utils.check_name_length(name, Volume.NAME_LENGTH,
"Volume name is too long")
utils.check_name_length(description, Volume.DESCRIPTION_LENGTH,
"Volume name is too long")
# Only ext_ disk template supports cloning from another source. Otherwise
# is must be the root volume so that 'snf-image' fill the volume
disk_template = server.flavor.disk_template
......
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