From cf51acfeafe33d92c1eefbbb7b377362cf9acd7e Mon Sep 17 00:00:00 2001 From: Chif Gergo <chif.gergo@cloud.bme.hu> Date: Wed, 3 Jul 2019 13:31:12 +0200 Subject: [PATCH] instance: Create Flavor and Lease model. Add fields to instance --- recircle/image/views.py | 2 +- recircle/instance/models.py | 59 +++++++++++++++++++++++++++++++++++++++++++++++------------ recircle/instance/views.py | 2 +- 3 files changed, 49 insertions(+), 14 deletions(-) diff --git a/recircle/image/views.py b/recircle/image/views.py index 407335e..ef06592 100644 --- a/recircle/image/views.py +++ b/recircle/image/views.py @@ -3,7 +3,7 @@ from image.serializers import DiskSerializer # from django.shortcuts import render from rest_framework.views import APIView from rest_framework.response import Response -from interface_openstack.implementation.image.OpenstackImageManager import ( +from implementation.image.OpenstackImageManager import ( OpenstackImageManager, ) import openstack diff --git a/recircle/instance/models.py b/recircle/instance/models.py index 07cb28d..cd99191 100644 --- a/recircle/instance/models.py +++ b/recircle/instance/models.py @@ -1,19 +1,44 @@ from django.db import models from django.conf import settings +from django.contrib.auth.models import User +from storage import Disk ACCESS_METHODS = tuple( [(key, val[0]) for key, val in settings.VM_ACCESS_PROTOCOLS.items()] ) -# Later stored in database -LEASE_TYPES = tuple( - [(val["name"], val["verbose_name"]) for val in settings.LEASE_TYPES] -) + +class Lease(models.Model): + """ Users can use the virtual machine until the lease dates. + After suspend interval the vm suspends and after delete it will be + destroyed + """ + name = models.CharField(blank=True, max_length=100) + description = models.CharField(blank=True, max_length=100) + suspend_interval_in_sec = models.IntegerField(blank=True, null=True) + delete_interval_in_sec = models.IntegerField(blank=True, null=True) + + +class Flavor(models.Model): + """ Flavors are reasource packages, contains all information about + resources accociated with the virtual machine + """ + name = models.CharField(blank=True, max_length=100) + description = models.CharField(blank=True, max_length=200) + ram = models.IntegerField(blank=True, null=True) + vcpu = models.IntegerField(blank=True, null=True) + initial_disk = models.IntegerField(blank=True, null=True) + priority = models.IntegerField(blank=True, null=True) class Instance(models.Model): - name = models.CharField(max_length=100, help_text="Human readable name of instance") + """Virtual machine instance. + """ + + name = models.CharField(max_length=100, + help_text="Human readable name of instance") + remote_id = models.CharField( max_length=100, help_text="ID of the instance on the backend" ) @@ -21,15 +46,13 @@ class Instance(models.Model): blank=True, help_text="The description of the instance" ) access_method = models.CharField( - max_length=10, choices=ACCESS_METHODS, help_text="Primary remote access method" + max_length=10, choices=ACCESS_METHODS, + help_text="Primary remote access method" ) system = models.CharField(max_length=50, help_text="Operating system type") password = models.CharField( max_length=50, help_text="Original password of the instance" ) - lease = models.CharField( - max_length=50, choices=LEASE_TYPES, help_text="Expiration method" - ) time_of_suspend = models.DateTimeField( help_text="After this point in time, the instance will be suspended" ) @@ -40,6 +63,18 @@ class Instance(models.Model): help_text="Indicates if the instance is ready for garbage collection", default=False, ) - # template - # disks - # owner + + # image = models.ForeignKey(TemplateImage, related_name="vm", null=True, + # help_text="The base image of the vm") + # + # snapshot = models.ForeignKey(Snapshot, related_name="vm", null=True, + # help_text="The base snapshot of the vm") + + disks = models.ManyToManyField(Disk, related_name="instance", + help_text="Disks attached to instance", + verbose_name="disks") + + owner = models.ForeignKey(User) + flavor = models.ForeignKey(Flavor, help_text="Reasources given to the vm", + verbose_name="flavor") + lease = models.ForeignKey(Lease) diff --git a/recircle/instance/views.py b/recircle/instance/views.py index 8a2d855..4f6febe 100644 --- a/recircle/instance/views.py +++ b/recircle/instance/views.py @@ -4,7 +4,7 @@ from django.http import Http404 from rest_framework.views import APIView from rest_framework.response import Response from rest_framework import status -from interface_openstack.implementation.vm.instance import OSVirtualMachineManager +from implementation.vm.instance import OSVirtualMachineManager import openstack import datetime -- libgit2 0.26.0