[models] update / doc

This commit is contained in:
Nico Schottelius 2020-08-01 16:29:24 +02:00
parent 9c1b4ab275
commit 64780bfc6c
2 changed files with 29 additions and 7 deletions

View file

@ -56,7 +56,7 @@ def default_payment_delay():
# See https://docs.djangoproject.com/en/dev/ref/models/fields/#field-choices-enum-types
class RecurringPeriod(models.IntegerChoices):
"""
We don't support months are years, because the vary in length.
We don't support months are years, because they vary in length.
This is not only complicated, but also unfair to the user, as the user pays the same
amount for different durations.
"""
@ -648,6 +648,9 @@ class Product(UncloudModel):
@property
def one_time_price(self):
"""
Default is 0 CHF
"""
return 0
@property

View file

@ -54,6 +54,7 @@ class VMHost(UncloudModel):
return self.usable_cores - sum([vm.cores for vm in self.vms ])
class VMProduct(Product):
vmhost = models.ForeignKey(
VMHost, on_delete=models.CASCADE, editable=False, blank=True, null=True
@ -75,8 +76,12 @@ class VMProduct(Product):
return self.cores * 3 + self.ram_in_gb * 4
def __str__(self):
return "VM {} ({}): {} cores {} gb ram".format(self.uuid,
self.name,
if self.name:
name = f"{self.name} ({self.id})"
else:
name = self.id
return "VM {}: {} cores {} gb ram".format(name,
self.cores,
self.ram_in_gb)
@ -140,6 +145,16 @@ class VMDiskImageProduct(UncloudModel):
self.size_in_gb)
# See https://docs.djangoproject.com/en/dev/ref/models/fields/#field-choices-enum-types
class VMDiskType(models.TextChoices):
"""
Types of disks that can be attached to VMs
"""
CEPH_SSD = 'ceph/ssd'
CEPH_HDD = 'ceph/hdd'
LOCAL_SSD = 'local/ssd'
LOCAL_HDD = 'local/hdd'
class VMDiskProduct(Product):
"""
@ -155,6 +170,11 @@ class VMDiskProduct(Product):
size_in_gb = models.FloatField(blank=True)
disk_type = models.CharField(
max_length=20,
choices=VMDiskType.choices,
default=VMDiskType.CEPH_SSD)
@property
def description(self):
return "Disk for VM '{}': {}GB".format(self.vm.name, self.size_in_gb)
@ -163,10 +183,9 @@ class VMDiskProduct(Product):
def recurring_price(self):
return (self.size_in_gb / 10) * 3.5
# Sample code for clean method
# Ensures that a VMDiskProduct can only be created from a VMDiskImageProduct
# that is in status 'active'
# This might not be need in "for billing only" constellations
# def clean(self):
# if self.image.status != 'active':