Commit cf51acfe by Chif Gergő

instance: Create Flavor and Lease model. Add fields to instance

parent 415ba749
......@@ -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
......
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)
......@@ -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
......
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