Phasing out Product model

Signed-off-by: Nico Schottelius <nico@nico-notebook.schottelius.org>
This commit is contained in:
Nico Schottelius 2020-09-28 20:59:08 +02:00
parent 1aead50170
commit c6bacab35a
12 changed files with 227 additions and 26 deletions

View File

@ -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',
),
]

View File

@ -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()

View File

@ -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

View File

@ -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')

View File

@ -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',
),
]

View File

@ -163,7 +163,7 @@ class VPNNetworkReservation(UncloudModel):
)
class VPNNetwork(Product):
class VPNNetwork(models.Model):
"""
A selected network. Used for tracking reservations / used networks
"""

View File

@ -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,
},
),
]

View File

@ -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.

View File

@ -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',
),
]

View File

@ -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,

View File

@ -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',
),
]

View File

@ -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)