[vpn] fix urls
This commit is contained in:
parent
096f7e05c0
commit
913e992a48
4 changed files with 34 additions and 19 deletions
|
@ -46,7 +46,7 @@ router.register(r'vm/vm', vmviews.VMProductViewSet, basename='vmproduct')
|
||||||
router.register(r'service/matrix', serviceviews.MatrixServiceProductViewSet, basename='matrixserviceproduct')
|
router.register(r'service/matrix', serviceviews.MatrixServiceProductViewSet, basename='matrixserviceproduct')
|
||||||
|
|
||||||
# Net
|
# Net
|
||||||
router.register(r'net/vpn', netviews.VPNProductViewSet, basename='vpnproduct')
|
router.register(r'net/vpn', netviews.VPNNetworkViewSet, basename='vpnnet')
|
||||||
|
|
||||||
|
|
||||||
# Pay
|
# Pay
|
||||||
|
@ -63,6 +63,8 @@ router.register(r'admin/payment', payviews.AdminPaymentViewSet, basename='admin/
|
||||||
router.register(r'admin/order', payviews.AdminOrderViewSet, basename='admin/order')
|
router.register(r'admin/order', payviews.AdminOrderViewSet, basename='admin/order')
|
||||||
router.register(r'admin/vmhost', vmviews.VMHostViewSet)
|
router.register(r'admin/vmhost', vmviews.VMHostViewSet)
|
||||||
router.register(r'admin/vmcluster', vmviews.VMClusterViewSet)
|
router.register(r'admin/vmcluster', vmviews.VMClusterViewSet)
|
||||||
|
router.register(r'admin/vpnpool', netviews.VPNPoolViewSet)
|
||||||
|
|
||||||
router.register(r'admin/opennebula', oneviews.VMViewSet, basename='opennebula')
|
router.register(r'admin/opennebula', oneviews.VMViewSet, basename='opennebula')
|
||||||
|
|
||||||
# User/Account
|
# User/Account
|
||||||
|
|
|
@ -6,31 +6,33 @@ from django.core.validators import MinValueValidator, MaxValueValidator
|
||||||
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
|
||||||
|
|
||||||
|
|
||||||
|
class MACAdress(models.Model):
|
||||||
|
default_prefix = 0x420000000000
|
||||||
|
|
||||||
class VPNPool(UncloudModel):
|
class VPNPool(UncloudModel):
|
||||||
"""
|
"""
|
||||||
Network address pools from which VPNs can be created
|
Network address pools from which VPNs can be created
|
||||||
"""
|
"""
|
||||||
|
|
||||||
network = models.GenericIPAddressField(primary_key=True,
|
network = models.GenericIPAddressField(primary_key=True)
|
||||||
editable=False)
|
|
||||||
|
|
||||||
network_size = models.IntegerField(validators=[MinValueValidator(0),
|
network_size = models.IntegerField(validators=[MinValueValidator(0),
|
||||||
MaxValueValidator(128)])
|
MaxValueValidator(128)])
|
||||||
|
|
||||||
class VPNNetwork(UncloudModel):
|
vpn_hostname = models.CharField(max_length=256)
|
||||||
|
|
||||||
|
wireguard_private_key = models.CharField(max_length=48)
|
||||||
|
|
||||||
|
|
||||||
|
class VPNNetwork(Product):
|
||||||
"""
|
"""
|
||||||
A selected network. Used for tracking reservations / used networks
|
A selected network. Used for tracking reservations / used networks
|
||||||
"""
|
"""
|
||||||
vpnpool = models.ForeignKey(VPNPool,
|
vpnpool = models.ForeignKey(VPNPool,
|
||||||
on_delete=models.CASCADE)
|
on_delete=models.CASCADE)
|
||||||
|
|
||||||
network = models.GenericIPAddressField(primary_key=True,
|
network = models.GenericIPAddressField(editable=False,
|
||||||
editable=False)
|
unique=True)
|
||||||
|
|
||||||
class VPNProduct(Product):
|
wireguard_public_key = models.CharField(max_length=48)
|
||||||
network = models.ForeignKey(VPNPool,
|
|
||||||
on_delete=models.CASCADE)
|
|
||||||
|
|
||||||
|
|
||||||
class MACAdress(models.Model):
|
|
||||||
default_prefix = 0x420000000000
|
|
||||||
|
|
|
@ -3,11 +3,16 @@ from rest_framework import serializers
|
||||||
|
|
||||||
from .models import *
|
from .models import *
|
||||||
|
|
||||||
class VPNProductSerializer(serializers.ModelSerializer):
|
class VPNPoolSerializer(serializers.ModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = VPNPool
|
||||||
|
fields = '__all__'
|
||||||
|
|
||||||
|
class VPNNetworkSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
network_size = serializers.IntegerField(min_value=0,
|
network_size = serializers.IntegerField(min_value=0,
|
||||||
max_value=128)
|
max_value=128)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = VPNProduct
|
model = VPNNetwork
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
|
|
|
@ -6,14 +6,20 @@ from .models import *
|
||||||
from .serializers import *
|
from .serializers import *
|
||||||
|
|
||||||
|
|
||||||
class VPNProductViewSet(viewsets.ModelViewSet):
|
class VPNPoolViewSet(viewsets.ModelViewSet):
|
||||||
serializer_class = VPNProductSerializer
|
serializer_class = VPNPoolSerializer
|
||||||
|
permission_classes = [permissions.IsAdminUser]
|
||||||
|
queryset = VPNPool.objects.all()
|
||||||
|
|
||||||
|
|
||||||
|
class VPNNetworkViewSet(viewsets.ModelViewSet):
|
||||||
|
serializer_class = VPNNetworkSerializer
|
||||||
permission_classes = [permissions.IsAdminUser]
|
permission_classes = [permissions.IsAdminUser]
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
if self.request.user.is_superuser:
|
if self.request.user.is_superuser:
|
||||||
obj = VPNProduct.objects.all()
|
obj = VPNNetwork.objects.all()
|
||||||
else:
|
else:
|
||||||
obj = VPNProduct.objects.filter(owner=self.request.user)
|
obj = VPNNetwork.objects.filter(owner=self.request.user)
|
||||||
|
|
||||||
return obj
|
return obj
|
||||||
|
|
Loading…
Reference in a new issue