forked from uncloud/uncloud
99 lines
3 KiB
Python
99 lines
3 KiB
Python
import uuid
|
|
|
|
from django.db import models
|
|
from django.contrib.auth import get_user_model
|
|
|
|
# Product in DB vs. product in code
|
|
# DB:
|
|
# - need to define params (+param types) in db -> messy?
|
|
# - get /products/ is easy / automatic
|
|
#
|
|
# code
|
|
# - can have serializer/verification of fields easily in DRF
|
|
# - can have per product side effects / extra code running
|
|
# - might (??) make features easier??
|
|
# - how to setup / query the recurring period (?)
|
|
# - could get products list via getattr() + re ...Product() classes
|
|
# -> this could include the url for ordering => /order/vm_snapshot (params)
|
|
# ---> this would work with urlpatterns
|
|
|
|
# Combination: create specific product in DB (?)
|
|
# - a table per product (?) with 1 entry?
|
|
|
|
# Orders
|
|
# define state in DB
|
|
# select a price from a product => product might change, order stays
|
|
# params:
|
|
# - the product uuid or name (?) => productuuid
|
|
# - the product parameters => for each feature
|
|
#
|
|
|
|
# logs
|
|
# Should have a log = ... => 1:n field for most models!
|
|
|
|
class Product(models.Model):
|
|
|
|
description = ""
|
|
|
|
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
|
|
|
|
def __str__(self):
|
|
return "{}".format(self.name)
|
|
|
|
|
|
class VMSnapshotProduct(Product):
|
|
# need to setup recurring_periodd
|
|
|
|
description = "Create snapshot of a VM"
|
|
|
|
|
|
class Feature(models.Model):
|
|
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
|
name = models.CharField(max_length=256)
|
|
|
|
recurring_price = models.FloatField(default=0)
|
|
one_time_price = models.FloatField()
|
|
|
|
product = models.ForeignKey(Product, on_delete=models.CASCADE)
|
|
|
|
# params for "cpu": cpu_count -> int
|
|
# each feature can only have one parameters
|
|
# could call this "value" and set whether it is user usable
|
|
# has_value = True/False
|
|
# value = string -> int (?)
|
|
# value_int
|
|
# value_str
|
|
# value_float
|
|
|
|
def __str__(self):
|
|
return "'{}' - '{}'".format(self.product, self.name)
|
|
|
|
|
|
class Order(models.Model):
|
|
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
|
|
|
owner = models.ForeignKey(get_user_model(),
|
|
on_delete=models.CASCADE)
|
|
|
|
product = models.ForeignKey(Product,
|
|
on_delete=models.CASCADE)
|
|
|
|
|
|
class VMSnapshotOrder(Order):
|
|
pass
|