Commit 57469aaa authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

cyclades: Add 'disk_template' to Volumes

Also check GANETI_CLONE_PROVIDERS.
parent fc96f8c6
......@@ -214,21 +214,6 @@ def get_flavor(flavor_id, include_deleted=False):
raise faults.ItemNotFound('Flavor not found.')
def get_flavor_provider(flavor):
"""Extract provider from disk template.
Provider for `ext` disk_template is encoded in the disk template
name, which is formed `ext_<provider_name>`. Provider is None
for all other disk templates.
"""
disk_template = flavor.disk_template
provider = None
if disk_template.startswith("ext"):
disk_template, provider = disk_template.split("_", 1)
return disk_template, provider
def get_network(network_id, user_id, for_update=False, non_deleted=False):
"""Return a Network instance or raise ItemNotFound."""
......
......@@ -1012,6 +1012,9 @@ class Volume(models.Model):
userid = models.CharField("Owner's UUID", max_length=100, null=False,
db_index=True)
size = models.IntegerField("Volume size in GB", null=False)
disk_template = models.CharField('Disk template', max_length=32,
null=False)
delete_on_termination = models.BooleanField("Delete on Server Termination",
default=True, null=False)
......@@ -1069,23 +1072,15 @@ class Volume(models.Model):
return None
@property
def disk_template(self):
if self.machine is None:
return None
else:
disk_template = self.machine.flavor.disk_template
return disk_template.split("_")[0]
def template(self):
return self.disk_template.split("_")[0]
@property
def disk_provider(self):
if self.machine is None:
return None
def provider(self):
if "_" in self.disk_template:
return self.disk_template.split("_", 1)[1]
else:
disk_template = self.machine.flavor.disk_template
if "_" in disk_template:
return disk_template.split("_")[1]
else:
return None
return None
@staticmethod
def prefix_source(source_id, source_type):
......
......@@ -716,7 +716,7 @@ def create_instance(vm, nics, volumes, flavor, image):
for volume in volumes:
disk = {"name": volume.backend_volume_uuid,
"size": volume.size * 1024}
provider = flavor.disk_provider
provider = volume.provider
if provider is not None:
disk["provider"] = provider
disk["origin"] = volume.origin
......
......@@ -57,3 +57,17 @@ def volume_to_links(volume_id):
def snapshot_to_links(snapshot_id):
href = join_urls(SNAPSHOTS_URL, str(snapshot_id))
return [{"rel": rel, "href": href} for rel in ("self", "bookmark")]
def get_disk_template_provider(disk_template):
"""Extract provider from disk template.
Provider for `ext` disk_template is encoded in the disk template
name, which is formed `ext_<provider_name>`. Provider is None
for all other disk templates.
"""
provider = None
if disk_template.startswith("ext") and "_" in disk_template:
disk_template, provider = disk_template.split("_", 1)
return disk_template, provider
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.volume import util
......@@ -57,7 +58,9 @@ def _create_volume(server, user_id, size, source_type, source_uuid,
# 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
can_have_source = (index == 0 or disk_template.startswith("ext_"))
teplate, provider = util.get_disk_template_provider(disk_template)
can_have_source = (index == 0 or
provider in settings.GANETI_CLONE_PROVIDERS)
if not can_have_source and source_type != "blank":
msg = ("Volumes of '%s' disk template cannot have a source" %
disk_template)
......@@ -111,6 +114,7 @@ def _create_volume(server, user_id, size, source_type, source_uuid,
volume = Volume.objects.create(userid=user_id,
size=size,
disk_template=disk_template,
name=name,
machine=server,
description=description,
......
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