Add initial ungleich_service app with MatrixServiceProduct shell
This commit is contained in:
parent
b5a242f176
commit
3b87a47430
11 changed files with 91 additions and 1 deletions
|
@ -63,6 +63,7 @@ INSTALLED_APPS = [
|
|||
'uncloud_pay',
|
||||
'uncloud_auth',
|
||||
'uncloud_vm',
|
||||
'ungleich_service',
|
||||
'opennebula'
|
||||
]
|
||||
|
||||
|
|
|
@ -20,14 +20,18 @@ from rest_framework import routers
|
|||
|
||||
from uncloud_vm import views as vmviews
|
||||
from uncloud_pay import views as payviews
|
||||
from ungleich_service import views as serviceviews
|
||||
from opennebula import views as oneviews
|
||||
|
||||
router = routers.DefaultRouter()
|
||||
|
||||
# user / regular urls
|
||||
# VM
|
||||
router.register(r'vm/snapshot', vmviews.VMSnapshotProductViewSet, basename='vmsnapshotproduct')
|
||||
router.register(r'vm/vm', vmviews.VMProductViewSet, basename='vmproduct')
|
||||
|
||||
# Services
|
||||
router.register(r'service/matrix', serviceviews.MatrixServiceProductViewSet, basename='matrixserviceproduct')
|
||||
|
||||
# Pay
|
||||
router.register(r'user', payviews.UserViewSet, basename='user')
|
||||
router.register(r'payment-method', payviews.PaymentMethodViewSet, basename='payment-method')
|
||||
|
|
0
uncloud/ungleich_service/__init__.py
Normal file
0
uncloud/ungleich_service/__init__.py
Normal file
3
uncloud/ungleich_service/admin.py
Normal file
3
uncloud/ungleich_service/admin.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
5
uncloud/ungleich_service/apps.py
Normal file
5
uncloud/ungleich_service/apps.py
Normal file
|
@ -0,0 +1,5 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class UngleichServiceConfig(AppConfig):
|
||||
name = 'ungleich_service'
|
33
uncloud/ungleich_service/migrations/0001_initial.py
Normal file
33
uncloud/ungleich_service/migrations/0001_initial.py
Normal file
|
@ -0,0 +1,33 @@
|
|||
# Generated by Django 3.0.3 on 2020-02-28 13:44
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
import uuid
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
('uncloud_pay', '0010_merge_20200228_1303'),
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
('uncloud_vm', '0007_auto_20200228_1344'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='MatrixServiceProduct',
|
||||
fields=[
|
||||
('uuid', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
|
||||
('status', models.CharField(choices=[('pending', 'Pending'), ('being_created', 'Being created'), ('active', 'Active'), ('deleted', 'Deleted')], default='pending', max_length=256)),
|
||||
('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')),
|
||||
],
|
||||
options={
|
||||
'abstract': False,
|
||||
},
|
||||
),
|
||||
]
|
0
uncloud/ungleich_service/migrations/__init__.py
Normal file
0
uncloud/ungleich_service/migrations/__init__.py
Normal file
20
uncloud/ungleich_service/models.py
Normal file
20
uncloud/ungleich_service/models.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
import uuid
|
||||
|
||||
from django.db import models
|
||||
from uncloud_pay.models import Product, RecurringPeriod
|
||||
from uncloud_vm.models import VMProduct
|
||||
|
||||
class MatrixServiceProduct(Product):
|
||||
monthly_managment_fee = 20
|
||||
setup_fee = 30
|
||||
|
||||
description = "Managed Matrix HomeServer"
|
||||
vm = models.ForeignKey(
|
||||
VMProduct, on_delete=models.CASCADE
|
||||
)
|
||||
|
||||
def recurring_price(self, recurring_period=RecurringPeriod.PER_MONTH):
|
||||
if recurring_period == RecurringPeriod.PER_MONTH:
|
||||
return monthly_managment_fee + vm.recurring_price(RecurringPeriod.PER_MONTH)
|
||||
else:
|
||||
raise Exception('Invalid recurring period for VM Product pricing.')
|
7
uncloud/ungleich_service/serializers.py
Normal file
7
uncloud/ungleich_service/serializers.py
Normal file
|
@ -0,0 +1,7 @@
|
|||
from rest_framework import serializers
|
||||
from .models import MatrixServiceProduct
|
||||
|
||||
class MatrixServiceProductSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = MatrixServiceProduct
|
||||
fields = '__all__'
|
3
uncloud/ungleich_service/tests.py
Normal file
3
uncloud/ungleich_service/tests.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
14
uncloud/ungleich_service/views.py
Normal file
14
uncloud/ungleich_service/views.py
Normal file
|
@ -0,0 +1,14 @@
|
|||
from rest_framework import viewsets, permissions
|
||||
|
||||
from .models import MatrixServiceProduct
|
||||
from .serializers import MatrixServiceProductSerializer
|
||||
|
||||
class MatrixServiceProductViewSet(viewsets.ModelViewSet):
|
||||
permission_classes = [permissions.IsAuthenticated]
|
||||
serializer_class = MatrixServiceProductSerializer
|
||||
|
||||
def get_queryset(self):
|
||||
return MatrixServiceProduct.objects.filter(owner=self.request.user)
|
||||
def create(self, request):
|
||||
# TODO
|
||||
pass
|
Loading…
Reference in a new issue