From bd6008462d9eb6823f9db90ed8ee895d474cb1a0 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 27 Feb 2020 15:29:05 +0100 Subject: [PATCH 1/3] add template for uncloud_net Signed-off-by: Nico Schottelius --- uncloud/uncloud_net/__init__.py | 0 uncloud/uncloud_net/admin.py | 3 +++ uncloud/uncloud_net/apps.py | 5 +++++ uncloud/uncloud_net/migrations/__init__.py | 0 uncloud/uncloud_net/models.py | 3 +++ uncloud/uncloud_net/tests.py | 3 +++ uncloud/uncloud_net/views.py | 3 +++ 7 files changed, 17 insertions(+) create mode 100644 uncloud/uncloud_net/__init__.py create mode 100644 uncloud/uncloud_net/admin.py create mode 100644 uncloud/uncloud_net/apps.py create mode 100644 uncloud/uncloud_net/migrations/__init__.py create mode 100644 uncloud/uncloud_net/models.py create mode 100644 uncloud/uncloud_net/tests.py create mode 100644 uncloud/uncloud_net/views.py diff --git a/uncloud/uncloud_net/__init__.py b/uncloud/uncloud_net/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/uncloud/uncloud_net/admin.py b/uncloud/uncloud_net/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/uncloud/uncloud_net/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/uncloud/uncloud_net/apps.py b/uncloud/uncloud_net/apps.py new file mode 100644 index 0000000..489beb1 --- /dev/null +++ b/uncloud/uncloud_net/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class UncloudNetConfig(AppConfig): + name = 'uncloud_net' diff --git a/uncloud/uncloud_net/migrations/__init__.py b/uncloud/uncloud_net/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/uncloud/uncloud_net/models.py b/uncloud/uncloud_net/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/uncloud/uncloud_net/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/uncloud/uncloud_net/tests.py b/uncloud/uncloud_net/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/uncloud/uncloud_net/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/uncloud/uncloud_net/views.py b/uncloud/uncloud_net/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/uncloud/uncloud_net/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. From 288a65f2192a93aaa2660b244be67b9bb8faee4a Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 27 Feb 2020 15:29:15 +0100 Subject: [PATCH 2/3] ++update Signed-off-by: Nico Schottelius --- .../migrations/0002_auto_20200227_1230.py | 18 ++++++++++ .../migrations/0005_auto_20200227_1230.py | 36 +++++++++++++++++++ uncloud/uncloud_vm/models.py | 15 ++++---- uncloud/uncloud_vm/serializers.py | 10 ++++++ uncloud/uncloud_vm/views.py | 13 ++++++- 5 files changed, 83 insertions(+), 9 deletions(-) create mode 100644 uncloud/uncloud_pay/migrations/0002_auto_20200227_1230.py create mode 100644 uncloud/uncloud_vm/migrations/0005_auto_20200227_1230.py diff --git a/uncloud/uncloud_pay/migrations/0002_auto_20200227_1230.py b/uncloud/uncloud_pay/migrations/0002_auto_20200227_1230.py new file mode 100644 index 0000000..0643e9a --- /dev/null +++ b/uncloud/uncloud_pay/migrations/0002_auto_20200227_1230.py @@ -0,0 +1,18 @@ +# Generated by Django 3.0.3 on 2020-02-27 12:30 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('uncloud_pay', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='payment', + name='source', + field=models.CharField(choices=[('wire', 'Wire Transfer'), ('stripe', 'Stripe'), ('voucher', 'Voucher'), ('referral', 'Referral'), ('unknown', 'Unknown')], default='unknown', max_length=256), + ), + ] diff --git a/uncloud/uncloud_vm/migrations/0005_auto_20200227_1230.py b/uncloud/uncloud_vm/migrations/0005_auto_20200227_1230.py new file mode 100644 index 0000000..1bd711b --- /dev/null +++ b/uncloud/uncloud_vm/migrations/0005_auto_20200227_1230.py @@ -0,0 +1,36 @@ +# Generated by Django 3.0.3 on 2020-02-27 12:30 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('uncloud_pay', '0002_auto_20200227_1230'), + ('uncloud_vm', '0004_vmsnapshotproduct'), + ] + + operations = [ + migrations.RemoveField( + model_name='vmsnapshotproduct', + name='vm_uuid', + ), + migrations.AddField( + model_name='vmproduct', + name='order', + field=models.ForeignKey(default=0, editable=False, on_delete=django.db.models.deletion.CASCADE, to='uncloud_pay.Order'), + preserve_default=False, + ), + migrations.AddField( + model_name='vmproduct', + name='status', + field=models.CharField(choices=[('pending', 'Pending'), ('being_created', 'Being created'), ('active', 'Active'), ('deleted', 'Deleted')], default='pending', max_length=256), + ), + migrations.AddField( + model_name='vmsnapshotproduct', + name='vm', + field=models.ForeignKey(default=0, on_delete=django.db.models.deletion.CASCADE, to='uncloud_vm.VMProduct'), + preserve_default=False, + ), + ] diff --git a/uncloud/uncloud_vm/models.py b/uncloud/uncloud_vm/models.py index 12d188e..4ebae25 100644 --- a/uncloud/uncloud_vm/models.py +++ b/uncloud/uncloud_vm/models.py @@ -32,13 +32,7 @@ class VMHost(models.Model): ) -class VMProduct(models.Model): - uuid = models.UUIDField(primary_key=True, - default=uuid.uuid4, - editable=False) - owner = models.ForeignKey(get_user_model(), - on_delete=models.CASCADE, - editable=False) +class VMProduct(Product): vmhost = models.ForeignKey(VMHost, on_delete=models.CASCADE, editable=False, @@ -72,8 +66,12 @@ class OperatingSystemDisk(VMDiskProduct): class VMNetworkCard(models.Model): vm = models.ForeignKey(VMProduct, on_delete=models.CASCADE) + mac_address = models.IntegerField() + ip_address = models.GenericIPAddressField(blank=True, + null=True) + class VMSnapshotProduct(Product): price_per_gb_ssd = 0.35 @@ -83,7 +81,8 @@ class VMSnapshotProduct(Product): gb_ssd = models.FloatField(editable=False) gb_hdd = models.FloatField(editable=False) - vm_uuid = models.UUIDField() + vm = models.ForeignKey(VMProduct, on_delete=models.CASCADE) + #vm_uuid = models.UUIDField() # Need to setup recurring_price and one_time_price and recurring period diff --git a/uncloud/uncloud_vm/serializers.py b/uncloud/uncloud_vm/serializers.py index c1eafe2..b247709 100644 --- a/uncloud/uncloud_vm/serializers.py +++ b/uncloud/uncloud_vm/serializers.py @@ -14,7 +14,17 @@ class VMProductSerializer(serializers.HyperlinkedModelSerializer): model = VMProduct fields = '__all__' + +# def create(self, validated_data): +# return VMSnapshotProduct() + class VMSnapshotProductSerializer(serializers.ModelSerializer): class Meta: model = VMSnapshotProduct fields = '__all__' + + + # verify that vm.owner == user.request + def validate_vm(self, value): + print(value) + return True diff --git a/uncloud/uncloud_vm/views.py b/uncloud/uncloud_vm/views.py index 444d134..7e517f5 100644 --- a/uncloud/uncloud_vm/views.py +++ b/uncloud/uncloud_vm/views.py @@ -11,6 +11,7 @@ from uncloud_pay.models import Order from .serializers import VMHostSerializer, VMProductSerializer, VMSnapshotProductSerializer + import datetime class VMHostViewSet(viewsets.ModelViewSet): @@ -29,7 +30,17 @@ class VMProductViewSet(viewsets.ModelViewSet): def create(self, request): serializer = VMProductSerializer(data=request.data, context={'request': request}) serializer.is_valid(raise_exception=True) - serializer.save(owner=request.user) + # Create order + now = datetime.datetime.now() + order = Order(owner=request.user, + creation_date=now, + starting_date=now, + recurring_price=20, + one_time_price=0, + recurring_period="per_month") + order.save() + + serializer.save(owner=request.user, order=order) return Response(serializer.data) From 89215e47b6daba0b860eb3d389ec3b1109231dde Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 28 Feb 2020 09:34:29 +0100 Subject: [PATCH 3/3] phase in mac --- uncloud/uncloud_net/models.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/uncloud/uncloud_net/models.py b/uncloud/uncloud_net/models.py index 71a8362..6d0c742 100644 --- a/uncloud/uncloud_net/models.py +++ b/uncloud/uncloud_net/models.py @@ -1,3 +1,4 @@ from django.db import models -# Create your models here. +class MACAdress(models.Model): + prefix = 0x420000000000