mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-22 19:33:11 +00:00
Generation des entrées dns dans models
This commit is contained in:
parent
918d427b60
commit
d25ae29736
2 changed files with 42 additions and 10 deletions
|
@ -145,6 +145,10 @@ class Extension(models.Model):
|
|||
need_infra = models.BooleanField(default=False)
|
||||
origin = models.OneToOneField('IpList', on_delete=models.PROTECT, blank=True, null=True)
|
||||
|
||||
@cached_property
|
||||
def dns_entry(self):
|
||||
return "@ IN A " + str(self.origin)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
@ -155,6 +159,10 @@ class Mx(models.Model):
|
|||
priority = models.IntegerField(unique=True)
|
||||
name = models.OneToOneField('Domain', on_delete=models.PROTECT)
|
||||
|
||||
@cached_property
|
||||
def dns_entry(self):
|
||||
return "@ IN MX " + str(self.priority) + " " + str(self.name)
|
||||
|
||||
def __str__(self):
|
||||
return str(self.zone) + ' ' + str(self.priority) + ' ' + str(self.name)
|
||||
|
||||
|
@ -164,6 +172,10 @@ class Ns(models.Model):
|
|||
zone = models.ForeignKey('Extension', on_delete=models.PROTECT)
|
||||
ns = models.OneToOneField('Domain', on_delete=models.PROTECT)
|
||||
|
||||
@cached_property
|
||||
def dns_entry(self):
|
||||
return "@ IN NS " + str(self.ns)
|
||||
|
||||
def __str__(self):
|
||||
return str(self.zone) + ' ' + str(self.ns)
|
||||
|
||||
|
@ -274,6 +286,10 @@ class Domain(models.Model):
|
|||
self.validate_unique()
|
||||
super(Domain, self).clean()
|
||||
|
||||
@cached_property
|
||||
def dns_entry(self):
|
||||
if self.cname:
|
||||
return str(self.name) + " IN CNAME " + str(self.cname)
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if not self.get_extension():
|
||||
|
|
|
@ -68,35 +68,43 @@ class TypeSerializer(serializers.ModelSerializer):
|
|||
|
||||
class ExtensionSerializer(serializers.ModelSerializer):
|
||||
origin = serializers.SerializerMethodField('get_origin_ip')
|
||||
zone_entry = serializers.SerializerMethodField('get_zone_name')
|
||||
|
||||
class Meta:
|
||||
model = Extension
|
||||
fields = ('name', 'origin')
|
||||
fields = ('name', 'origin', 'zone_entry')
|
||||
|
||||
def get_origin_ip(self, obj):
|
||||
return obj.origin.ipv4
|
||||
|
||||
def get_zone_name(self, obj):
|
||||
return str(obj.dns_entry)
|
||||
|
||||
class MxSerializer(serializers.ModelSerializer):
|
||||
name = serializers.SerializerMethodField('get_mx_name')
|
||||
name = serializers.SerializerMethodField('get_entry_name')
|
||||
zone = serializers.SerializerMethodField('get_zone_name')
|
||||
mx_entry = serializers.SerializerMethodField('get_mx_name')
|
||||
|
||||
class Meta:
|
||||
model = Mx
|
||||
fields = ('zone', 'priority', 'name')
|
||||
fields = ('zone', 'priority', 'name', 'mx_entry')
|
||||
|
||||
def get_mx_name(self, obj):
|
||||
def get_entry_name(self, obj):
|
||||
return str(obj.name)
|
||||
|
||||
def get_zone_name(self, obj):
|
||||
return obj.zone.name
|
||||
|
||||
def get_mx_name(self, obj):
|
||||
return str(obj.dns_entry)
|
||||
|
||||
class TextSerializer(serializers.ModelSerializer):
|
||||
zone = serializers.SerializerMethodField('get_zone_name')
|
||||
text = serializers.SerializerMethodField('get_text_name')
|
||||
text_entry = serializers.SerializerMethodField('get_text_name')
|
||||
|
||||
class Meta:
|
||||
model = Text
|
||||
fields = ('zone','text')
|
||||
fields = ('zone','text_entry','field1', 'field2')
|
||||
|
||||
def get_zone_name(self, obj):
|
||||
return str(obj.zone.name)
|
||||
|
@ -107,10 +115,11 @@ class TextSerializer(serializers.ModelSerializer):
|
|||
class NsSerializer(serializers.ModelSerializer):
|
||||
zone = serializers.SerializerMethodField('get_zone_name')
|
||||
ns = serializers.SerializerMethodField('get_domain_name')
|
||||
ns_entry = serializers.SerializerMethodField('get_text_name')
|
||||
|
||||
class Meta:
|
||||
model = Ns
|
||||
fields = ('zone', 'ns')
|
||||
fields = ('zone', 'ns', 'ns_entry')
|
||||
|
||||
def get_zone_name(self, obj):
|
||||
return obj.zone.name
|
||||
|
@ -118,20 +127,27 @@ class NsSerializer(serializers.ModelSerializer):
|
|||
def get_domain_name(self, obj):
|
||||
return str(obj.ns)
|
||||
|
||||
def get_text_name(self, obj):
|
||||
return str(obj.dns_entry)
|
||||
|
||||
class DomainSerializer(serializers.ModelSerializer):
|
||||
extension = serializers.SerializerMethodField('get_zone_name')
|
||||
cname = serializers.SerializerMethodField('get_cname_name')
|
||||
cname = serializers.SerializerMethodField('get_alias_name')
|
||||
cname_entry = serializers.SerializerMethodField('get_cname_name')
|
||||
|
||||
class Meta:
|
||||
model = Domain
|
||||
fields = ('name', 'extension', 'cname')
|
||||
fields = ('name', 'extension', 'cname', 'cname_entry')
|
||||
|
||||
def get_zone_name(self, obj):
|
||||
return obj.extension.name
|
||||
|
||||
def get_cname_name(self, obj):
|
||||
def get_alias_name(self, obj):
|
||||
return str(obj.cname)
|
||||
|
||||
def get_cname_name(self, obj):
|
||||
return str(obj.dns_entry)
|
||||
|
||||
class ServiceServersSerializer(serializers.ModelSerializer):
|
||||
server = serializers.SerializerMethodField('get_server_name')
|
||||
service = serializers.SerializerMethodField('get_service_name')
|
||||
|
|
Loading…
Reference in a new issue