# Copyright © 2022 Aravinth Manivannan # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . from django.db import models from django.contrib.auth.models import User from django.utils.http import urlencode from django.urls import reverse class InstanceConfiguration(models.Model): ID = models.AutoField(primary_key=True) name = models.CharField( "Name of this configuration", unique=True, max_length=32, ) rent = models.FloatField("Monthly rent of instance in Euros", null=False) ram = models.FloatField( "The amount of RAM an instance will have", null=False, ) cpu = models.IntegerField( "The amount of CPU an instance will have", null=False, ) storage = models.FloatField( "The amount of storage an instance will have", null=False, ) created_at = models.DateTimeField(auto_now_add=True, blank=True) def __str__(self): return f"{self.name}" class Meta: constraints = [ models.UniqueConstraint( fields=["ram", "cpu", "storage"], name="no_repeat_config" ) ] class Instance(models.Model): """ Hostea instances """ owned_by = models.ForeignKey(User, on_delete=models.CASCADE) ID = models.AutoField(primary_key=True) name = models.CharField( "Name of this Instance. Also Serves as subdomain", unique=True, max_length=200, ) configuration_id = models.ForeignKey( InstanceConfiguration, on_delete=models.PROTECT ) created_at = models.DateTimeField(auto_now_add=True, blank=True) def __str__(self): return f"{self.owned_by}'s instance '{self.name}'"