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