From 3b87a4743053ef054704a7d6bcbea4f1189c9fcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Floure?= Date: Fri, 28 Feb 2020 14:46:33 +0100 Subject: [PATCH] Add initial ungleich_service app with MatrixServiceProduct shell --- uncloud/uncloud/settings.py | 1 + uncloud/uncloud/urls.py | 6 +++- uncloud/ungleich_service/__init__.py | 0 uncloud/ungleich_service/admin.py | 3 ++ uncloud/ungleich_service/apps.py | 5 +++ .../migrations/0001_initial.py | 33 +++++++++++++++++++ .../ungleich_service/migrations/__init__.py | 0 uncloud/ungleich_service/models.py | 20 +++++++++++ uncloud/ungleich_service/serializers.py | 7 ++++ uncloud/ungleich_service/tests.py | 3 ++ uncloud/ungleich_service/views.py | 14 ++++++++ 11 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 uncloud/ungleich_service/__init__.py create mode 100644 uncloud/ungleich_service/admin.py create mode 100644 uncloud/ungleich_service/apps.py create mode 100644 uncloud/ungleich_service/migrations/0001_initial.py create mode 100644 uncloud/ungleich_service/migrations/__init__.py create mode 100644 uncloud/ungleich_service/models.py create mode 100644 uncloud/ungleich_service/serializers.py create mode 100644 uncloud/ungleich_service/tests.py create mode 100644 uncloud/ungleich_service/views.py diff --git a/uncloud/uncloud/settings.py b/uncloud/uncloud/settings.py index 179ff0b..24a425f 100644 --- a/uncloud/uncloud/settings.py +++ b/uncloud/uncloud/settings.py @@ -63,6 +63,7 @@ INSTALLED_APPS = [ 'uncloud_pay', 'uncloud_auth', 'uncloud_vm', + 'ungleich_service', 'opennebula' ] diff --git a/uncloud/uncloud/urls.py b/uncloud/uncloud/urls.py index 8244e0e..e4abba5 100644 --- a/uncloud/uncloud/urls.py +++ b/uncloud/uncloud/urls.py @@ -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') diff --git a/uncloud/ungleich_service/__init__.py b/uncloud/ungleich_service/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/uncloud/ungleich_service/admin.py b/uncloud/ungleich_service/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/uncloud/ungleich_service/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/uncloud/ungleich_service/apps.py b/uncloud/ungleich_service/apps.py new file mode 100644 index 0000000..184e181 --- /dev/null +++ b/uncloud/ungleich_service/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class UngleichServiceConfig(AppConfig): + name = 'ungleich_service' diff --git a/uncloud/ungleich_service/migrations/0001_initial.py b/uncloud/ungleich_service/migrations/0001_initial.py new file mode 100644 index 0000000..2e19344 --- /dev/null +++ b/uncloud/ungleich_service/migrations/0001_initial.py @@ -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, + }, + ), + ] diff --git a/uncloud/ungleich_service/migrations/__init__.py b/uncloud/ungleich_service/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/uncloud/ungleich_service/models.py b/uncloud/ungleich_service/models.py new file mode 100644 index 0000000..ac1f90e --- /dev/null +++ b/uncloud/ungleich_service/models.py @@ -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.') diff --git a/uncloud/ungleich_service/serializers.py b/uncloud/ungleich_service/serializers.py new file mode 100644 index 0000000..54737e9 --- /dev/null +++ b/uncloud/ungleich_service/serializers.py @@ -0,0 +1,7 @@ +from rest_framework import serializers +from .models import MatrixServiceProduct + +class MatrixServiceProductSerializer(serializers.ModelSerializer): + class Meta: + model = MatrixServiceProduct + fields = '__all__' diff --git a/uncloud/ungleich_service/tests.py b/uncloud/ungleich_service/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/uncloud/ungleich_service/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/uncloud/ungleich_service/views.py b/uncloud/ungleich_service/views.py new file mode 100644 index 0000000..776b94c --- /dev/null +++ b/uncloud/ungleich_service/views.py @@ -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