dnmgmt/domains/models.py

72 lines
1.9 KiB
Python
Raw Normal View History

2017-03-14 20:18:57 +01:00
from django.db import models
from django.urls import reverse
from whoisdb.models import MntdObject, Contact, InetNum
# generally allow domains for .dn to be created
# allow owners of a subnet to create reverse dns record?
2017-03-15 02:22:08 +01:00
2017-03-14 20:18:57 +01:00
class Nameserver(MntdObject):
handleSuffix = "NS"
# dns name
# ip address, if glue
# ipv4/ipv6 address?
handle = None
name = models.CharField(max_length=256, unique=True)
glueIPv4 = models.GenericIPAddressField(protocol='IPv4', blank=True, null=True)
glueIPv6 = models.GenericIPAddressField(protocol='IPv6', blank=True, null=True)
admin_c = models.ManyToManyField(Contact)
def get_absolute_url(self):
return reverse("domains:nameserver-show", args=(self.name,))
def __str__(self):
return self.name
2017-03-15 02:22:08 +01:00
2017-03-14 20:18:57 +01:00
class Domain(MntdObject):
handle = None
handleSuffix = "DOM"
name = models.CharField(max_length=67, unique=True, db_index=True)
nameservers = models.ManyToManyField(Nameserver, blank=True)
admin_c = models.ManyToManyField(Contact)
def get_absolute_url(self):
return reverse("domains:domain-show", args=(self.name,))
def __str__(self):
return self.name
2017-03-15 02:22:08 +01:00
def getNoDeleteReasons(self):
reasons = []
nameservers = Nameserver.objects.filter(name__endswith="." + self.name)
for ns in nameservers:
reasons.append("Nameserver %s depends on this domain" % ns.name)
return reasons
2017-03-14 20:18:57 +01:00
#class NameserverDomainAssignment(models.Model):
# domain = models.ForeignKey(Domain)
# nameserver = models.ForeignKey(Nameserver)
#
# order = models.PositiveSmallIntegerField(default=0)
2017-03-15 02:22:08 +01:00
2017-03-14 20:18:57 +01:00
class ReverseZone(models.Model):
parentNet = models.ForeignKey(InetNum)
address = models.GenericIPAddressField(db_index=True)
netmask = models.PositiveIntegerField()
2017-03-15 02:22:08 +01:00
nameservers = models.ManyToManyField(Nameserver)
2017-03-14 20:18:57 +01:00
#class NameserverReverseZoneAssignment(models.Model):
# reversezone = models.ForeignKey(ReverseZone)
# nameserver = models.ForeignKey(Nameserver)
#
# order = models.PositiveSmallIntegerField()