Commit 183bc1db by Bodor Máté

Implement create from volume function

parent a920b540
from django.db import models
from django.contrib.auth.models import User
from django.conf import settings
from image.models import Disk
from image.models import Image
from interface_openstack.implementation.storage.openstack_snapshot_manager import SnapshotManager
class BaseTemplate(models.Model):
......@@ -29,7 +33,15 @@ class BaseTemplate(models.Model):
editable=False,
help_text="Date, when the template created."
)
# owner = models.ForeignKey(User)
created_by = models.ForeignKey(
User,
on_delete=models.DO_NOTHING,
related_name=("created_templates")
)
# lease
# flavour
class Template(BaseTemplate):
......@@ -40,10 +52,24 @@ class Template(BaseTemplate):
help_text="The disk where the template is located."
)
@classmethod
def create_from_volume(cls, name, description, disk, user):
interface = SnapshotManager(settings.CONNECTION)
remote_template = interface.create_from_volume(disk.remote_ID)
remote_id = remote_template.id
new_template = cls.object.create(
name=name,
description=description,
disk=disk,
remote_ID=remote_id,
created_by=user
)
return new_template
# class PureTemplate(BaseTemplate):
# images = modesl.ForeignKey(
# Image,
# related_name="templates",
# on_delete=models.CASCADE
# )
class PureTemplate(BaseTemplate):
images = models.ForeignKey(
Image,
related_name="templates",
on_delete=models.CASCADE
)
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 sign in to comment