[vm] cleanup

This commit is contained in:
Nico Schottelius 2020-08-01 18:30:40 +02:00
parent cbd5a08ae7
commit 880e4d046b

View file

@ -97,11 +97,6 @@ class VMProduct(Product):
RecurringPeriod.PER_30D, RecurringPeriod.PER_HOUR],
RecurringPeriod.choices))
def __str__(self):
return "VM {} ({} Cores/{} GB RAM) running on {} in cluster {}".format(
self.uuid, self.cores, self.ram_in_gb,
self.vmhost, self.vmcluster)
class VMWithOSProduct(VMProduct):
primary_disk = models.ForeignKey('VMDiskProduct', on_delete=models.CASCADE, null=True)
@ -115,9 +110,6 @@ class VMDiskImageProduct(UncloudModel):
"""
uuid = models.UUIDField(
primary_key=True, default=uuid.uuid4, editable=False
)
owner = models.ForeignKey(
get_user_model(), on_delete=models.CASCADE, editable=False
)
@ -166,7 +158,9 @@ class VMDiskProduct(Product):
"""
vm = models.ForeignKey(VMProduct, on_delete=models.CASCADE)
image = models.ForeignKey(VMDiskImageProduct, on_delete=models.CASCADE)
image = models.ForeignKey(VMDiskImageProduct, on_delete=models.CASCADE,
blank=True, null=True)
size_in_gb = models.FloatField(blank=True)
@ -181,22 +175,16 @@ class VMDiskProduct(Product):
@property
def recurring_price(self):
return (self.size_in_gb / 10) * 3.5
# 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':
# raise ValidationError({
# 'image': 'VM Disk must be created from an active disk image.'
# })
def save(self, *args, **kwargs):
self.full_clean()
super().save(*args, **kwargs)
if self.disk_type == VMDiskType.CEPH_SSD:
price_per_gb = 3.5/10
elif self.disk_type == VMDiskType.CEPH_HDD:
price_per_gb = 1.5/100
elif self.disk_type == VMDiskType.LOCAL_SSD:
price_per_gb = 3.5/10
elif self.disk_type == VMDiskType.CEPH_HDD:
price_per_gb = 1.5/100
return self.size_in_gb * price_per_gb
class VMNetworkCard(models.Model):