diff --git a/doc/uncloud-manual-2020-08-01.org b/doc/uncloud-manual-2020-08-01.org
index 5a8346c..4a61407 100644
--- a/doc/uncloud-manual-2020-08-01.org
+++ b/doc/uncloud-manual-2020-08-01.org
@@ -46,6 +46,12 @@
old order. The old order stops one second before the new order
starts.
+ If a order has been replaced can be seen by its replaced_by count:
+ #+BEGIN_SRC sh
+>>> Order.objects.get(id=1).replaced_by.count()
+1
+ #+END_SRC
+
** Product and Product Children
- A product describes something a user can buy
- A product inherits from the uncloud_pay.models.Product model to
diff --git a/opennebula/management/commands/opennebula-syncvms.py b/opennebula/management/commands/opennebula-syncvms.py
index 458528b..3c12fa9 100644
--- a/opennebula/management/commands/opennebula-syncvms.py
+++ b/opennebula/management/commands/opennebula-syncvms.py
@@ -1,12 +1,9 @@
import json
-import uncloud.secrets as secrets
-
-
from xmlrpc.client import ServerProxy as RPCClient
-
from django_auth_ldap.backend import LDAPBackend
from django.core.management.base import BaseCommand
+from django.conf import settings
from xmltodict import parse
from opennebula.models import VM as VMModel
@@ -19,9 +16,9 @@ class Command(BaseCommand):
pass
def handle(self, *args, **options):
- with RPCClient(secrets.OPENNEBULA_URL) as rpc_client:
+ with RPCClient(settings.OPENNEBULA_URL) as rpc_client:
success, response, *_ = rpc_client.one.vmpool.infoextended(
- secrets.OPENNEBULA_USER_PASS, -2, -1, -1, -1
+ settings.OPENNEBULA_USER_PASS, -2, -1, -1, -1
)
if success:
vms = json.loads(json.dumps(parse(response)))['VM_POOL']['VM']
diff --git a/opennebula/migrations/0001_initial.py b/opennebula/migrations/0001_initial.py
index 6c1a0e7..0852436 100644
--- a/opennebula/migrations/0001_initial.py
+++ b/opennebula/migrations/0001_initial.py
@@ -1,4 +1,4 @@
-# Generated by Django 3.0.6 on 2020-06-21 12:34
+# Generated by Django 3.0.6 on 2020-08-01 16:38
from django.conf import settings
import django.contrib.postgres.fields.jsonb
@@ -12,15 +12,22 @@ class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
+ ('uncloud_pay', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='VM',
fields=[
+ ('extra_data', django.contrib.postgres.fields.jsonb.JSONField(blank=True, editable=False, null=True)),
+ ('status', models.CharField(choices=[('PENDING', 'Pending'), ('AWAITING_PAYMENT', 'Awaiting payment'), ('BEING_CREATED', 'Being created'), ('SCHEDULED', 'Scheduled'), ('ACTIVE', 'Active'), ('MODIFYING', 'Modifying'), ('DELETED', 'Deleted'), ('DISABLED', 'Disabled'), ('UNUSABLE', 'Unusable')], default='AWAITING_PAYMENT', max_length=32)),
('vmid', models.IntegerField(primary_key=True, serialize=False)),
('data', django.contrib.postgres.fields.jsonb.JSONField()),
- ('owner', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
+ ('order', models.ForeignKey(editable=False, null=True, on_delete=django.db.models.deletion.CASCADE, to='uncloud_pay.Order')),
+ ('owner', models.ForeignKey(editable=False, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
+ options={
+ 'abstract': False,
+ },
),
]
diff --git a/opennebula/migrations/0002_auto_20200801_1203.py b/opennebula/migrations/0002_auto_20200801_1203.py
deleted file mode 100644
index 0be8715..0000000
--- a/opennebula/migrations/0002_auto_20200801_1203.py
+++ /dev/null
@@ -1,38 +0,0 @@
-# Generated by Django 3.0.6 on 2020-08-01 12:03
-
-from django.conf import settings
-import django.contrib.postgres.fields.jsonb
-from django.db import migrations, models
-import django.db.models.deletion
-
-
-class Migration(migrations.Migration):
-
- dependencies = [
- ('uncloud_pay', '0003_auto_20200621_1442'),
- migrations.swappable_dependency(settings.AUTH_USER_MODEL),
- ('opennebula', '0001_initial'),
- ]
-
- operations = [
- migrations.AddField(
- model_name='vm',
- name='extra_data',
- field=django.contrib.postgres.fields.jsonb.JSONField(blank=True, editable=False, null=True),
- ),
- migrations.AddField(
- model_name='vm',
- name='order',
- field=models.ForeignKey(editable=False, null=True, on_delete=django.db.models.deletion.CASCADE, to='uncloud_pay.Order'),
- ),
- migrations.AddField(
- model_name='vm',
- name='status',
- field=models.CharField(choices=[('PENDING', 'Pending'), ('AWAITING_PAYMENT', 'Awaiting payment'), ('BEING_CREATED', 'Being created'), ('SCHEDULED', 'Scheduled'), ('ACTIVE', 'Active'), ('MODIFYING', 'Modifying'), ('DELETED', 'Deleted'), ('DISABLED', 'Disabled'), ('UNUSABLE', 'Unusable')], default='AWAITING_PAYMENT', max_length=32),
- ),
- migrations.AlterField(
- model_name='vm',
- name='owner',
- field=models.ForeignKey(editable=False, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
- ),
- ]
diff --git a/uncloud/templates/uncloud/base.html b/uncloud/templates/uncloud/base.html
new file mode 100644
index 0000000..034fa7c
--- /dev/null
+++ b/uncloud/templates/uncloud/base.html
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+ {% block title %}Welcome to uncloud{% endblock %}
+ {% block header %}{% endblock %}
+
+
+ {% block body %}{% endblock %}
+
+
diff --git a/uncloud_auth/migrations/0001_initial.py b/uncloud_auth/migrations/0001_initial.py
index 6779be2..ebb14ae 100644
--- a/uncloud_auth/migrations/0001_initial.py
+++ b/uncloud_auth/migrations/0001_initial.py
@@ -1,4 +1,4 @@
-# Generated by Django 3.0.6 on 2020-06-21 12:34
+# Generated by Django 3.0.6 on 2020-08-01 16:38
import django.contrib.auth.models
import django.contrib.auth.validators
diff --git a/uncloud_net/migrations/0001_initial.py b/uncloud_net/migrations/0001_initial.py
index 98714c9..7e018b2 100644
--- a/uncloud_net/migrations/0001_initial.py
+++ b/uncloud_net/migrations/0001_initial.py
@@ -1,4 +1,4 @@
-# Generated by Django 3.0.6 on 2020-06-21 12:34
+# Generated by Django 3.0.6 on 2020-08-01 16:38
from django.conf import settings
import django.contrib.postgres.fields.jsonb
diff --git a/uncloud_pay/management/commands/add-opennebula-vm-orders.py b/uncloud_pay/management/commands/add-opennebula-vm-orders.py
new file mode 100644
index 0000000..d96e4c8
--- /dev/null
+++ b/uncloud_pay/management/commands/add-opennebula-vm-orders.py
@@ -0,0 +1,77 @@
+from django.core.management.base import BaseCommand
+from django.contrib.auth import get_user_model
+
+from django.utils import timezone
+from datetime import datetime, timedelta
+
+from uncloud_pay.models import *
+#import opennebula.models as one
+from uncloud_vm.models import *
+
+def vm_price_2020(cpu=1, ram=2, v6only=False):
+ if v6only:
+ discount = 9
+ else:
+ discount = 0
+
+ return cpu*3 + ram*4 - discount
+
+def disk_price_2020(size_in_gb, disk_type):
+ if disk_type == VMDiskType.CEPH_SSD:
+ price = 3.5/10
+ elif disk_type == VMDiskType.CEPH_HDD:
+ price = 1.5/100
+ else:
+ raise Exception("not yet defined price")
+
+ return size_in_gb * price
+
+class Command(BaseCommand):
+ help = 'Adding VMs / creating orders for user'
+
+ def add_arguments(self, parser):
+ parser.add_argument('--username', type=str, required=True)
+
+ def handle(self, *args, **options):
+ user = get_user_model().objects.get(username=options['username'])
+ addr, created = BillingAddress.objects.get_or_create(
+ owner=user,
+ active=True,
+ defaults={'organization': 'Undefined organisation',
+ 'name': 'Undefined name',
+ 'street': 'Undefined Street',
+ 'city': 'Undefined city',
+ 'postal_code': '8750',
+ 'country': 'CH',
+ 'active': True
+ }
+ )
+
+
+ orders = []
+
+ # 25206
+ vm25206 = VMProduct.objects.create(name="OpenNebula 25206",
+ cores=1,
+ ram_in_gb=4,
+ owner=user)
+
+ vm25206_ssd = VMDiskProduct.objects.create(vm=vm25206,
+ owner=user,
+ size_in_gb=30)
+
+ order_vm_25206 = Order.objects.create(owner=user,
+ billing_address=addr,
+ starting_date=timezone.make_aware(datetime.datetime(2020,3,3)),
+ recurring_period=RecurringPeriod.PER_30D,
+ recurring_price = vm_price_2020(cpu=1, ram=4) / 2,
+ description = "VM %s" % vm25206
+ )
+
+ order_vm_25206_ssd = Order.objects.create(owner=user,
+ billing_address=addr,
+ starting_date=timezone.make_aware(datetime.datetime(2020,3,3)),
+ recurring_period=RecurringPeriod.PER_30D,
+ recurring_price = disk_price_2020(30, VMDiskType.CEPH_SSD) / 2,
+ description = vm25206_ssd
+ )
diff --git a/uncloud_pay/migrations/0001_initial.py b/uncloud_pay/migrations/0001_initial.py
index 0be384a..439b3d0 100644
--- a/uncloud_pay/migrations/0001_initial.py
+++ b/uncloud_pay/migrations/0001_initial.py
@@ -1,4 +1,4 @@
-# Generated by Django 3.0.6 on 2020-06-21 12:34
+# Generated by Django 3.0.6 on 2020-08-01 16:38
from django.conf import settings
import django.core.validators
@@ -23,9 +23,9 @@ class Migration(migrations.Migration):
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('creation_date', models.DateTimeField(auto_now_add=True)),
- ('starting_date', models.DateTimeField()),
- ('ending_date', models.DateTimeField()),
- ('due_date', models.DateField()),
+ ('starting_date', models.DateTimeField(default=uncloud_pay.models.start_of_this_month)),
+ ('ending_date', models.DateTimeField(default=uncloud_pay.models.end_of_this_month)),
+ ('due_date', models.DateField(default=uncloud_pay.models.default_payment_delay)),
('valid', models.BooleanField(default=True)),
],
),
@@ -53,10 +53,12 @@ class Migration(migrations.Migration):
('starting_date', models.DateTimeField(default=django.utils.timezone.now)),
('ending_date', models.DateTimeField(blank=True, null=True)),
('recurring_period', models.IntegerField(choices=[(31536000, 'Per 365 days'), (2592000, 'Per 30 days'), (604800, 'Per Week'), (86400, 'Per Day'), (3600, 'Per Hour'), (60, 'Per Minute'), (1, 'Per Second'), (0, 'Onetime')], default=2592000)),
+ ('one_time_price', models.DecimalField(decimal_places=2, default=0.0, max_digits=10, validators=[django.core.validators.MinValueValidator(0)])),
+ ('recurring_price', models.DecimalField(decimal_places=2, default=0.0, max_digits=10, validators=[django.core.validators.MinValueValidator(0)])),
('billing_address', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='uncloud_pay.BillingAddress')),
('depends_on', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='parent_of', to='uncloud_pay.Order')),
('owner', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
- ('replaced_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='supersede', to='uncloud_pay.Order')),
+ ('replaces', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='replaced_by', to='uncloud_pay.Order')),
],
),
migrations.CreateModel(
@@ -115,7 +117,7 @@ class Migration(migrations.Migration):
name='BillRecord',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
- ('usage_count', models.IntegerField(default=1)),
+ ('quantity', models.IntegerField(default=1)),
('creation_date', models.DateTimeField(auto_now_add=True)),
('starting_date', models.DateTimeField()),
('ending_date', models.DateTimeField()),
@@ -137,4 +139,8 @@ class Migration(migrations.Migration):
model_name='billingaddress',
constraint=models.UniqueConstraint(condition=models.Q(active=True), fields=('owner',), name='one_active_billing_address_per_user'),
),
+ migrations.AddConstraint(
+ model_name='bill',
+ constraint=models.UniqueConstraint(fields=('owner', 'starting_date', 'ending_date'), name='one_bill_per_month_per_user'),
+ ),
]
diff --git a/uncloud_pay/migrations/0002_auto_20200621_1335.py b/uncloud_pay/migrations/0002_auto_20200621_1335.py
deleted file mode 100644
index c4a6e64..0000000
--- a/uncloud_pay/migrations/0002_auto_20200621_1335.py
+++ /dev/null
@@ -1,33 +0,0 @@
-# Generated by Django 3.0.6 on 2020-06-21 13:35
-
-from django.db import migrations, models
-import uncloud_pay.models
-
-
-class Migration(migrations.Migration):
-
- dependencies = [
- ('uncloud_pay', '0001_initial'),
- ]
-
- operations = [
- migrations.AlterField(
- model_name='bill',
- name='due_date',
- field=models.DateField(default=uncloud_pay.models.default_payment_delay),
- ),
- migrations.AlterField(
- model_name='bill',
- name='ending_date',
- field=models.DateTimeField(default=uncloud_pay.models.end_of_this_month),
- ),
- migrations.AlterField(
- model_name='bill',
- name='starting_date',
- field=models.DateTimeField(default=uncloud_pay.models.start_of_this_month),
- ),
- migrations.AddConstraint(
- model_name='bill',
- constraint=models.UniqueConstraint(fields=('owner', 'starting_date', 'ending_date'), name='one_bill_per_month_per_user'),
- ),
- ]
diff --git a/uncloud_pay/migrations/0003_auto_20200621_1442.py b/uncloud_pay/migrations/0003_auto_20200621_1442.py
deleted file mode 100644
index 89e49cd..0000000
--- a/uncloud_pay/migrations/0003_auto_20200621_1442.py
+++ /dev/null
@@ -1,18 +0,0 @@
-# Generated by Django 3.0.6 on 2020-06-21 14:42
-
-from django.db import migrations
-
-
-class Migration(migrations.Migration):
-
- dependencies = [
- ('uncloud_pay', '0002_auto_20200621_1335'),
- ]
-
- operations = [
- migrations.RenameField(
- model_name='billrecord',
- old_name='usage_count',
- new_name='quantity',
- ),
- ]
diff --git a/uncloud_pay/migrations/0004_auto_20200801_1604.py b/uncloud_pay/migrations/0004_auto_20200801_1604.py
deleted file mode 100644
index 9b87bd6..0000000
--- a/uncloud_pay/migrations/0004_auto_20200801_1604.py
+++ /dev/null
@@ -1,23 +0,0 @@
-# Generated by Django 3.0.6 on 2020-08-01 16:04
-
-from django.db import migrations, models
-import django.db.models.deletion
-
-
-class Migration(migrations.Migration):
-
- dependencies = [
- ('uncloud_pay', '0003_auto_20200621_1442'),
- ]
-
- operations = [
- migrations.RemoveField(
- model_name='order',
- name='replaced_by',
- ),
- migrations.AddField(
- model_name='order',
- name='replaces',
- field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='replaced_by', to='uncloud_pay.Order'),
- ),
- ]
diff --git a/uncloud_pay/migrations/0005_auto_20200801_1626.py b/uncloud_pay/migrations/0005_auto_20200801_1626.py
deleted file mode 100644
index 323a4cf..0000000
--- a/uncloud_pay/migrations/0005_auto_20200801_1626.py
+++ /dev/null
@@ -1,24 +0,0 @@
-# Generated by Django 3.0.6 on 2020-08-01 16:26
-
-import django.core.validators
-from django.db import migrations, models
-
-
-class Migration(migrations.Migration):
-
- dependencies = [
- ('uncloud_pay', '0004_auto_20200801_1604'),
- ]
-
- operations = [
- migrations.AddField(
- model_name='order',
- name='one_time_price',
- field=models.DecimalField(decimal_places=2, default=0.0, max_digits=10, validators=[django.core.validators.MinValueValidator(0)]),
- ),
- migrations.AddField(
- model_name='order',
- name='recurring_price',
- field=models.DecimalField(decimal_places=2, default=0.0, max_digits=10, validators=[django.core.validators.MinValueValidator(0)]),
- ),
- ]
diff --git a/uncloud_pay/models.py b/uncloud_pay/models.py
index 844124e..122b806 100644
--- a/uncloud_pay/models.py
+++ b/uncloud_pay/models.py
@@ -398,7 +398,7 @@ class Order(models.Model):
def records(self):
return OrderRecord.objects.filter(order=self)
- # these are reald fields!!!
+ # these are real fields!!!
# @property
# def one_time_price(self):
# return reduce(lambda acc, record: acc + record.one_time_price, self.records, 0)
diff --git a/uncloud_service/migrations/0001_initial.py b/uncloud_service/migrations/0001_initial.py
index d718327..96fb3c0 100644
--- a/uncloud_service/migrations/0001_initial.py
+++ b/uncloud_service/migrations/0001_initial.py
@@ -1,4 +1,4 @@
-# Generated by Django 3.0.6 on 2020-06-21 12:34
+# Generated by Django 3.0.6 on 2020-08-01 16:38
from django.conf import settings
import django.contrib.postgres.fields.jsonb
@@ -12,9 +12,9 @@ class Migration(migrations.Migration):
initial = True
dependencies = [
- ('uncloud_pay', '0001_initial'),
('uncloud_vm', '__first__'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
+ ('uncloud_pay', '0001_initial'),
]
operations = [
diff --git a/uncloud_service/models.py b/uncloud_service/models.py
index a9cea0b..d067a23 100644
--- a/uncloud_service/models.py
+++ b/uncloud_service/models.py
@@ -1,5 +1,3 @@
-import uuid
-
from django.db import models
from uncloud_pay.models import Product, RecurringPeriod, AMOUNT_MAX_DIGITS, AMOUNT_DECIMALS
from uncloud_vm.models import VMProduct, VMDiskImageProduct
@@ -23,7 +21,8 @@ class MatrixServiceProduct(Product):
@staticmethod
def base_image():
# TODO: find a way to safely reference debian 10 image.
- return VMDiskImageProduct.objects.get(uuid="93e564c5-adb3-4741-941f-718f76075f02")
+#e return VMDiskImageProduct.objects.get(uuid="93e564c5-adb3-4741-941f-718f76075f02")
+ return False
@staticmethod
def allowed_recurring_periods():
diff --git a/uncloud_service/serializers.py b/uncloud_service/serializers.py
index 6666a15..8dbd547 100644
--- a/uncloud_service/serializers.py
+++ b/uncloud_service/serializers.py
@@ -12,9 +12,9 @@ class MatrixServiceProductSerializer(serializers.ModelSerializer):
class Meta:
model = MatrixServiceProduct
- fields = ['uuid', 'order', 'owner', 'status', 'vm', 'domain',
+ fields = ['order', 'owner', 'status', 'vm', 'domain',
'recurring_period']
- read_only_fields = ['uuid', 'order', 'owner', 'status']
+ read_only_fields = ['order', 'owner', 'status']
class OrderMatrixServiceProductSerializer(MatrixServiceProductSerializer):
recurring_period = serializers.ChoiceField(
@@ -37,9 +37,9 @@ class OrderMatrixServiceProductSerializer(MatrixServiceProductSerializer):
class GenericServiceProductSerializer(serializers.ModelSerializer):
class Meta:
model = GenericServiceProduct
- fields = ['uuid', 'order', 'owner', 'status', 'custom_recurring_price',
+ fields = ['order', 'owner', 'status', 'custom_recurring_price',
'custom_description', 'custom_one_time_price']
- read_only_fields = ['uuid', 'order', 'owner', 'status']
+ read_only_fields = [ 'owner', 'status']
class OrderGenericServiceProductSerializer(GenericServiceProductSerializer):
recurring_period = serializers.ChoiceField(
diff --git a/uncloud_vm/admin.py b/uncloud_vm/admin.py
index 8c38f3f..9fbcb82 100644
--- a/uncloud_vm/admin.py
+++ b/uncloud_vm/admin.py
@@ -1,3 +1,7 @@
from django.contrib import admin
# Register your models here.
+from uncloud_vm.models import *
+
+admin.site.register(VMProduct)
+admin.site.register(VMDiskProduct)
diff --git a/uncloud_vm/migrations/0001_initial.py b/uncloud_vm/migrations/0001_initial.py
index 675a286..e104129 100644
--- a/uncloud_vm/migrations/0001_initial.py
+++ b/uncloud_vm/migrations/0001_initial.py
@@ -1,10 +1,9 @@
-# Generated by Django 3.0.6 on 2020-06-21 12:34
+# Generated by Django 3.0.6 on 2020-08-01 16:38
from django.conf import settings
import django.contrib.postgres.fields.jsonb
from django.db import migrations, models
import django.db.models.deletion
-import uuid
class Migration(migrations.Migration):
@@ -12,16 +11,16 @@ class Migration(migrations.Migration):
initial = True
dependencies = [
- ('uncloud_pay', '0001_initial'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
+ ('uncloud_pay', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='VMCluster',
fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('extra_data', django.contrib.postgres.fields.jsonb.JSONField(blank=True, editable=False, null=True)),
- ('uuid', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('name', models.CharField(max_length=128, unique=True)),
],
options={
@@ -31,8 +30,8 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name='VMDiskImageProduct',
fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('extra_data', django.contrib.postgres.fields.jsonb.JSONField(blank=True, editable=False, null=True)),
- ('uuid', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('name', models.CharField(max_length=256)),
('is_os_image', models.BooleanField(default=False)),
('is_public', models.BooleanField(default=False, editable=False)),
@@ -51,8 +50,8 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name='VMHost',
fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('extra_data', django.contrib.postgres.fields.jsonb.JSONField(blank=True, editable=False, null=True)),
- ('uuid', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('hostname', models.CharField(max_length=253, unique=True)),
('physical_cores', models.IntegerField(default=0)),
('usable_cores', models.IntegerField(default=0)),
@@ -114,7 +113,8 @@ class Migration(migrations.Migration):
('extra_data', django.contrib.postgres.fields.jsonb.JSONField(blank=True, editable=False, null=True)),
('status', models.CharField(choices=[('PENDING', 'Pending'), ('AWAITING_PAYMENT', 'Awaiting payment'), ('BEING_CREATED', 'Being created'), ('SCHEDULED', 'Scheduled'), ('ACTIVE', 'Active'), ('MODIFYING', 'Modifying'), ('DELETED', 'Deleted'), ('DISABLED', 'Disabled'), ('UNUSABLE', 'Unusable')], default='AWAITING_PAYMENT', max_length=32)),
('size_in_gb', models.FloatField(blank=True)),
- ('image', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='uncloud_vm.VMDiskImageProduct')),
+ ('disk_type', models.CharField(choices=[('ceph/ssd', 'Ceph Ssd'), ('ceph/hdd', 'Ceph Hdd'), ('local/ssd', 'Local Ssd'), ('local/hdd', 'Local Hdd')], default='ceph/ssd', max_length=20)),
+ ('image', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='uncloud_vm.VMDiskImageProduct')),
('order', models.ForeignKey(editable=False, null=True, on_delete=django.db.models.deletion.CASCADE, to='uncloud_pay.Order')),
('owner', models.ForeignKey(editable=False, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
('vm', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='uncloud_vm.VMProduct')),
diff --git a/uncloud_vm/migrations/0002_vmdiskproduct_disk_type.py b/uncloud_vm/migrations/0002_vmdiskproduct_disk_type.py
deleted file mode 100644
index 8dba16d..0000000
--- a/uncloud_vm/migrations/0002_vmdiskproduct_disk_type.py
+++ /dev/null
@@ -1,18 +0,0 @@
-# Generated by Django 3.0.6 on 2020-08-01 14:02
-
-from django.db import migrations, models
-
-
-class Migration(migrations.Migration):
-
- dependencies = [
- ('uncloud_vm', '0001_initial'),
- ]
-
- operations = [
- migrations.AddField(
- model_name='vmdiskproduct',
- name='disk_type',
- field=models.CharField(choices=[('ceph/ssd', 'Ceph Ssd'), ('ceph/hdd', 'Ceph Hdd'), ('local/ssd', 'Local Ssd'), ('local/hdd', 'Local Hdd')], default='ceph/ssd', max_length=20),
- ),
- ]
diff --git a/uncloud_vm/models.py b/uncloud_vm/models.py
index 3eb46b7..89ee431 100644
--- a/uncloud_vm/models.py
+++ b/uncloud_vm/models.py
@@ -1,5 +1,3 @@
-import uuid
-
from django.db import models
from django.contrib.auth import get_user_model
@@ -10,13 +8,9 @@ import uncloud_pay.models as pay_models
import uncloud_storage.models
class VMCluster(UncloudModel):
- uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
name = models.CharField(max_length=128, unique=True)
-
class VMHost(UncloudModel):
- uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
-
# 253 is the maximum DNS name length
hostname = models.CharField(max_length=253, unique=True)
@@ -132,7 +126,7 @@ class VMDiskImageProduct(UncloudModel):
)
def __str__(self):
- return "VMDiskImage {} ({}): {} gb".format(self.uuid,
+ return "VMDiskImage {} ({}): {} gb".format(self.id,
self.name,
self.size_in_gb)
diff --git a/uncloud_vm/serializers.py b/uncloud_vm/serializers.py
index 19fb872..5032ad4 100644
--- a/uncloud_vm/serializers.py
+++ b/uncloud_vm/serializers.py
@@ -67,7 +67,7 @@ class VMSnapshotProductSerializer(serializers.ModelSerializer):
disks = VMDiskProduct.objects.filter(vm=value)
if len(disks) == 0:
- raise serializers.ValidationError("VM {} does not have any disks, cannot snapshot".format(value.uuid))
+ raise serializers.ValidationError("VM {} does not have any disks, cannot snapshot".format(value.id))
return value
@@ -96,9 +96,9 @@ class VMProductSerializer(serializers.ModelSerializer):
class Meta:
model = VMWithOSProduct
- fields = ['uuid', 'order', 'owner', 'status', 'name', 'cores',
+ fields = ['order', 'owner', 'status', 'name', 'cores',
'ram_in_gb', 'primary_disk', 'snapshots', 'disks', 'extra_data']
- read_only_fields = ['uuid', 'order', 'owner', 'status']
+ read_only_fields = ['order', 'owner', 'status']
class OrderVMProductSerializer(VMProductSerializer):
recurring_period = serializers.ChoiceField(
@@ -119,7 +119,7 @@ class NicoVMProductSerializer(serializers.ModelSerializer):
class Meta:
model = VMProduct
- read_only_fields = ['uuid', 'order', 'owner', 'status',
+ read_only_fields = ['order', 'owner', 'status',
'vmhost', 'vmcluster', 'snapshots',
'extra_data' ]
fields = read_only_fields + [ 'name',