restructure to move uncloudnetwork into core
This commit is contained in:
parent
8959bc6ad5
commit
20c7c86703
8 changed files with 130 additions and 47 deletions
|
|
@ -6,43 +6,6 @@ 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" ),
|
||||
( "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):
|
||||
default_prefix = 0x420000000000
|
||||
|
|
@ -219,3 +182,15 @@ class VPNNetwork(models.Model):
|
|||
self.network.save()
|
||||
super().save(*args, **kwargs)
|
||||
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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue