forked from uncloud/uncloud
[vm] cleanup
This commit is contained in:
parent
cbd5a08ae7
commit
880e4d046b
1 changed files with 12 additions and 24 deletions
|
@ -97,11 +97,6 @@ class VMProduct(Product):
|
||||||
RecurringPeriod.PER_30D, RecurringPeriod.PER_HOUR],
|
RecurringPeriod.PER_30D, RecurringPeriod.PER_HOUR],
|
||||||
RecurringPeriod.choices))
|
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):
|
class VMWithOSProduct(VMProduct):
|
||||||
primary_disk = models.ForeignKey('VMDiskProduct', on_delete=models.CASCADE, null=True)
|
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(
|
owner = models.ForeignKey(
|
||||||
get_user_model(), on_delete=models.CASCADE, editable=False
|
get_user_model(), on_delete=models.CASCADE, editable=False
|
||||||
)
|
)
|
||||||
|
@ -166,7 +158,9 @@ class VMDiskProduct(Product):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
vm = models.ForeignKey(VMProduct, on_delete=models.CASCADE)
|
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)
|
size_in_gb = models.FloatField(blank=True)
|
||||||
|
|
||||||
|
@ -181,22 +175,16 @@ class VMDiskProduct(Product):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def recurring_price(self):
|
def recurring_price(self):
|
||||||
return (self.size_in_gb / 10) * 3.5
|
if self.disk_type == VMDiskType.CEPH_SSD:
|
||||||
|
price_per_gb = 3.5/10
|
||||||
# Ensures that a VMDiskProduct can only be created from a VMDiskImageProduct
|
elif self.disk_type == VMDiskType.CEPH_HDD:
|
||||||
# that is in status 'active'
|
price_per_gb = 1.5/100
|
||||||
# This might not be need in "for billing only" constellations
|
elif self.disk_type == VMDiskType.LOCAL_SSD:
|
||||||
|
price_per_gb = 3.5/10
|
||||||
# def clean(self):
|
elif self.disk_type == VMDiskType.CEPH_HDD:
|
||||||
# if self.image.status != 'active':
|
price_per_gb = 1.5/100
|
||||||
# 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)
|
|
||||||
|
|
||||||
|
return self.size_in_gb * price_per_gb
|
||||||
|
|
||||||
|
|
||||||
class VMNetworkCard(models.Model):
|
class VMNetworkCard(models.Model):
|
||||||
|
|
Loading…
Reference in a new issue