phase in vpn

Signed-off-by: Nico Schottelius <nico@nico-notebook.schottelius.org>
This commit is contained in:
Nico Schottelius 2020-04-03 19:27:49 +02:00
parent 8fb3ad7fe8
commit 5d084a5716
11 changed files with 190 additions and 116 deletions

View file

@ -62,6 +62,7 @@ INSTALLED_APPS = [
'uncloud', 'uncloud',
'uncloud_pay', 'uncloud_pay',
'uncloud_auth', 'uncloud_auth',
'uncloud_net',
'uncloud_storage', 'uncloud_storage',
'uncloud_vm', 'uncloud_vm',
'ungleich_service', 'ungleich_service',

View file

@ -22,11 +22,12 @@ from django.conf.urls.static import static
from rest_framework import routers 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_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() router = routers.DefaultRouter()
@ -44,6 +45,10 @@ router.register(r'vm/vm', vmviews.VMProductViewSet, basename='vmproduct')
# Services # Services
router.register(r'service/matrix', serviceviews.MatrixServiceProductViewSet, basename='matrixserviceproduct') router.register(r'service/matrix', serviceviews.MatrixServiceProductViewSet, basename='matrixserviceproduct')
# Net
router.register(r'net/vpn', netviews.VPNProductViewSet, basename='vpnproduct')
# Pay # Pay
router.register(r'payment-method', payviews.PaymentMethodViewSet, basename='payment-method') router.register(r'payment-method', payviews.PaymentMethodViewSet, basename='payment-method')
router.register(r'bill', payviews.BillViewSet, basename='bill') 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') 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 = [ urlpatterns = [
path('', include(router.urls)), 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 path('api-auth/', include('rest_framework.urls', namespace='rest_framework')) # for login to REST API
] ]

View file

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

View file

@ -1,4 +1,36 @@
from django.db import models 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): class MACAdress(models.Model):
prefix = 0x420000000000 default_prefix = 0x420000000000

View file

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

View file

@ -1,3 +1,19 @@
from django.shortcuts import render 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

View file

@ -1,101 +0,0 @@
<!DOCTYPE>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>ungleich</title>
<link rel="stylesheet" href="css/style.css">
<link href="css/font/font.css" rel="stylesheet">
</head>
<body>
<div class="d1">
<div class="logo">
<img class="" src="img/logo.png" width="140%" height="80%">
</div>
</div>
<div class="d2">
<strong> ungleich glarus ag</strong>
<br> Bahnhofstrasse 1
<br> 8783 Linthal
<br> Switzerland
<br>
</div>
<div class="d1">
<b>$company_name</b>
<br>$user_name
<span></span>$user_email
<br> $user_street
<br> $user_postal $user_city
<br> $user_country
</div>
<div class="d4">
<div class="b1">
Rechnungsdatum:
<br> Rechnungsnummer
<br> Zahlbar bis
</div>
<div class="b2">
$invoice_date<br>
$invoice_number<br>
$invoice_payable_on
</div>
</div>
<div style="clear: both;"></div>
<div class="d5">
<h1>RECHNUNG</h1>
</div>
<div class="wf th">
<p class="bold">
<span class="tl">Beschreibung</span>
<span class="tr">Netto CHF</span>
</p>
</div>
<div class="wf">
$product_names_and_amounts
</div>
<div class="wf th">
<p class="ts">
<span class="tl">Total</span>
<span class="tr">$total_amount</span>
</p>
<p class="ts">
<span class="tl">7.70% Mehrwertsteuer</span>
<span class="tr">$total_vat_amount</span>
</p>
</div>
<div class="wf pc">
<p class="bold">
<span class="tl">Gesamtbetrag</span>
<span class="tr">$grand_total</span>
</p>
</div>
<div class="wf footer">
<div class="d6">
<p>
<img class="icon" src="img/call.png">+044 534-66-22</p>
<p>
<img class="icon" src="img/msg.png">buchhaltung-ag@ungleich.ch</p>
<p>
<img class="icon" src="img/home.png">https://ungleich.ch</p>
<p>
<img class="icon" src="img/twitter.png">@ungleich</p>
</div>
<div class="d7">
<p>Glarner Kantonalbank</p>
<p>
<span class="bold">IBAN: CH 4300 7730 0055 5931 177</span>
</p>
<p>
<span class="bold">BIC: GLKBCH22</span>
</p>
<p style="font-size: 13px">Mwst-Nummer: CHE-156.970.649 MWST</p>
</div>
</div>
</body>
</html>

View file

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

View file

@ -3,10 +3,6 @@ import uuid
from django.db import models from django.db import models
from django.contrib.auth import get_user_model 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_pay.models import Product, RecurringPeriod
from uncloud.models import UncloudModel, UncloudStatus from uncloud.models import UncloudModel, UncloudStatus

View file

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