good night commit - introducing status
This commit is contained in:
parent
b1bb6bc314
commit
4f4a4be839
2 changed files with 51 additions and 22 deletions
|
@ -32,35 +32,59 @@ from django.contrib.auth import get_user_model
|
||||||
# Should have a log = ... => 1:n field for most models!
|
# Should have a log = ... => 1:n field for most models!
|
||||||
|
|
||||||
class Product(models.Model):
|
class Product(models.Model):
|
||||||
|
# override these fields by default
|
||||||
description = ""
|
description = ""
|
||||||
|
recurring_period = "not_recurring"
|
||||||
|
|
||||||
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
status = models.CharField(max_length=256,
|
||||||
name = models.CharField(max_length=256)
|
choices = (
|
||||||
|
('pending', 'Pending'),
|
||||||
recurring_period = models.CharField(max_length=256,
|
('being_created', 'Being created'),
|
||||||
choices = (
|
('created_active', 'Created'),
|
||||||
("per_year", "Per Year"),
|
('deleted', 'Deleted')
|
||||||
("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
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "{}".format(self.name)
|
return "{}".format(self.name)
|
||||||
|
|
||||||
|
|
||||||
class VMSnapshotProduct(Product):
|
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"
|
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):
|
class Feature(models.Model):
|
||||||
|
|
|
@ -61,16 +61,21 @@ import inspect
|
||||||
import sys
|
import sys
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
# Next: create /order/<productname> urls
|
||||||
|
# Next: strip off "Product" at the end
|
||||||
class ProductsView(APIView):
|
class ProductsView(APIView):
|
||||||
def get(self, request, format=None):
|
def get(self, request, format=None):
|
||||||
clsmembers = inspect.getmembers(sys.modules['uncloud_api.models'], inspect.isclass)
|
clsmembers = inspect.getmembers(sys.modules['uncloud_api.models'], inspect.isclass)
|
||||||
products = []
|
products = []
|
||||||
for name, c in clsmembers:
|
for name, c in clsmembers:
|
||||||
# Include everything that ends in Product, but not Product itself
|
# Include everything that ends in Product, but not Product itself
|
||||||
if re.search(r'.+Product$', name):
|
m = re.match(r'(?P<pname>.+)Product$', name)
|
||||||
|
if m:
|
||||||
products.append({
|
products.append({
|
||||||
'name': name,
|
'name': m.group('pname'),
|
||||||
'description': c.description
|
'description': c.description,
|
||||||
|
'recurring_period': c.recurring_period,
|
||||||
|
'pricing_model': c.pricing_model()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue