phase in configuration - move address to base
This commit is contained in:
parent
fe4e200dc0
commit
bbc7625550
22 changed files with 668 additions and 300 deletions
|
|
@ -1,3 +1,6 @@
|
|||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
from .models import UncloudNetwork
|
||||
|
||||
for m in [ UncloudNetwork ]:
|
||||
admin.site.register(m)
|
||||
|
|
|
|||
22
uncloud_net/migrations/0007_uncloudnetwork.py
Normal file
22
uncloud_net/migrations/0007_uncloudnetwork.py
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
# Generated by Django 3.1 on 2020-10-11 19:20
|
||||
|
||||
import django.core.validators
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('uncloud_net', '0006_auto_20200928_1858'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='UncloudNetwork',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('network_address', models.GenericIPAddressField()),
|
||||
('network_mask', models.IntegerField(validators=[django.core.validators.MinValueValidator(0), django.core.validators.MaxValueValidator(128)])),
|
||||
],
|
||||
),
|
||||
]
|
||||
18
uncloud_net/migrations/0008_auto_20201011_1924.py
Normal file
18
uncloud_net/migrations/0008_auto_20201011_1924.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 3.1 on 2020-10-11 19:24
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('uncloud_net', '0007_uncloudnetwork'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='uncloudnetwork',
|
||||
name='network_address',
|
||||
field=models.GenericIPAddressField(unique=True),
|
||||
),
|
||||
]
|
||||
19
uncloud_net/migrations/0009_uncloudnetwork_description.py
Normal file
19
uncloud_net/migrations/0009_uncloudnetwork_description.py
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
# Generated by Django 3.1 on 2020-10-11 19:24
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('uncloud_net', '0008_auto_20201011_1924'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='uncloudnetwork',
|
||||
name='description',
|
||||
field=models.CharField(default='', max_length=256),
|
||||
preserve_default=False,
|
||||
),
|
||||
]
|
||||
21
uncloud_net/migrations/0010_auto_20201011_2009.py
Normal file
21
uncloud_net/migrations/0010_auto_20201011_2009.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
# Generated by Django 3.1 on 2020-10-11 20:09
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('uncloud_net', '0009_uncloudnetwork_description'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='vpnnetworkreservation',
|
||||
name='extra_data',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='vpnpool',
|
||||
name='extra_data',
|
||||
),
|
||||
]
|
||||
|
|
@ -4,16 +4,49 @@ import ipaddress
|
|||
from django.db import models
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.core.validators import MinValueValidator, MaxValueValidator
|
||||
from django.core.exceptions import FieldError
|
||||
|
||||
class UncloudNetwork(models.Model):
|
||||
"""
|
||||
Storing IP networks
|
||||
"""
|
||||
|
||||
network_address = models.GenericIPAddressField(null=False, unique=True)
|
||||
network_mask = models.IntegerField(null=False,
|
||||
validators=[MinValueValidator(0),
|
||||
MaxValueValidator(128)]
|
||||
)
|
||||
|
||||
description = models.CharField(max_length=256)
|
||||
|
||||
@classmethod
|
||||
def populate_db_defaults(cls):
|
||||
for net, desc in [
|
||||
( "2a0a:e5c0:11::", "uncloud Billing" ),
|
||||
( "2a0a:e5c0:11:1::", "uncloud Referral" )
|
||||
]:
|
||||
obj, created = cls.objects.get_or_create(network_address=net,
|
||||
defaults= {
|
||||
'network_mask': 64,
|
||||
'description': desc
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
from uncloud_pay.models import Product, RecurringPeriod
|
||||
from uncloud.models import UncloudModel, UncloudStatus
|
||||
def save(self, *args, **kwargs):
|
||||
if not ':' in self.network_address and self.network_mask > 32:
|
||||
raise FieldError("Mask cannot exceed 32 for IPv4")
|
||||
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.network_address}/{self.network_mask} {self.description}"
|
||||
|
||||
class MACAdress(models.Model):
|
||||
default_prefix = 0x420000000000
|
||||
|
||||
class VPNPool(UncloudModel):
|
||||
class VPNPool(models.Model):
|
||||
"""
|
||||
Network address pools from which VPNs can be created
|
||||
"""
|
||||
|
|
@ -145,7 +178,7 @@ AllowedIPs = {peer_network}
|
|||
pass
|
||||
|
||||
|
||||
class VPNNetworkReservation(UncloudModel):
|
||||
class VPNNetworkReservation(models.Model):
|
||||
"""
|
||||
This class tracks the used VPN networks. It will be deleted, when the product is cancelled.
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -3,13 +3,20 @@ from rest_framework.test import APIRequestFactory, force_authenticate
|
|||
|
||||
from rest_framework.reverse import reverse
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.core.exceptions import ValidationError, FieldError
|
||||
|
||||
from .views import *
|
||||
from .models import *
|
||||
|
||||
from uncloud_pay.models import BillingAddress, Order
|
||||
|
||||
|
||||
class UncloudNetworkTests(TestCase):
|
||||
def test_invalid_IPv4_network(self):
|
||||
with self.assertRaises(FieldError):
|
||||
UncloudNetwork.objects.create(network_address="192.168.1.0",
|
||||
network_mask=33)
|
||||
|
||||
class VPNTests(TestCase):
|
||||
def setUp(self):
|
||||
self.user = get_user_model().objects.create_user('django-test-user', 'noreply@ungleich.ch')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue