restructure to move uncloudnetwork into core
This commit is contained in:
parent
8959bc6ad5
commit
20c7c86703
8 changed files with 130 additions and 47 deletions
|
@ -1,6 +1,6 @@
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
|
||||||
from .models import UncloudProvider
|
from .models import UncloudProvider, UncloudNetwork
|
||||||
|
|
||||||
for m in [ UncloudProvider ]:
|
for m in [ UncloudProvider, UncloudNetwork ]:
|
||||||
admin.site.register(m)
|
admin.site.register(m)
|
||||||
|
|
|
@ -7,8 +7,7 @@ from django.contrib.auth import get_user_model
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
from uncloud_pay.models import BillingAddress, RecurringPeriod, Product
|
from uncloud_pay.models import BillingAddress, RecurringPeriod, Product
|
||||||
from uncloud_net.models import UncloudNetwork
|
from uncloud.models import UncloudProvider, UncloudNetwork
|
||||||
from uncloud.models import UncloudProvider
|
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
|
|
40
uncloud/migrations/0006_auto_20201025_1931.py
Normal file
40
uncloud/migrations/0006_auto_20201025_1931.py
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
# Generated by Django 3.1 on 2020-10-25 19:31
|
||||||
|
|
||||||
|
import django.core.validators
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('uncloud', '0005_uncloudprovider_coupon_network'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='UncloudNetwork',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('network_address', models.GenericIPAddressField(unique=True)),
|
||||||
|
('network_mask', models.IntegerField(validators=[django.core.validators.MinValueValidator(0), django.core.validators.MaxValueValidator(128)])),
|
||||||
|
('description', models.CharField(max_length=256)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='uncloudprovider',
|
||||||
|
name='billing_network',
|
||||||
|
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='uncloudproviderbill', to='uncloud.uncloudnetwork'),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='uncloudprovider',
|
||||||
|
name='coupon_network',
|
||||||
|
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='uncloudprovidercoupon', to='uncloud.uncloudnetwork'),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='uncloudprovider',
|
||||||
|
name='referral_network',
|
||||||
|
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='uncloudproviderreferral', to='uncloud.uncloudnetwork'),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
2
|
|
@ -2,10 +2,9 @@ from django.db import models
|
||||||
from django.db.models import JSONField, Q
|
from django.db.models import JSONField, Q
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
from django.core.validators import MinValueValidator, MaxValueValidator
|
||||||
|
|
||||||
from uncloud import COUNTRIES
|
from uncloud import COUNTRIES
|
||||||
from uncloud_net.models import UncloudNetwork
|
|
||||||
|
|
||||||
|
|
||||||
class UncloudModel(models.Model):
|
class UncloudModel(models.Model):
|
||||||
"""
|
"""
|
||||||
|
@ -66,6 +65,48 @@ class UncloudAddress(models.Model):
|
||||||
class Meta:
|
class Meta:
|
||||||
abstract = True
|
abstract = True
|
||||||
|
|
||||||
|
|
||||||
|
###
|
||||||
|
# UncloudNetworks are used as identifiers - such they are a base of uncloud
|
||||||
|
|
||||||
|
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" ),
|
||||||
|
( "2a0a:e5c0:11:2::", "uncloud Coupon" )
|
||||||
|
]:
|
||||||
|
obj, created = cls.objects.get_or_create(network_address=net,
|
||||||
|
defaults= {
|
||||||
|
'network_mask': 64,
|
||||||
|
'description': desc
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
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}"
|
||||||
|
|
||||||
###
|
###
|
||||||
# Who is running / providing this instance of uncloud?
|
# Who is running / providing this instance of uncloud?
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
|
||||||
from .models import UncloudNetwork
|
|
||||||
|
|
||||||
for m in [ UncloudNetwork ]:
|
# for m in [ UncloudNetwork ]:
|
||||||
admin.site.register(m)
|
# admin.site.register(m)
|
||||||
|
|
29
uncloud_net/migrations/0011_auto_20201025_1931.py
Normal file
29
uncloud_net/migrations/0011_auto_20201025_1931.py
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
# Generated by Django 3.1 on 2020-10-25 19:31
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||||
|
('uncloud', '0006_auto_20201025_1931'),
|
||||||
|
('uncloud_net', '0010_auto_20201011_2009'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='ReverseDNSEntry',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('ip_address', models.GenericIPAddressField(unique=True)),
|
||||||
|
('name', models.CharField(max_length=253)),
|
||||||
|
('owner', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.DeleteModel(
|
||||||
|
name='UncloudNetwork',
|
||||||
|
),
|
||||||
|
]
|
|
@ -6,43 +6,6 @@ from django.contrib.auth import get_user_model
|
||||||
from django.core.validators import MinValueValidator, MaxValueValidator
|
from django.core.validators import MinValueValidator, MaxValueValidator
|
||||||
from django.core.exceptions import FieldError
|
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" ),
|
|
||||||
( "2a0a:e5c0:11:2::", "uncloud Coupon" )
|
|
||||||
]:
|
|
||||||
obj, created = cls.objects.get_or_create(network_address=net,
|
|
||||||
defaults= {
|
|
||||||
'network_mask': 64,
|
|
||||||
'description': desc
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
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):
|
class MACAdress(models.Model):
|
||||||
default_prefix = 0x420000000000
|
default_prefix = 0x420000000000
|
||||||
|
@ -219,3 +182,15 @@ class VPNNetwork(models.Model):
|
||||||
self.network.save()
|
self.network.save()
|
||||||
super().save(*args, **kwargs)
|
super().save(*args, **kwargs)
|
||||||
print("deleted {}".format(self))
|
print("deleted {}".format(self))
|
||||||
|
|
||||||
|
|
||||||
|
class ReverseDNSEntry(models.Model):
|
||||||
|
"""
|
||||||
|
A reverse DNS entry
|
||||||
|
"""
|
||||||
|
owner = models.ForeignKey(get_user_model(),
|
||||||
|
on_delete=models.CASCADE)
|
||||||
|
|
||||||
|
ip_address = models.GenericIPAddressField(null=False, unique=True)
|
||||||
|
|
||||||
|
name = models.CharField(max_length=253, null=False)
|
||||||
|
|
|
@ -1061,7 +1061,7 @@ class Bill(models.Model):
|
||||||
provider = UncloudProvider.objects.get()
|
provider = UncloudProvider.objects.get()
|
||||||
|
|
||||||
# Assume always VAT inside the country
|
# Assume always VAT inside the country
|
||||||
if provider.country = self.billing_address.country:
|
if provider.country == self.billing_address.country:
|
||||||
vat_rate = VATRate.objects.get(country=provider.country,
|
vat_rate = VATRate.objects.get(country=provider.country,
|
||||||
when=self.ending_date)
|
when=self.ending_date)
|
||||||
elif self.billing_address.country in EU:
|
elif self.billing_address.country in EU:
|
||||||
|
|
Loading…
Reference in a new issue