From 5d084a5716d83b0153e5aa8df6015bf25aacccab Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 3 Apr 2020 19:27:49 +0200 Subject: [PATCH] phase in vpn Signed-off-by: Nico Schottelius --- .../uncloud/uncloud/settings.py | 1 + uncloud_django_based/uncloud/uncloud/urls.py | 21 ++-- .../uncloud_net/migrations/0001_initial.py | 63 +++++++++++ .../uncloud_net/migrations/__init__.py | 0 .../uncloud/uncloud_net/models.py | 34 +++++- .../uncloud/uncloud_net/serializers.py | 13 +++ .../uncloud/uncloud_net/views.py | 18 +++- .../uncloud_pay/templates/bill.html.template | 101 ------------------ .../migrations/0008_auto_20200403_1727.py | 33 ++++++ .../uncloud/uncloud_vm/models.py | 4 - .../migrations/0004_auto_20200403_1727.py | 18 ++++ 11 files changed, 190 insertions(+), 116 deletions(-) create mode 100644 uncloud_django_based/uncloud/uncloud_net/migrations/0001_initial.py create mode 100644 uncloud_django_based/uncloud/uncloud_net/migrations/__init__.py create mode 100644 uncloud_django_based/uncloud/uncloud_net/serializers.py delete mode 100644 uncloud_django_based/uncloud/uncloud_pay/templates/bill.html.template create mode 100644 uncloud_django_based/uncloud/uncloud_vm/migrations/0008_auto_20200403_1727.py create mode 100644 uncloud_django_based/uncloud/ungleich_service/migrations/0004_auto_20200403_1727.py 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 @@ - - - - - - ungleich - - - - - - -
- -
-
- ungleich glarus ag -
Bahnhofstrasse 1 -
8783 Linthal -
Switzerland -
-
-
- $company_name -
$user_name - $user_email -
$user_street -
$user_postal $user_city -
$user_country -
-
-
- Rechnungsdatum: -
Rechnungsnummer -
Zahlbar bis - -
-
- $invoice_date
- $invoice_number
- $invoice_payable_on -
-
-
-
-

RECHNUNG

-
-
-

- Beschreibung - Netto CHF -

-
-
- $product_names_and_amounts -
-
-

- Total - $total_amount -

-

- 7.70% Mehrwertsteuer - $total_vat_amount -

-
-
-

- Gesamtbetrag - $grand_total -

-
- - - - \ No newline at end of file diff --git a/uncloud_django_based/uncloud/uncloud_vm/migrations/0008_auto_20200403_1727.py b/uncloud_django_based/uncloud/uncloud_vm/migrations/0008_auto_20200403_1727.py new file mode 100644 index 0000000..5f4b494 --- /dev/null +++ b/uncloud_django_based/uncloud/uncloud_vm/migrations/0008_auto_20200403_1727.py @@ -0,0 +1,33 @@ +# Generated by Django 3.0.5 on 2020-04-03 17:27 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('uncloud_vm', '0007_vmhost_vmcluster'), + ] + + operations = [ + migrations.AlterField( + model_name='vmdiskimageproduct', + name='status', + field=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), + ), + migrations.AlterField( + model_name='vmhost', + name='status', + field=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), + ), + migrations.AlterField( + model_name='vmproduct', + name='status', + field=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), + ), + migrations.AlterField( + model_name='vmsnapshotproduct', + name='status', + field=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), + ), + ] diff --git a/uncloud_django_based/uncloud/uncloud_vm/models.py b/uncloud_django_based/uncloud/uncloud_vm/models.py index 3b2c46b..8644e93 100644 --- a/uncloud_django_based/uncloud/uncloud_vm/models.py +++ b/uncloud_django_based/uncloud/uncloud_vm/models.py @@ -3,10 +3,6 @@ import uuid from django.db import models from django.contrib.auth import get_user_model - -# Uncomment if you override model's clean method -# from django.core.exceptions import ValidationError - from uncloud_pay.models import Product, RecurringPeriod from uncloud.models import UncloudModel, UncloudStatus diff --git a/uncloud_django_based/uncloud/ungleich_service/migrations/0004_auto_20200403_1727.py b/uncloud_django_based/uncloud/ungleich_service/migrations/0004_auto_20200403_1727.py new file mode 100644 index 0000000..eed8d33 --- /dev/null +++ b/uncloud_django_based/uncloud/ungleich_service/migrations/0004_auto_20200403_1727.py @@ -0,0 +1,18 @@ +# Generated by Django 3.0.5 on 2020-04-03 17:27 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('ungleich_service', '0003_auto_20200322_1758'), + ] + + operations = [ + migrations.AlterField( + model_name='matrixserviceproduct', + name='status', + field=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), + ), + ]