forked from uncloud/uncloud
114 lines
3.8 KiB
Python
114 lines
3.8 KiB
Python
|
from django.db import models
|
||
|
from django.contrib.auth import get_user_model
|
||
|
|
||
|
# 1st mixin: owner alike?
|
||
|
# 2nd: time frames
|
||
|
|
||
|
|
||
|
class Nextcloudv1(models.Model):
|
||
|
name = models.CharField(max_length=128, unique=True)
|
||
|
|
||
|
owner = models.ForeignKey(
|
||
|
get_user_model(), on_delete=models.CASCADE, editable=False
|
||
|
)
|
||
|
|
||
|
domain = models.CharField(max_length=253)
|
||
|
|
||
|
cpu_cores = models.FloatField(null=True, blank=True)
|
||
|
ram_in_gb = models.FloatField(null=True, blank=True)
|
||
|
storage_in_gb = models.FloatField(null=True, blank=True)
|
||
|
|
||
|
|
||
|
|
||
|
def __str__(self):
|
||
|
return f"Nextcloud {domain}: {cores}C {ram_in_gb}GB RAM {storage} GB storage from {owner}"
|
||
|
|
||
|
class Order(models.Model):
|
||
|
# name = models.CharField(max_length=128, unique=True)
|
||
|
|
||
|
owner = models.ForeignKey(
|
||
|
get_user_model(), on_delete=models.CASCADE, editable=False
|
||
|
)
|
||
|
|
||
|
creation_date = models.DateTimeField(auto_now_add=True)
|
||
|
starting_date = models.DateTimeField(default=timezone.now)
|
||
|
ending_date = models.DateTimeField(blank=True, null=True)
|
||
|
|
||
|
product = models.ForeignKey(Product, on_delete=models.CASCADE)
|
||
|
resourceconfigs = models.ManyToManyField(ResourceConfig)
|
||
|
textconfigs = models.ManyToManyField(ResourceConfig)
|
||
|
|
||
|
class Product(models.Model):
|
||
|
"""
|
||
|
Describes a product a user can buy, its pricings and its configurations
|
||
|
"""
|
||
|
|
||
|
name = models.CharField(max_length=128, unique=True) # Nextcloud, Matrix, etc.
|
||
|
|
||
|
textconfig = models.ManyToManyField(ProductTextConfiguration)
|
||
|
textfieldconfig = models.ManyToManyField(ProductTextFieldConfiguration)
|
||
|
|
||
|
timeframes = models.ManyToManyField(TimeFrame)
|
||
|
resources = models.ManyToManyField(Resource)
|
||
|
|
||
|
class Resource(models.Model):
|
||
|
name = models.CharField(max_length=128, unique=True) # CPU, RAM
|
||
|
unit = models.CharField(max_length=128, unique=True) # Count, GB
|
||
|
minimum_units = models.FloatField(null=True, blank=True) # might have min
|
||
|
maximum_units = models.FloatField(null=True, blank=True) # might have max
|
||
|
step_size = models.FloatField(default=1, null=True, blank=True) # might/must step size
|
||
|
|
||
|
timeframe = models.ForeignKey(TimeFrame, on_delete=models.CASCADE)
|
||
|
price = models.FloatField() # Per unit and per time frame
|
||
|
|
||
|
class ResourceConfig(models.Model):
|
||
|
"""
|
||
|
Describes an actual setting of a resource
|
||
|
"""
|
||
|
value = models.FloatField()
|
||
|
resource = models.ForeignKey(Resource, on_delete=models.CASCADE)
|
||
|
|
||
|
|
||
|
class ProductTextConfiguration(models.Model):
|
||
|
name = models.CharField(max_length=128, unique=True) # Domain, etc.
|
||
|
|
||
|
class ProductTextFieldConfiguration(models.Model):
|
||
|
name = models.CharField(max_length=128, unique=True) # homeserver.Yaml, etc.
|
||
|
|
||
|
class ProductTextConfig(models.Model):
|
||
|
"""
|
||
|
Describes an actual setting of a resource
|
||
|
"""
|
||
|
value = models.CharField(max_length=256)
|
||
|
config = models.ForeignKey(ProductTextConfiguration, on_delete=models.CASCADE)
|
||
|
|
||
|
class ProductTextFieldConfig(models.Model):
|
||
|
"""
|
||
|
Describes an actual setting of a resource
|
||
|
"""
|
||
|
value = models.TextField()
|
||
|
config = models.ForeignKey(ProductTextFieldConfiguration, on_delete=models.CASCADE)
|
||
|
|
||
|
class TimeFrame(models.Model):
|
||
|
name = models.CharField(max_length=128, unique=True)
|
||
|
duration_in_seconds = models.IntegerField(null=True, blank=True)
|
||
|
|
||
|
# 3600
|
||
|
# 86400
|
||
|
# 30*86400
|
||
|
|
||
|
# class Nextcloudv2(Product):
|
||
|
# domain = models.CharField(max_length=253)
|
||
|
|
||
|
# def __str__(self):
|
||
|
# return f"Nextcloud {domain} {owner}"
|
||
|
|
||
|
# class ProductPricing(models.Model):
|
||
|
# """
|
||
|
# Defines the allowed time frames and the available resources
|
||
|
# """
|
||
|
|
||
|
# name = models.CharField(max_length=128, unique=True) # cpu 2022, ipv4 2022
|
||
|
# timeframes = models.ManyToManyField(TimeFrame)
|
||
|
# resources = models.ManyToManyField(Resource)
|