diff --git a/uncloud_django_based/uncloud/uncloud/settings.py b/uncloud_django_based/uncloud/uncloud/settings.py index 94476d1..871ac8e 100644 --- a/uncloud_django_based/uncloud/uncloud/settings.py +++ b/uncloud_django_based/uncloud/uncloud/settings.py @@ -62,6 +62,7 @@ INSTALLED_APPS = [ 'uncloud', 'uncloud_pay', 'uncloud_auth', + 'uncloud_net', 'uncloud_storage', 'uncloud_vm', 'ungleich_service', diff --git a/uncloud_django_based/uncloud/uncloud/urls.py b/uncloud_django_based/uncloud/uncloud/urls.py index 8de3fa5..d7550db 100644 --- a/uncloud_django_based/uncloud/uncloud/urls.py +++ b/uncloud_django_based/uncloud/uncloud/urls.py @@ -22,11 +22,12 @@ from django.conf.urls.static import static 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 +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 +from uncloud_vm import views as vmviews +from ungleich_service import views as serviceviews router = routers.DefaultRouter() @@ -44,6 +45,10 @@ router.register(r'vm/vm', vmviews.VMProductViewSet, basename='vmproduct') # Services router.register(r'service/matrix', serviceviews.MatrixServiceProductViewSet, basename='matrixserviceproduct') +# Net +router.register(r'net/vpn', netviews.VPNProductViewSet, basename='vpnproduct') + + # Pay router.register(r'payment-method', payviews.PaymentMethodViewSet, basename='payment-method') router.register(r'bill', payviews.BillViewSet, basename='bill') @@ -64,12 +69,10 @@ router.register(r'admin/opennebula', oneviews.VMViewSet, basename='opennebula') router.register(r'user', authviews.UserViewSet, basename='user') -# Testing -# router.register(r'user', authviews.UserViewSet, basename='user') -from uncloud_net import views as netview - urlpatterns = [ path('', include(router.urls)), - path('pdf/', payviews.MyPDFView.as_view(), name='pdf'), + # web/ = stuff to view in the browser + + path('web/pdf/', payviews.MyPDFView.as_view(), name='pdf'), path('api-auth/', include('rest_framework.urls', namespace='rest_framework')) # for login to REST API ] diff --git a/uncloud_django_based/uncloud/uncloud_net/migrations/0001_initial.py b/uncloud_django_based/uncloud/uncloud_net/migrations/0001_initial.py new file mode 100644 index 0000000..b40e0b3 --- /dev/null +++ b/uncloud_django_based/uncloud/uncloud_net/migrations/0001_initial.py @@ -0,0 +1,63 @@ +# Generated by Django 3.0.5 on 2020-04-03 17:27 + +from django.conf import settings +import django.contrib.postgres.fields.jsonb +import django.core.validators +from django.db import migrations, models +import django.db.models.deletion +import uuid + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('uncloud_pay', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='MACAdress', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ], + ), + migrations.CreateModel( + name='VPNPool', + fields=[ + ('extra_data', django.contrib.postgres.fields.jsonb.JSONField(blank=True, editable=False, null=True)), + ('network', models.GenericIPAddressField(editable=False, primary_key=True, serialize=False)), + ('network_size', models.IntegerField(validators=[django.core.validators.MinValueValidator(0), django.core.validators.MaxValueValidator(128)])), + ], + options={ + 'abstract': False, + }, + ), + migrations.CreateModel( + name='VPNProduct', + fields=[ + ('extra_data', django.contrib.postgres.fields.jsonb.JSONField(blank=True, editable=False, null=True)), + ('uuid', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), + ('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='PENDING', max_length=32)), + ('network', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='uncloud_net.VPNPool')), + ('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)), + ], + options={ + 'abstract': False, + }, + ), + migrations.CreateModel( + name='VPNNetwork', + fields=[ + ('extra_data', django.contrib.postgres.fields.jsonb.JSONField(blank=True, editable=False, null=True)), + ('network', models.GenericIPAddressField(editable=False, primary_key=True, serialize=False)), + ('vpnpool', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='uncloud_net.VPNPool')), + ], + options={ + 'abstract': False, + }, + ), + ] diff --git a/uncloud_django_based/uncloud/uncloud_net/migrations/__init__.py b/uncloud_django_based/uncloud/uncloud_net/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/uncloud_django_based/uncloud/uncloud_net/models.py b/uncloud_django_based/uncloud/uncloud_net/models.py index 6d0c742..934eeb5 100644 --- a/uncloud_django_based/uncloud/uncloud_net/models.py +++ b/uncloud_django_based/uncloud/uncloud_net/models.py @@ -1,4 +1,36 @@ from django.db import models +from django.contrib.auth import get_user_model +from django.core.validators import MinValueValidator, MaxValueValidator + + +from uncloud_pay.models import Product, RecurringPeriod +from uncloud.models import UncloudModel, UncloudStatus + +class VPNPool(UncloudModel): + """ + Network address pools from which VPNs can be created + """ + + network = models.GenericIPAddressField(primary_key=True, + editable=False) + + network_size = models.IntegerField(validators=[MinValueValidator(0), + MaxValueValidator(128)]) + +class VPNNetwork(UncloudModel): + """ + A selected network. Used for tracking reservations / used networks + """ + vpnpool = models.ForeignKey(VPNPool, + on_delete=models.CASCADE) + + network = models.GenericIPAddressField(primary_key=True, + editable=False) + +class VPNProduct(Product): + network = models.ForeignKey(VPNPool, + on_delete=models.CASCADE) + class MACAdress(models.Model): - prefix = 0x420000000000 + default_prefix = 0x420000000000 diff --git a/uncloud_django_based/uncloud/uncloud_net/serializers.py b/uncloud_django_based/uncloud/uncloud_net/serializers.py new file mode 100644 index 0000000..856688b --- /dev/null +++ b/uncloud_django_based/uncloud/uncloud_net/serializers.py @@ -0,0 +1,13 @@ +from django.contrib.auth import get_user_model +from rest_framework import serializers + +from .models import * + +class VPNProductSerializer(serializers.ModelSerializer): + + network_size = serializers.IntegerField(min_value=0, + max_value=128) + + class Meta: + model = VPNProduct + fields = '__all__' diff --git a/uncloud_django_based/uncloud/uncloud_net/views.py b/uncloud_django_based/uncloud/uncloud_net/views.py index 91ea44a..f22da2f 100644 --- a/uncloud_django_based/uncloud/uncloud_net/views.py +++ b/uncloud_django_based/uncloud/uncloud_net/views.py @@ -1,3 +1,19 @@ from django.shortcuts import render +from rest_framework import viewsets, permissions -# Create your views here. + +from .models import * +from .serializers import * + + +class VPNProductViewSet(viewsets.ModelViewSet): + serializer_class = VPNProductSerializer + permission_classes = [permissions.IsAdminUser] + + def get_queryset(self): + if self.request.user.is_superuser: + obj = VPNProduct.objects.all() + else: + obj = VPNProduct.objects.filter(owner=self.request.user) + + return obj diff --git a/uncloud_django_based/uncloud/uncloud_pay/templates/bill.html.template b/uncloud_django_based/uncloud/uncloud_pay/templates/bill.html.template deleted file mode 100644 index 019ee81..0000000 --- a/uncloud_django_based/uncloud/uncloud_pay/templates/bill.html.template +++ /dev/null @@ -1,101 +0,0 @@ - - - -
- -- Beschreibung - Netto CHF -
-- Total - $total_amount -
-- 7.70% Mehrwertsteuer - $total_vat_amount -
-- Gesamtbetrag - $grand_total -
-