1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-03-23 11:04:49 +00:00

Added V2 from scratch

This commit is contained in:
retspen 2018-09-23 13:17:48 +03:00
parent 5c2232f4e8
commit 6c2925a35d
478 changed files with 21437 additions and 134206 deletions

View file

3
backend/flavor/admin.py Normal file
View file

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

5
backend/flavor/apps.py Normal file
View file

@ -0,0 +1,5 @@
from django.apps import AppConfig
class FlavorConfig(AppConfig):
name = 'flavor'

View file

@ -0,0 +1,61 @@
# Generated by Django 2.0.8 on 2018-09-22 07:20
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion
import re
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Image',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('slug', models.SlugField(max_length=200, validators=[django.core.validators.RegexValidator(re.compile('^[-a-zA-Z0-9_]+\\Z'), "Enter a valid 'slug' consisting of letters, numbers, underscores or hyphens.", 'invalid')])),
('name', models.CharField(max_length=255)),
('url', models.URLField()),
('md5sum', models.CharField(max_length=50)),
('is_active', models.BooleanField(default=False)),
('created_at', models.DateTimeField(auto_now_add=True)),
('is_deleted', models.BooleanField(default=False)),
('deleted_at', models.DateTimeField(blank=True, null=True)),
],
options={
'verbose_name': 'Instance Image',
'verbose_name_plural': 'Instance Images',
'ordering': ['-id'],
},
),
migrations.CreateModel(
name='Size',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('slug', models.CharField(max_length=200, validators=[django.core.validators.RegexValidator(re.compile('^[-a-zA-Z0-9_]+\\Z'), "Enter a valid 'slug' consisting of letters, numbers, underscores or hyphens.", 'invalid')])),
('name', models.CharField(blank=True, max_length=255)),
('cpu', models.IntegerField(default=1)),
('disk_bytes', models.BigIntegerField(default=21474836480)),
('memory_bytes', models.BigIntegerField(default=536870912)),
('is_active', models.BooleanField(default=False)),
('created_at', models.DateTimeField(auto_now_add=True)),
('is_deleted', models.BooleanField(default=False)),
('deleted_at', models.DateTimeField(blank=True, null=True)),
],
options={
'verbose_name': 'Instance Size',
'verbose_name_plural': 'Instance Sizes',
'ordering': ['-id'],
},
),
migrations.AddField(
model_name='image',
name='required_size',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='flavor.Size'),
),
]

View file

111
backend/flavor/models.py Normal file
View file

@ -0,0 +1,111 @@
from django.db import models
from django.core.validators import validate_slug
class Size(models.Model):
slug = models.CharField(
max_length=200,
validators=[validate_slug],
)
name = models.CharField(
max_length=255,
blank=True,
)
cpu = models.IntegerField(
default=1,
)
disk_bytes = models.BigIntegerField(
default=21474836480,
)
memory_bytes = models.BigIntegerField(
default=536870912,
)
is_active = models.BooleanField(
default=False,
)
created_at = models.DateTimeField(
auto_now_add=True,
)
is_deleted = models.BooleanField(
default=False,
)
deleted_at = models.DateTimeField(
blank=True,
null=True,
)
class Meta:
ordering = ['-id']
verbose_name = "Instance Size"
verbose_name_plural = "Instance Sizes"
def __unicode__(self):
return self.name
def save(self):
if self.ram < 1 * (1024 ** 2):
self.ram = self.ram * (1024 ** 2)
if self.disk < 1 * (1024 ** 3):
self.disk = self.disk * (1024 ** 3)
super(Size, self).save()
class Image(models.Model):
slug = models.SlugField(
max_length=200,
validators=[validate_slug],
)
name = models.CharField(
max_length=255,
)
url = models.URLField(
max_length=200,
)
md5sum = models.CharField(
max_length=50,
)
is_active = models.BooleanField(
default=False,
)
created_at = models.DateTimeField(
auto_now_add=True,
)
is_deleted = models.BooleanField(
default=False,
)
deleted_at = models.DateTimeField(
blank=True,
null=True,
)
required_size = models.ForeignKey(
Size,
blank=True,
null=True,
on_delete=models.CASCADE,
)
class Meta:
ordering = ['-id']
verbose_name = "Instance Image"
verbose_name_plural = "Instance Images"
def __unicode__(self):
return self.name

3
backend/flavor/tests.py Normal file
View file

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

3
backend/flavor/views.py Normal file
View file

@ -0,0 +1,3 @@
from django.shortcuts import render
# Create your views here.