diff --git a/gestion/gen_confs/bind.py b/gestion/gen_confs/bind.py index 062b90a1..112d0457 100755 --- a/gestion/gen_confs/bind.py +++ b/gestion/gen_confs/bind.py @@ -230,6 +230,17 @@ class Zone(ZoneBase): else: return None + def get_name_vi(self, nom, i): + if not i in [4, 6]: + raise ValueError("i should be 4 or 6") + if nom == '@': + return 'v%s' % i + elif '.' in nom: + nom_1, nom_2 = nom.split('.', 1) + return "%s.v%s.%s" % (nom_1, i, nom_2) + else: + return "%s.v%s" % (nom, i) + def add_delegation(zone, server): zone = self.het_name(zone) if zone: @@ -240,10 +251,7 @@ class Zone(ZoneBase): for ip in machine.get('ipHostNumber', []): self.add(A(nom, ip)) if self.ipv6: - if nom == '@': - self.add(A("v4", ip)) - else: - self.add(A("%s.v4" % nom, ip)) + self.add(A(self.get_name_vi(nom, 4), ip)) def add_aaaa_record(self, nom, machine): if self.ipv6: @@ -251,10 +259,7 @@ class Zone(ZoneBase): if machine.get('dnsIpv6', [True])[0]: self.add(AAAA(nom, ip)) if self.ipv4: - if nom == '@': - self.add(AAAA("v6", ip)) - else: - self.add(AAAA("%s.v6" % nom, ip)) + self.add(AAAA(self.get_name_vi(nom, 6), ip)) def add_sshfp_record(self, nom, machine): for sshkey in machine.get('sshFingerprint', []): @@ -264,12 +269,8 @@ class Zone(ZoneBase): for hash in config.sshfp_hash.keys(): self.add(SSHFP(nom, hash, algo, key)) if self.ipv4 and self.ipv6: - if nom == '@': - self.add(SSHFP("v4", hash, algo, key)) - self.add(SSHFP("v6", hash, algo, key)) - else: - self.add(SSHFP("%s.v4" % nom, hash, algo, key)) - self.add(SSHFP("%s.v6" % nom, hash, algo, key)) + self.add(SSHFP(self.get_name_vi(nom, 4), hash, algo, key)) + self.add(SSHFP(self.get_name_vi(nom, 6), hash, algo, key)) # KeyError is l'algo dans ldap n'est pas connu # TypeError si la clef n'est pas bien en base64 except (KeyError, TypeError): @@ -303,16 +304,16 @@ class Zone(ZoneBase): continue alias = self.get_name(alias) if alias is None: continue - to_nom, to_zone = str(machine['host'][0]).split('.', 1) + to_nom = self.get_name(machine['host'][0]) if alias in ['@', '%s.' % self.zone_name]: self.add_a_record(alias, machine) self.add_aaaa_record(alias, machine) self.add_sshfp_record(alias, machine) - elif to_zone == self.zone_name: + elif to_nom: self.add(CNAME(alias, "%s" % to_nom)) if self.ipv4 and self.ipv6: - self.add(CNAME("%s.v4" % alias, "%s.v4" % to_nom)) - self.add(CNAME("%s.v6" % alias, "%s.v6" % to_nom)) + self.add(CNAME(self.get_name_vi(alias, 6), self.get_name_vi(to_nom, 6))) + self.add(CNAME(self.get_name_vi(alias, 4), self.get_name_vi(to_nom, 4))) else: self.add(CNAME(alias, "%s." % machine['host'][0]))