From c6bacab35ac1a19638870ee46bef6c0169b71a84 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Mon, 28 Sep 2020 20:59:08 +0200 Subject: [PATCH] Phasing out Product model Signed-off-by: Nico Schottelius --- .../migrations/0006_auto_20200928_1858.py | 25 +++++++ opennebula/models.py | 2 +- opennebula/views.py | 22 +++---- uncloud/urls.py | 4 +- .../migrations/0006_auto_20200928_1858.py | 25 +++++++ uncloud_net/models.py | 2 +- .../migrations/0016_auto_20200928_1858.py | 65 +++++++++++++++++++ uncloud_pay/models.py | 12 ++-- .../migrations/0006_auto_20200928_1858.py | 37 +++++++++++ uncloud_service/models.py | 4 +- .../migrations/0006_auto_20200928_1858.py | 49 ++++++++++++++ uncloud_vm/models.py | 6 +- 12 files changed, 227 insertions(+), 26 deletions(-) create mode 100644 opennebula/migrations/0006_auto_20200928_1858.py create mode 100644 uncloud_net/migrations/0006_auto_20200928_1858.py create mode 100644 uncloud_pay/migrations/0016_auto_20200928_1858.py create mode 100644 uncloud_service/migrations/0006_auto_20200928_1858.py create mode 100644 uncloud_vm/migrations/0006_auto_20200928_1858.py diff --git a/opennebula/migrations/0006_auto_20200928_1858.py b/opennebula/migrations/0006_auto_20200928_1858.py new file mode 100644 index 0000000..49da56f --- /dev/null +++ b/opennebula/migrations/0006_auto_20200928_1858.py @@ -0,0 +1,25 @@ +# Generated by Django 3.1 on 2020-09-28 18:58 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('opennebula', '0005_remove_vm_orders'), + ] + + operations = [ + migrations.RemoveField( + model_name='vm', + name='extra_data', + ), + migrations.RemoveField( + model_name='vm', + name='owner', + ), + migrations.RemoveField( + model_name='vm', + name='status', + ), + ] diff --git a/opennebula/models.py b/opennebula/models.py index 6c7dc52..f15b845 100644 --- a/opennebula/models.py +++ b/opennebula/models.py @@ -10,7 +10,7 @@ storage_class_mapping = { 'hdd': 'hdd' } -class VM(Product): +class VM(models.Model): vmid = models.IntegerField(primary_key=True) data = models.JSONField() diff --git a/opennebula/views.py b/opennebula/views.py index 89b1a52..688f0b4 100644 --- a/opennebula/views.py +++ b/opennebula/views.py @@ -1,16 +1,16 @@ from rest_framework import viewsets, permissions -from .models import VM -from .serializers import OpenNebulaVMSerializer +#from .models import VM +# from .serializers import OpenNebulaVMSerializer -class VMViewSet(viewsets.ModelViewSet): - permission_classes = [permissions.IsAuthenticated] - serializer_class = OpenNebulaVMSerializer +# class VMViewSet(viewsets.ModelViewSet): +# permission_classes = [permissions.IsAuthenticated] +# serializer_class = OpenNebulaVMSerializer - def get_queryset(self): - if self.request.user.is_superuser: - obj = VM.objects.all() - else: - obj = VM.objects.filter(owner=self.request.user) +# def get_queryset(self): +# if self.request.user.is_superuser: +# obj = VM.objects.all() +# else: +# obj = VM.objects.filter(owner=self.request.user) - return obj +# return obj diff --git a/uncloud/urls.py b/uncloud/urls.py index 8b4862e..ef950a0 100644 --- a/uncloud/urls.py +++ b/uncloud/urls.py @@ -12,7 +12,7 @@ from django.conf.urls.static import static from rest_framework import routers from rest_framework.schemas import get_schema_view -from opennebula import views as oneviews +#from opennebula import views as oneviews from uncloud_auth import views as authviews from uncloud_net import views as netviews from uncloud_pay import views as payviews @@ -60,7 +60,7 @@ router.register(r'v1/admin/order', payviews.AdminOrderViewSet, basename='admin/o router.register(r'v1/admin/vmhost', vmviews.VMHostViewSet) router.register(r'v1/admin/vmcluster', vmviews.VMClusterViewSet) router.register(r'v1/admin/vpnpool', netviews.VPNPoolViewSet) -router.register(r'v1/admin/opennebula', oneviews.VMViewSet, basename='opennebula') +#router.register(r'v1/admin/opennebula', oneviews.VMViewSet, basename='opennebula') # User/Account router.register(r'v1/my/user', authviews.UserViewSet, basename='user') diff --git a/uncloud_net/migrations/0006_auto_20200928_1858.py b/uncloud_net/migrations/0006_auto_20200928_1858.py new file mode 100644 index 0000000..b1a04a6 --- /dev/null +++ b/uncloud_net/migrations/0006_auto_20200928_1858.py @@ -0,0 +1,25 @@ +# Generated by Django 3.1 on 2020-09-28 18:58 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('uncloud_net', '0005_remove_vpnnetwork_orders'), + ] + + operations = [ + migrations.RemoveField( + model_name='vpnnetwork', + name='extra_data', + ), + migrations.RemoveField( + model_name='vpnnetwork', + name='owner', + ), + migrations.RemoveField( + model_name='vpnnetwork', + name='status', + ), + ] diff --git a/uncloud_net/models.py b/uncloud_net/models.py index 4f80246..153b456 100644 --- a/uncloud_net/models.py +++ b/uncloud_net/models.py @@ -163,7 +163,7 @@ class VPNNetworkReservation(UncloudModel): ) -class VPNNetwork(Product): +class VPNNetwork(models.Model): """ A selected network. Used for tracking reservations / used networks """ diff --git a/uncloud_pay/migrations/0016_auto_20200928_1858.py b/uncloud_pay/migrations/0016_auto_20200928_1858.py new file mode 100644 index 0000000..0c5ebfa --- /dev/null +++ b/uncloud_pay/migrations/0016_auto_20200928_1858.py @@ -0,0 +1,65 @@ +# Generated by Django 3.1 on 2020-09-28 18:58 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('uncloud_pay', '0015_auto_20200928_1844'), + ] + + operations = [ + migrations.RemoveField( + model_name='sampleonetimeproduct', + name='extra_data', + ), + migrations.RemoveField( + model_name='sampleonetimeproduct', + name='owner', + ), + migrations.RemoveField( + model_name='sampleonetimeproduct', + name='status', + ), + migrations.RemoveField( + model_name='samplerecurringproduct', + name='extra_data', + ), + migrations.RemoveField( + model_name='samplerecurringproduct', + name='owner', + ), + migrations.RemoveField( + model_name='samplerecurringproduct', + name='status', + ), + migrations.RemoveField( + model_name='samplerecurringproductonetimefee', + name='extra_data', + ), + migrations.RemoveField( + model_name='samplerecurringproductonetimefee', + name='owner', + ), + migrations.RemoveField( + model_name='samplerecurringproductonetimefee', + name='status', + ), + migrations.CreateModel( + name='Product', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('extra_data', models.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)), + ('config', models.JSONField()), + ('owner', models.ForeignKey(editable=False, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ], + options={ + 'abstract': False, + }, + ), + ] diff --git a/uncloud_pay/models.py b/uncloud_pay/models.py index 5b6299c..b6f8f39 100644 --- a/uncloud_pay/models.py +++ b/uncloud_pay/models.py @@ -876,7 +876,7 @@ class Product(UncloudModel): choices=UncloudStatus.choices, default=UncloudStatus.AWAITING_PAYMENT) -# config = models.JSONField() + config = models.JSONField() # Default period for all products default_recurring_period = RecurringPeriod.PER_30D @@ -996,8 +996,8 @@ class Product(UncloudModel): def allowed_recurring_periods(): return RecurringPeriod.choices - class Meta: - abstract = True + # class Meta: + # abstract = True def discounted_price_by_period(self, requested_period): """ @@ -1082,7 +1082,7 @@ class Product(UncloudModel): # Sample products included into uncloud -class SampleOneTimeProduct(Product): +class SampleOneTimeProduct(models.Model): """ Products are usually more complex, but this product shows how easy it can be to create your own one time product. @@ -1096,7 +1096,7 @@ class SampleOneTimeProduct(Product): def one_time_price(self): return self.ot_price -class SampleRecurringProduct(Product): +class SampleRecurringProduct(models.Model): """ Products are usually more complex, but this product shows how easy it can be to create your own recurring fee product. @@ -1110,7 +1110,7 @@ class SampleRecurringProduct(Product): def recurring_price(self): return self.rc_price -class SampleRecurringProductOneTimeFee(Product): +class SampleRecurringProductOneTimeFee(models.Model): """ Products are usually more complex, but this product shows how easy it can be to create your own one time + recurring fee product. diff --git a/uncloud_service/migrations/0006_auto_20200928_1858.py b/uncloud_service/migrations/0006_auto_20200928_1858.py new file mode 100644 index 0000000..154ddb1 --- /dev/null +++ b/uncloud_service/migrations/0006_auto_20200928_1858.py @@ -0,0 +1,37 @@ +# Generated by Django 3.1 on 2020-09-28 18:58 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('uncloud_service', '0005_auto_20200928_1844'), + ] + + operations = [ + migrations.RemoveField( + model_name='genericserviceproduct', + name='extra_data', + ), + migrations.RemoveField( + model_name='genericserviceproduct', + name='owner', + ), + migrations.RemoveField( + model_name='genericserviceproduct', + name='status', + ), + migrations.RemoveField( + model_name='matrixserviceproduct', + name='extra_data', + ), + migrations.RemoveField( + model_name='matrixserviceproduct', + name='owner', + ), + migrations.RemoveField( + model_name='matrixserviceproduct', + name='status', + ), + ] diff --git a/uncloud_service/models.py b/uncloud_service/models.py index d067a23..8afb2e7 100644 --- a/uncloud_service/models.py +++ b/uncloud_service/models.py @@ -3,7 +3,7 @@ from uncloud_pay.models import Product, RecurringPeriod, AMOUNT_MAX_DIGITS, AMOU from uncloud_vm.models import VMProduct, VMDiskImageProduct from django.core.validators import MinValueValidator -class MatrixServiceProduct(Product): +class MatrixServiceProduct(models.Model): monthly_managment_fee = 20 description = "Managed Matrix HomeServer" @@ -34,7 +34,7 @@ class MatrixServiceProduct(Product): def one_time_price(self): return 30 -class GenericServiceProduct(Product): +class GenericServiceProduct(models.Model): custom_description = models.TextField() custom_recurring_price = models.DecimalField(default=0.0, max_digits=AMOUNT_MAX_DIGITS, diff --git a/uncloud_vm/migrations/0006_auto_20200928_1858.py b/uncloud_vm/migrations/0006_auto_20200928_1858.py new file mode 100644 index 0000000..96725d4 --- /dev/null +++ b/uncloud_vm/migrations/0006_auto_20200928_1858.py @@ -0,0 +1,49 @@ +# Generated by Django 3.1 on 2020-09-28 18:58 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('uncloud_vm', '0005_auto_20200928_1844'), + ] + + operations = [ + migrations.RemoveField( + model_name='vmdiskproduct', + name='extra_data', + ), + migrations.RemoveField( + model_name='vmdiskproduct', + name='owner', + ), + migrations.RemoveField( + model_name='vmdiskproduct', + name='status', + ), + migrations.RemoveField( + model_name='vmproduct', + name='extra_data', + ), + migrations.RemoveField( + model_name='vmproduct', + name='owner', + ), + migrations.RemoveField( + model_name='vmproduct', + name='status', + ), + migrations.RemoveField( + model_name='vmsnapshotproduct', + name='extra_data', + ), + migrations.RemoveField( + model_name='vmsnapshotproduct', + name='owner', + ), + migrations.RemoveField( + model_name='vmsnapshotproduct', + name='status', + ), + ] diff --git a/uncloud_vm/models.py b/uncloud_vm/models.py index a625555..72a9555 100644 --- a/uncloud_vm/models.py +++ b/uncloud_vm/models.py @@ -49,7 +49,7 @@ class VMHost(UncloudModel): -class VMProduct(Product): +class VMProduct(models.Model): vmhost = models.ForeignKey( VMHost, on_delete=models.CASCADE, editable=False, blank=True, null=True ) @@ -133,7 +133,7 @@ class VMDiskType(models.TextChoices): LOCAL_HDD = 'local/hdd' -class VMDiskProduct(Product): +class VMDiskProduct(models.Model): """ The VMDiskProduct is attached to a VM. @@ -180,7 +180,7 @@ class VMNetworkCard(models.Model): null=True) -class VMSnapshotProduct(Product): +class VMSnapshotProduct(models.Model): gb_ssd = models.FloatField(editable=False) gb_hdd = models.FloatField(editable=False)