From f5897ed4b13f19e44553d63c621b9c54c7f5b5e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Floure?= Date: Mon, 13 Apr 2020 12:00:59 +0200 Subject: [PATCH] Adapt recurring price of VM and Matrix to new scheme --- .../uncloud/uncloud_service/models.py | 8 +++----- uncloud_django_based/uncloud/uncloud_vm/models.py | 13 +++---------- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/uncloud_django_based/uncloud/uncloud_service/models.py b/uncloud_django_based/uncloud/uncloud_service/models.py index 4f26a99..fb1af50 100644 --- a/uncloud_django_based/uncloud/uncloud_service/models.py +++ b/uncloud_django_based/uncloud/uncloud_service/models.py @@ -15,11 +15,9 @@ class MatrixServiceProduct(Product): ) domain = models.CharField(max_length=255, default='domain.tld') - def recurring_price(self, recurring_period=RecurringPeriod.PER_MONTH): - if recurring_period == RecurringPeriod.PER_MONTH: - return self.monthly_managment_fee - else: - raise Exception('Invalid recurring period for VM Product pricing.') + # Default recurring price is PER_MONT, see Product class. + def recurring_price(self): + return self.monthly_managment_fee @staticmethod def base_image(): diff --git a/uncloud_django_based/uncloud/uncloud_vm/models.py b/uncloud_django_based/uncloud/uncloud_vm/models.py index ee8eed1..f56ed0d 100644 --- a/uncloud_django_based/uncloud/uncloud_vm/models.py +++ b/uncloud_django_based/uncloud/uncloud_vm/models.py @@ -71,16 +71,9 @@ class VMProduct(Product): primary_disk = models.ForeignKey('VMDiskProduct', on_delete=models.CASCADE, null=True) - def recurring_price(self, recurring_period=RecurringPeriod.PER_MONTH): - # TODO: move magic numbers in variables - if recurring_period == RecurringPeriod.PER_MONTH: - return self.cores * 3 + self.ram_in_gb * 4 - elif recurring_period == RecurringPeriod.PER_HOUR: - return self.cores * 4.0/(30 * 24) + self.ram_in_gb * 4.5/(30* 24) - elif recurring_period == RecurringPeriod.PER_YEAR: - return (self.cores * 2.5 + self.ram_in_gb * 3.5) * 12 - else: - raise Exception('Invalid recurring period for VM Product pricing.') + # Default recurring price is PER_MONTH, see uncloud_pay.models.Product. + def recurring_price(self): + return self.cores * 3 + self.ram_in_gb * 4 def __str__(self): return "VM {} ({}): {} cores {} gb ram".format(self.uuid,