From 4f4a4be8396316df064f4acd8f61a4dc184e3fb0 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sat, 22 Feb 2020 00:50:06 +0100 Subject: [PATCH] good night commit - introducing status --- nicohack202002/uncloud/uncloud_api/models.py | 62 ++++++++++++++------ nicohack202002/uncloud/uncloud_api/views.py | 11 +++- 2 files changed, 51 insertions(+), 22 deletions(-) diff --git a/nicohack202002/uncloud/uncloud_api/models.py b/nicohack202002/uncloud/uncloud_api/models.py index 6df17c4..fafefe6 100644 --- a/nicohack202002/uncloud/uncloud_api/models.py +++ b/nicohack202002/uncloud/uncloud_api/models.py @@ -32,35 +32,59 @@ from django.contrib.auth import get_user_model # Should have a log = ... => 1:n field for most models! class Product(models.Model): - + # override these fields by default description = "" + recurring_period = "not_recurring" - uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) - name = models.CharField(max_length=256) - - recurring_period = models.CharField(max_length=256, - choices = ( - ("per_year", "Per Year"), - ("per_month", "Per Month"), - ("per_week", "Per Week"), - ("per_day", "Per Day"), - ("per_hour", "Per Hour"), - ("not_recurring", "Not recurring") - ), - default="not_recurring" - ) - - # params = [ vmuuid, ... ] - # features -> required as defined + status = models.CharField(max_length=256, + choices = ( + ('pending', 'Pending'), + ('being_created', 'Being created'), + ('created_active', 'Created'), + ('deleted', 'Deleted') + ) def __str__(self): return "{}".format(self.name) class VMSnapshotProduct(Product): - # need to setup recurring_periodd + price_per_gb_ssd = 0.35 + price_per_gb_hdd = 1.5/100 + + sample_ssd = 10 + sample_hdd = 100 + + def recurring_price(self): + return 0 + + def one_time_price(self): + return 0 + + @classmethod + def sample_price(cls): + return cls.sample_ssd * cls.price_per_gb_ssd + cls.sample_hdd * cls.price_per_gb_hdd description = "Create snapshot of a VM" + recurring_period = "monthly" + + @classmethod + def pricing_model(cls): + return """ +Pricing is on monthly basis and storage prices are equivalent to the storage +price in the VM. + +Price per GB SSD is: {} +Price per GB HDD is: {} + + +Sample price for a VM with {} GB SSD and {} GB HDD VM is: {}. +""".format(cls.price_per_gb_ssd, cls.price_per_gb_hdd, + cls.sample_ssd, cls.sample_hdd, cls.sample_price()) + + gb_ssd = models.FloatField() + gb_hdd = models.FloatField() + class Feature(models.Model): diff --git a/nicohack202002/uncloud/uncloud_api/views.py b/nicohack202002/uncloud/uncloud_api/views.py index 8cf76f2..68963ff 100644 --- a/nicohack202002/uncloud/uncloud_api/views.py +++ b/nicohack202002/uncloud/uncloud_api/views.py @@ -61,16 +61,21 @@ import inspect import sys import re +# Next: create /order/ urls +# Next: strip off "Product" at the end class ProductsView(APIView): def get(self, request, format=None): clsmembers = inspect.getmembers(sys.modules['uncloud_api.models'], inspect.isclass) products = [] for name, c in clsmembers: # Include everything that ends in Product, but not Product itself - if re.search(r'.+Product$', name): + m = re.match(r'(?P.+)Product$', name) + if m: products.append({ - 'name': name, - 'description': c.description + 'name': m.group('pname'), + 'description': c.description, + 'recurring_period': c.recurring_period, + 'pricing_model': c.pricing_model() } )