forked from uncloud/uncloud
Merge remote-tracking branch 'origin/fnux-stable'
Signed-off-by: Nico Schottelius <nico@nico-notebook.schottelius.org>
This commit is contained in:
commit
a50095f873
49 changed files with 1340 additions and 116 deletions
|
|
@ -6,7 +6,8 @@ from django.contrib.auth import get_user_model
|
|||
# Uncomment if you override model's clean method
|
||||
# from django.core.exceptions import ValidationError
|
||||
|
||||
from uncloud_pay.models import Product
|
||||
from uncloud_pay.models import Product, RecurringPeriod
|
||||
import uncloud_pay.models as pay_models
|
||||
|
||||
STATUS_CHOICES = (
|
||||
('pending', 'Pending'), # Initial state
|
||||
|
|
@ -45,9 +46,31 @@ class VMProduct(Product):
|
|||
VMHost, on_delete=models.CASCADE, editable=False, blank=True, null=True
|
||||
)
|
||||
|
||||
# VM-specific. The name is only intended for customers: it's a pain te
|
||||
# remember IDs (speaking from experience as ungleich customer)!
|
||||
name = models.CharField(max_length=32)
|
||||
cores = models.IntegerField()
|
||||
ram_in_gb = models.FloatField()
|
||||
|
||||
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 * 2
|
||||
elif recurring_period == RecurringPeriod.PER_HOUR:
|
||||
return self.cores * 4.0/(30 * 24) + self.ram_in_gb * 3.0/(30* 24)
|
||||
else:
|
||||
raise Exception('Invalid recurring period for VM Product pricing.')
|
||||
|
||||
@property
|
||||
def description(self):
|
||||
return "Virtual machine '{}': {} core(s), {}GB memory".format(
|
||||
self.name, self.cores, self.ram_in_gb)
|
||||
|
||||
@staticmethod
|
||||
def allowed_recurring_periods():
|
||||
return list(filter(
|
||||
lambda pair: pair[0] in [RecurringPeriod.PER_MONTH, RecurringPeriod.PER_HOUR],
|
||||
RecurringPeriod.choices))
|
||||
|
||||
class VMWithOSProduct(VMProduct):
|
||||
pass
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue