2016-12-20 23:05:20 +00:00
|
|
|
from django.db import models
|
|
|
|
|
2017-02-15 04:34:06 +00:00
|
|
|
|
|
|
|
class BetaAccessVMType(models.Model):
|
|
|
|
ssd = models.IntegerField()
|
|
|
|
ram = models.IntegerField()
|
|
|
|
cpu = models.IntegerField()
|
|
|
|
price = models.FloatField()
|
|
|
|
|
|
|
|
def __str__(self):
|
2017-02-17 03:32:14 +00:00
|
|
|
return "ID: %s - SSD %s - RAM %s - CPU %s - Price %s " % \
|
2017-07-26 17:38:38 +00:00
|
|
|
(self.id, str(self.ssd), self.ram, self.cpu, self.price)
|
2016-12-20 23:05:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
class BetaAccess(models.Model):
|
|
|
|
email = models.CharField(max_length=250)
|
2017-03-31 00:51:15 +00:00
|
|
|
name = models.CharField(max_length=250)
|
2017-07-26 17:38:38 +00:00
|
|
|
|
2017-02-15 04:34:06 +00:00
|
|
|
# vm = models.ForeignKey(BetaAccessVM)
|
2016-12-20 23:05:20 +00:00
|
|
|
|
|
|
|
def __str__(self):
|
2017-02-15 04:34:06 +00:00
|
|
|
vms = self.betaaccessvm_set.all()
|
|
|
|
rep = "Email: %s " % self.email
|
|
|
|
for vm in vms:
|
|
|
|
rep += "(vm:%s - amount:%s) - " % (vm.type.id, vm.amount)
|
|
|
|
return rep
|
|
|
|
|
|
|
|
|
|
|
|
class BetaAccessVM(models.Model):
|
|
|
|
type = models.ForeignKey(BetaAccessVMType)
|
|
|
|
access = models.ForeignKey(BetaAccess)
|
|
|
|
amount = models.IntegerField()
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def create(cls, data):
|
|
|
|
VM_KEY_ID = 0
|
|
|
|
VM_AMOUNT = 1
|
2017-02-17 03:32:14 +00:00
|
|
|
ZERO = 0
|
2017-02-15 04:34:06 +00:00
|
|
|
email = data.get('email')
|
|
|
|
beta_access = BetaAccess.objects.create(email=email)
|
|
|
|
vm_data = [(key, value) for key, value in data.items() if 'vm' in key]
|
2017-02-17 03:32:14 +00:00
|
|
|
created_vms = []
|
2017-02-15 04:34:06 +00:00
|
|
|
for vm in vm_data:
|
2017-02-17 03:32:14 +00:00
|
|
|
if int(vm[VM_AMOUNT]) == ZERO:
|
|
|
|
continue
|
2017-02-15 04:34:06 +00:00
|
|
|
vm_id = vm[VM_KEY_ID].split('-').pop()
|
|
|
|
vm_type = BetaAccessVMType.objects.get(id=vm_id)
|
2017-02-17 03:32:14 +00:00
|
|
|
created_vms.append(cls.objects.create(access=beta_access,
|
|
|
|
amount=vm[VM_AMOUNT], type=vm_type))
|
|
|
|
|
|
|
|
return created_vms
|
2017-07-26 17:38:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
class VMTemplate(models.Model):
|
|
|
|
name = models.CharField(max_length=50)
|
2017-07-26 18:35:12 +00:00
|
|
|
opennebula_vm_template_id = models.IntegerField()
|
2017-07-26 17:38:38 +00:00
|
|
|
|
|
|
|
@classmethod
|
2017-07-26 18:35:12 +00:00
|
|
|
def create(cls, name, opennebula_vm_template_id):
|
2017-08-27 07:49:05 +00:00
|
|
|
vm_template = cls(
|
|
|
|
name=name, opennebula_vm_template_id=opennebula_vm_template_id)
|
2017-07-26 17:38:38 +00:00
|
|
|
return vm_template
|
2017-08-16 22:52:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
class StripePlan(models.Model):
|
|
|
|
"""
|
|
|
|
A model to store Data Center Light's created Stripe plans
|
|
|
|
"""
|
2017-08-21 20:25:45 +00:00
|
|
|
stripe_plan_id = models.CharField(max_length=256, null=True)
|
2017-08-16 22:52:23 +00:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def create(cls, stripe_plan_id):
|
|
|
|
stripe_plan = cls(stripe_plan_id=stripe_plan_id)
|
|
|
|
return stripe_plan
|
2017-08-27 07:49:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ContactUs(models.Model):
|
|
|
|
name = models.CharField(max_length=250)
|
|
|
|
email = models.CharField(max_length=250)
|
|
|
|
message = models.TextField()
|
|
|
|
field = models.DateTimeField(auto_now_add=True)
|