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..6d0c742 --- /dev/null +++ b/uncloud/uncloud_net/models.py @@ -0,0 +1,4 @@ +from django.db import models + +class MACAdress(models.Model): + prefix = 0x420000000000 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. 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_pay/migrations/0010_merge_20200228_1303.py b/uncloud/uncloud_pay/migrations/0010_merge_20200228_1303.py new file mode 100644 index 0000000..2ea423c --- /dev/null +++ b/uncloud/uncloud_pay/migrations/0010_merge_20200228_1303.py @@ -0,0 +1,14 @@ +# Generated by Django 3.0.3 on 2020-02-28 13:03 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('uncloud_pay', '0002_auto_20200227_1230'), + ('uncloud_pay', '0009_auto_20200228_0825'), + ] + + operations = [ + ] 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..5535071 --- /dev/null +++ b/uncloud/uncloud_vm/migrations/0005_auto_20200227_1230.py @@ -0,0 +1,25 @@ +# 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='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/migrations/0005_auto_20200227_1532.py b/uncloud/uncloud_vm/migrations/0005_auto_20200227_1532.py index b49d6e4..3ebd472 100644 --- a/uncloud/uncloud_vm/migrations/0005_auto_20200227_1532.py +++ b/uncloud/uncloud_vm/migrations/0005_auto_20200227_1532.py @@ -17,11 +17,6 @@ class Migration(migrations.Migration): name='order', field=models.ForeignKey(editable=False, null=True, on_delete=django.db.models.deletion.CASCADE, to='uncloud_pay.Order'), ), - 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.AlterField( model_name='vmsnapshotproduct', name='order', diff --git a/uncloud/uncloud_vm/migrations/0006_merge_20200228_1303.py b/uncloud/uncloud_vm/migrations/0006_merge_20200228_1303.py new file mode 100644 index 0000000..29411ca --- /dev/null +++ b/uncloud/uncloud_vm/migrations/0006_merge_20200228_1303.py @@ -0,0 +1,14 @@ +# Generated by Django 3.0.3 on 2020-02-28 13:03 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('uncloud_vm', '0005_auto_20200227_1532'), + ('uncloud_vm', '0005_auto_20200227_1230'), + ] + + operations = [ + ] diff --git a/uncloud/uncloud_vm/models.py b/uncloud/uncloud_vm/models.py index 26b369f..663765a 100644 --- a/uncloud/uncloud_vm/models.py +++ b/uncloud/uncloud_vm/models.py @@ -75,8 +75,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 @@ -86,7 +90,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 a7171c9..e5fd4ba 100644 --- a/uncloud/uncloud_vm/views.py +++ b/uncloud/uncloud_vm/views.py @@ -10,6 +10,7 @@ from .models import VMHost, VMProduct, VMSnapshotProduct from uncloud_pay.models import Order, RecurringPeriod from .serializers import VMHostSerializer, VMProductSerializer, VMSnapshotProductSerializer + import datetime class VMHostViewSet(viewsets.ModelViewSet): diff --git a/uncloud/uncloud_vm/views.py.orig b/uncloud/uncloud_vm/views.py.orig deleted file mode 100644 index a311320..0000000 --- a/uncloud/uncloud_vm/views.py.orig +++ /dev/null @@ -1,84 +0,0 @@ -from django.shortcuts import render - -from django.contrib.auth.models import User -from django.shortcuts import get_object_or_404 - -from rest_framework import viewsets, permissions -from rest_framework.response import Response - -<<<<<<< HEAD -from .models import VMHost, VMProduct, VMSnapshotProduct -from uncloud_pay.models import Order - -======= -from uncloud_pay.models import Order, RecurringPeriod - -from .models import VMHost, VMProduct ->>>>>>> Quickly wire vm creation to orders -from .serializers import VMHostSerializer, VMProductSerializer, VMSnapshotProductSerializer - -import datetime - -class VMHostViewSet(viewsets.ModelViewSet): - serializer_class = VMHostSerializer - queryset = VMHost.objects.all() - permission_classes = [permissions.IsAdminUser] - - -class VMProductViewSet(viewsets.ModelViewSet): - permission_classes = [permissions.IsAuthenticated] - serializer_class = VMProductSerializer - - def get_queryset(self): - return VMProduct.objects.filter(owner=self.request.user) - - def create(self, request): - # Create base order. - order = Order.objects.create( - recurring_period=RecurringPeriod.PER_MONTH, - recurring_price=0, - one_time_price=0, - owner=request.user - ) - - # Create VM. - serializer = VMProductSerializer(data=request.data, context={'request': request}) - serializer.is_valid(raise_exception=True) - vm = serializer.save(owner=request.user, order=order) - - # FIXME: commit everything (VM + order) at once. - order.recurring_price = vm.recurring_price(order.recurring_period) - order.one_time_price = 0 - order.save() - - return Response(serializer.data) - - -class VMSnapshotProductViewSet(viewsets.ModelViewSet): - permission_classes = [permissions.IsAuthenticated] - serializer_class = VMSnapshotProductSerializer - - def get_queryset(self): - return VMSnapshotProduct.objects.filter(owner=self.request.user) - - def create(self, request): - serializer = VMSnapshotProductSerializer(data=request.data, context={'request': request}) - serializer.is_valid(raise_exception=True) - - # 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() - - # FIXME: calculate the gb_* values - serializer.save(owner=request.user, - order=order, - gb_ssd=12, - gb_hdd=20) - - return Response(serializer.data)