uncloud-mravi/uncloud/uncloud_vm/models.py
Nico Schottelius 6a38e4e0a4 add url for importing disk image
Signed-off-by: Nico Schottelius <nico@nico-notebook.schottelius.org>
2020-02-29 17:00:13 +01:00

124 lines
3.8 KiB
Python

from django.db import models
from django.contrib.auth import get_user_model
import uuid
from uncloud_pay.models import Product
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(Product):
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 VMDiskImageProduct(models.Model):
"""
Images are used for cloning/linking.
They are the base for images.
"""
uuid = models.UUIDField(primary_key=True,
default=uuid.uuid4,
editable=False)
owner = models.ForeignKey(get_user_model(),
on_delete=models.CASCADE,
editable=False)
name = models.CharField(max_length=256)
is_os_image = models.BooleanField(default=False)
is_public = models.BooleanField(default=False)
size_in_gb = models.FloatField(null=True,
blank=True)
import_url = models.URLField(null=True,
blank=True)
storage_class = models.CharField(max_length=32,
choices = (
('hdd', 'HDD'),
('ssd', 'SSD'),
),
default='ssd'
)
# source = models.CharField(max_length=32,
# choices = (
# ('url', 'HDD'),
# ('ssd', 'SSD'),
# ),
# default='ssd'
# )
class VMDiskProduct(models.Model):
"""
The VMDiskProduct is attached to a VM.
It is based on a VMDiskImageProduct that will be used as a basis.
It can be enlarged, but not shrinked compared to the VMDiskImageProduct.
"""
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
owner = models.ForeignKey(get_user_model(),
on_delete=models.CASCADE,
editable=False)
vm = models.ForeignKey(VMProduct, on_delete=models.CASCADE)
image = models.ForeignKey(VMDiskImageProduct, on_delete=models.CASCADE)
size_in_gb = models.FloatField()
class VMNetworkCard(models.Model):
vm = models.ForeignKey(VMProduct, on_delete=models.CASCADE)
mac_address = models.IntegerField()
ip_address = models.GenericIPAddressField(blank=True,
null=True)
class VMSnapshotProduct(Product):
gb_ssd = models.FloatField(editable=False)
gb_hdd = models.FloatField(editable=False)
vm = models.ForeignKey(VMProduct, on_delete=models.CASCADE)