2020-02-23 13:07:37 +00:00
|
|
|
from django.db import models
|
2020-02-25 19:53:12 +00:00
|
|
|
from django.contrib.auth import get_user_model
|
|
|
|
import uuid
|
2020-02-23 13:07:37 +00:00
|
|
|
|
|
|
|
|
2020-02-23 16:43:06 +00:00
|
|
|
class VMHost(models.Model):
|
|
|
|
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
|
|
|
|
|
|
|
# 253 is the maximum DNS name length
|
2020-02-25 19:53:12 +00:00
|
|
|
hostname = models.CharField(max_length=253, unique=True)
|
2020-02-23 16:43:06 +00:00
|
|
|
|
|
|
|
# indirectly gives a maximum number of cores / VM - f.i. 32
|
2020-02-25 19:53:12 +00:00
|
|
|
physical_cores = models.IntegerField(default=0)
|
2020-02-23 16:43:06 +00:00
|
|
|
|
|
|
|
# determines the maximum usable cores - f.i. 320 if you overbook by a factor of 10
|
2020-02-25 19:53:12 +00:00
|
|
|
usable_cores = models.IntegerField(default=0)
|
2020-02-23 16:43:06 +00:00
|
|
|
|
|
|
|
# ram that can be used of the server
|
2020-02-25 19:53:12 +00:00
|
|
|
usable_ram_in_gb = models.FloatField(default=0)
|
2020-02-23 16:43:06 +00:00
|
|
|
|
|
|
|
|
2020-02-23 16:46:30 +00:00
|
|
|
status = models.CharField(max_length=32,
|
|
|
|
choices = (
|
|
|
|
('pending', 'Pending'),
|
|
|
|
('active', 'Active'),
|
|
|
|
('unusable', 'Unusable'),
|
2020-02-25 19:53:12 +00:00
|
|
|
('deleted', 'Deleted'),
|
2020-02-23 16:46:30 +00:00
|
|
|
),
|
|
|
|
default='pending'
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2020-02-25 19:53:12 +00:00
|
|
|
class VMProduct(models.Model):
|
|
|
|
uuid = models.UUIDField(primary_key=True,
|
|
|
|
default=uuid.uuid4,
|
|
|
|
editable=False)
|
|
|
|
owner = models.ForeignKey(get_user_model(),
|
|
|
|
on_delete=models.CASCADE,
|
|
|
|
editable=False)
|
|
|
|
vmhost = models.ForeignKey(VMHost,
|
|
|
|
on_delete=models.CASCADE,
|
|
|
|
editable=False)
|
2020-02-23 13:07:37 +00:00
|
|
|
|
|
|
|
cores = models.IntegerField()
|
2020-02-23 16:43:06 +00:00
|
|
|
ram_in_gb = models.FloatField()
|
|
|
|
|
2020-02-23 13:07:37 +00:00
|
|
|
|
2020-02-25 19:53:12 +00:00
|
|
|
class VMWithOSProduct(VMProduct):
|
|
|
|
pass
|
2020-02-23 13:07:37 +00:00
|
|
|
|
2020-02-25 19:53:12 +00:00
|
|
|
class VMDiskProduct(models.Model):
|
2020-02-23 16:43:06 +00:00
|
|
|
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
2020-02-25 19:53:12 +00:00
|
|
|
vm = models.ForeignKey(VMProduct, on_delete=models.CASCADE)
|
2020-02-23 16:43:06 +00:00
|
|
|
size_in_gb = models.FloatField()
|
|
|
|
|
|
|
|
storage_class = models.CharField(max_length=32,
|
|
|
|
choices = (
|
|
|
|
('hdd', 'HDD'),
|
|
|
|
('ssd', 'SSD'),
|
|
|
|
),
|
|
|
|
default='ssd'
|
|
|
|
)
|
2020-02-25 19:53:12 +00:00
|
|
|
|
|
|
|
class OperatingSystemDisk(VMDiskProduct):
|
|
|
|
""" Defines an Operating System Disk that can be cloned for a VM """
|
|
|
|
os_name = models.CharField(max_length=128)
|
|
|
|
|
|
|
|
|
|
|
|
class VMNetworkCard(models.Model):
|
|
|
|
vm = models.ForeignKey(VMProduct, on_delete=models.CASCADE)
|
|
|
|
mac_address = models.IntegerField()
|