2022-06-17 15:03:48 +00:00
|
|
|
# Copyright © 2022 Aravinth Manivannan <realaravinth@batsense.net>
|
|
|
|
#
|
|
|
|
# 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 <http://www.gnu.org/licenses/>.
|
|
|
|
|
2022-06-17 10:33:13 +00:00
|
|
|
from django.db import models
|
2022-06-17 15:03:48 +00:00
|
|
|
from django.contrib.auth.models import User
|
|
|
|
from django.utils.http import urlencode
|
|
|
|
from django.urls import reverse
|
|
|
|
|
2022-06-19 15:31:12 +00:00
|
|
|
|
2022-06-17 15:03:48 +00:00
|
|
|
class InstanceConfiguration(models.Model):
|
|
|
|
ID = models.AutoField(primary_key=True)
|
|
|
|
name = models.CharField(
|
|
|
|
"Name of this configuration",
|
|
|
|
unique=True,
|
|
|
|
max_length=32,
|
|
|
|
)
|
2022-06-17 18:25:58 +00:00
|
|
|
rent = models.FloatField("Monthly rent of instance in Euros", null=False)
|
2022-06-17 15:03:48 +00:00
|
|
|
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}"
|
2022-06-17 10:33:13 +00:00
|
|
|
|
2022-06-17 15:03:48 +00:00
|
|
|
class Meta:
|
|
|
|
constraints = [
|
|
|
|
models.UniqueConstraint(
|
|
|
|
fields=["ram", "cpu", "storage"], name="no_repeat_config"
|
|
|
|
)
|
|
|
|
]
|
2022-06-17 17:58:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Instance(models.Model):
|
|
|
|
"""
|
|
|
|
Hostea instances
|
|
|
|
"""
|
|
|
|
|
2022-06-18 16:24:53 +00:00
|
|
|
owned_by = models.ForeignKey(User, on_delete=models.CASCADE)
|
2022-06-17 17:58:51 +00:00
|
|
|
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}'"
|