uncloud/uncloud/uncloud_vm/models.py

74 lines
2.5 KiB
Python
Raw Normal View History

from django.db import models
from django.contrib.auth import get_user_model
import uuid
class VMHost(models.Model):
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
# 253 is the maximum DNS name length
hostname = models.CharField(max_length=253, unique=True)
# indirectly gives a maximum number of cores / VM - f.i. 32
physical_cores = models.IntegerField(default=0)
# determines the maximum usable cores - f.i. 320 if you overbook by a factor of 10
usable_cores = models.IntegerField(default=0)
# ram that can be used of the server
usable_ram_in_gb = models.FloatField(default=0)
status = models.CharField(max_length=32,
choices = (
('pending', 'Pending'),
('active', 'Active'),
('unusable', 'Unusable'),
('deleted', 'Deleted'),
),
default='pending'
)
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,
blank=True,
null=True)
cores = models.IntegerField()
ram_in_gb = models.FloatField()
class VMWithOSProduct(VMProduct):
pass
class VMDiskProduct(models.Model):
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
vm = models.ForeignKey(VMProduct, on_delete=models.CASCADE)
size_in_gb = models.FloatField()
storage_class = models.CharField(max_length=32,
choices = (
('hdd', 'HDD'),
('ssd', 'SSD'),
),
default='ssd'
)
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()