forked from uncloud/uncloud
++cleanup
Signed-off-by: Nico Schottelius <nico@nico-notebook.schottelius.org>
This commit is contained in:
parent
033b1e846a
commit
028fd6789f
37 changed files with 783 additions and 420 deletions
|
|
@ -2,6 +2,18 @@ from django.db import models
|
|||
from django.contrib.auth import get_user_model
|
||||
import uuid
|
||||
|
||||
from uncloud_pay.models import Product
|
||||
|
||||
STATUS_CHOICES = (
|
||||
('pending', 'Pending'), # Initial state
|
||||
('creating', 'Creating'), # Creating VM/image/etc.
|
||||
('active', 'Active'), # Is usable / active
|
||||
('disabled', 'Disabled'), # Is usable, but cannot be used for new things
|
||||
('unusable', 'Unusable'), # Has some kind of error
|
||||
('deleted', 'Deleted'), # Does not exist anymore, only DB entry as a log
|
||||
)
|
||||
|
||||
STATUS_DEFAULT='pending'
|
||||
|
||||
class VMHost(models.Model):
|
||||
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
||||
|
|
@ -20,23 +32,12 @@ class VMHost(models.Model):
|
|||
|
||||
|
||||
status = models.CharField(max_length=32,
|
||||
choices = (
|
||||
('pending', 'Pending'),
|
||||
('active', 'Active'),
|
||||
('unusable', 'Unusable'),
|
||||
('deleted', 'Deleted'),
|
||||
),
|
||||
default='pending'
|
||||
choices=STATUS_CHOICES,
|
||||
default=STATUS_DEFAULT
|
||||
)
|
||||
|
||||
|
||||
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)
|
||||
class VMProduct(Product):
|
||||
vmhost = models.ForeignKey(VMHost,
|
||||
on_delete=models.CASCADE,
|
||||
editable=False,
|
||||
|
|
@ -50,10 +51,31 @@ class VMProduct(models.Model):
|
|||
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()
|
||||
|
||||
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 = (
|
||||
|
|
@ -63,11 +85,42 @@ class VMDiskProduct(models.Model):
|
|||
default='ssd'
|
||||
)
|
||||
|
||||
class OperatingSystemDisk(VMDiskProduct):
|
||||
""" Defines an Operating System Disk that can be cloned for a VM """
|
||||
os_name = models.CharField(max_length=128)
|
||||
status = models.CharField(max_length=32,
|
||||
choices=STATUS_CHOICES,
|
||||
default=STATUS_DEFAULT
|
||||
)
|
||||
|
||||
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(blank=True)
|
||||
|
||||
|
||||
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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue