From e4f975e18ab739ec951fd2e94f533141b2e690b5 Mon Sep 17 00:00:00 2001 From: Maxime Bombar Date: Fri, 2 Nov 2018 15:04:37 +0100 Subject: [PATCH] Handles DNAME records --- api/serializers.py | 14 +++++++++++++- machines/models.py | 3 +++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/api/serializers.py b/api/serializers.py index f520cf98..c0136c35 100644 --- a/api/serializers.py +++ b/api/serializers.py @@ -1001,6 +1001,17 @@ class CNAMERecordSerializer(serializers.ModelSerializer): model = machines.Domain fields = ('alias', 'hostname') +class DNAMERecordSerializer(serializers.ModelSerializer): + """Serialize `machines.models.Domain` objects with the data needed to + generate a DNAME DNS record. + """ + alias = serializers.CharField(read_only=True) + zone = serializers.CharField(read_only=True) + + class Meta: + model = machines.DName + fields = ('alias', 'zone') + class DNSZonesSerializer(serializers.ModelSerializer): """Serialize the data about DNS Zones. @@ -1015,13 +1026,14 @@ class DNSZonesSerializer(serializers.ModelSerializer): a_records = ARecordSerializer(many=True, source='get_associated_a_records') aaaa_records = AAAARecordSerializer(many=True, source='get_associated_aaaa_records') cname_records = CNAMERecordSerializer(many=True, source='get_associated_cname_records') + dname_records = DNAMERecordSerializer(many=True, source='get_associated_dname_records') sshfp_records = SSHFPInterfaceSerializer(many=True, source='get_associated_sshfp_records') class Meta: model = machines.Extension fields = ('name', 'soa', 'ns_records', 'originv4', 'originv6', 'mx_records', 'txt_records', 'srv_records', 'a_records', - 'aaaa_records', 'cname_records', 'sshfp_records') + 'aaaa_records', 'cname_records', 'dname_records', 'sshfp_records') #REMINDER diff --git a/machines/models.py b/machines/models.py index 8db0c9d8..2281b3d3 100644 --- a/machines/models.py +++ b/machines/models.py @@ -741,6 +741,9 @@ class Extension(RevMixin, AclMixin, models.Model): .filter(cname__interface_parent__in=all_active_assigned_interfaces()) .prefetch_related('cname')) + def get_associated_dname_records(self): + return (DName.objects.filter(alias=self)) + @staticmethod def can_use_all(user_request, *_args, **_kwargs): """Superdroit qui permet d'utiliser toutes les extensions sans