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!
|
||||
|
||||
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,
|
||||
status = 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"
|
||||
('pending', 'Pending'),
|
||||
('being_created', 'Being created'),
|
||||
('created_active', 'Created'),
|
||||
('deleted', 'Deleted')
|
||||
)
|
||||
|
||||
# params = [ vmuuid, ... ]
|
||||
# features -> required as defined
|
||||
|
||||
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):
|
||||
|
|
|
@ -61,16 +61,21 @@ import inspect
|
|||
import sys
|
||||
import re
|
||||
|
||||
# Next: create /order/<productname> 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<pname>.+)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()
|
||||
}
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in a new issue