29 |
29 |
30 yield pvl.dns.ZoneRecord.CNAME(label, forward) |
30 yield pvl.dns.ZoneRecord.CNAME(label, forward) |
31 |
31 |
32 elif host.forward is None: |
32 elif host.forward is None: |
33 # forward |
33 # forward |
34 if host.ip : |
34 for sublabel, (ip4, ip6) in host.ip.iteritems(): |
35 log.info("%s: ip: %s@%s A %s", host, label, origin, host.ip) |
35 if sublabel: |
36 |
36 sublabel = pvl.dns.join(sublabel, label) |
37 yield pvl.dns.ZoneRecord.A(label, host.ip) |
37 else: |
38 |
38 sublabel = label |
39 if host.ip6 : |
39 |
40 log.info("%s: ip6: %s@%s AAAA %s", host, label, origin, host.ip6) |
40 if ip4: |
41 |
41 log.info("%s: ip: %s@%s A %s", host, sublabel, origin, ip4) |
42 yield pvl.dns.ZoneRecord.AAAA(label, host.ip6) |
42 |
|
43 yield pvl.dns.ZoneRecord.A(sublabel, ip4) |
|
44 |
|
45 if ip6: |
|
46 log.info("%s: ip6: %s@%s AAAA %s", host, label, origin, ip6) |
|
47 |
|
48 yield pvl.dns.ZoneRecord.AAAA(sublabel, ip6) |
43 |
49 |
44 else: |
50 else: |
45 log.info("%s: skip forward", host) |
51 log.info("%s: skip forward", host) |
46 return |
52 return |
47 |
53 |
55 |
61 |
56 for alias in host.alias: |
62 for alias in host.alias: |
57 yield pvl.dns.ZoneRecord.CNAME(pvl.dns.relative(origin, host.domain, alias), label) |
63 yield pvl.dns.ZoneRecord.CNAME(pvl.dns.relative(origin, host.domain, alias), label) |
58 |
64 |
59 for alias in host.alias4: |
65 for alias in host.alias4: |
60 if not host.ip: |
66 if not host.ip4: |
61 raise HostZoneError(host, "alias4={host.alias4} without ip=".format(host=host)) |
67 raise HostZoneError(host, "alias4={host.alias4} without ip4=".format(host=host)) |
62 |
68 |
63 yield pvl.dns.ZoneRecord.A(pvl.dns.relative(origin, host.domain, alias), host.ip) |
69 yield pvl.dns.ZoneRecord.A(pvl.dns.relative(origin, host.domain, alias), host.ip4) |
64 |
70 |
65 for alias in host.alias6: |
71 for alias in host.alias6: |
66 if not host.ip6: |
72 if not host.ip6: |
67 raise HostZoneError(host, "alias6={host.alias6} without ip6=".format(host=host)) |
73 raise HostZoneError(host, "alias6={host.alias6} without ip6=".format(host=host)) |
68 |
74 |
70 |
76 |
71 def host_reverse (host, prefix) : |
77 def host_reverse (host, prefix) : |
72 """ |
78 """ |
73 Yield (ipaddr.IPAddress, ZoneRecord) tuples for host within given prefix's reverse-dns zone. |
79 Yield (ipaddr.IPAddress, ZoneRecord) tuples for host within given prefix's reverse-dns zone. |
74 """ |
80 """ |
75 |
81 |
76 if prefix.version == 4 : |
82 for sublabel, (ip4, ip6) in host.ip.iteritems(): |
77 ip = host.ip |
83 if prefix.version == 4: |
|
84 ip = ip4 |
|
85 |
|
86 # reverse= is IPv4-only |
|
87 reverse = host.reverse |
|
88 |
|
89 elif prefix.version == 6: |
|
90 ip = ip6 |
|
91 |
|
92 # if reverse= is set, always omit, for lack of reverse6= |
|
93 reverse = None if host.reverse is None else False |
|
94 |
|
95 else: |
|
96 raise ValueError("%s: unknown ip version: %s" % (prefix, prefix.version)) |
|
97 |
|
98 if not ip: |
|
99 log.debug("%s: no ip%d", host, prefix.version) |
|
100 continue |
|
101 |
|
102 if ip not in prefix: |
|
103 log.debug("%s: %s out of prefix: %s", host, ip, prefix) |
|
104 continue |
78 |
105 |
79 # reverse= is IPv4-only |
106 # relative label |
80 reverse = host.reverse |
107 label = pvl.dns.reverse_label(prefix, ip) |
81 |
108 |
82 elif prefix.version == 6 : |
109 if reverse: |
83 ip = host.ip6 |
110 alias = pvl.dns.fqdn(reverse) |
84 |
111 |
85 # if reverse= is set, always omit, for lack of reverse6= |
112 log.info("%s %s[%s]: CNAME %s", host, prefix, ip, alias) |
86 reverse = None if host.reverse is None else False |
113 |
87 |
114 yield ip, pvl.dns.zone.ZoneRecord.CNAME(label, alias) |
88 else : |
115 |
89 raise ValueError("%s: unknown ip version: %s" % (prefix, prefix.version)) |
116 elif reverse is None: |
90 |
117 fqdn = host.fqdn() |
91 if not ip : |
118 |
92 log.debug("%s: no ip%d", host, prefix.version) |
119 if sublabel: |
93 return |
120 fqdn = pvl.dns.join(sublabel, fqdn) |
94 |
121 |
95 if ip not in prefix : |
122 log.info("%s %s[%s]: PTR %s", host, prefix, ip, fqdn) |
96 log.debug("%s: %s out of prefix: %s", host, ip, prefix) |
123 |
97 return |
124 yield ip, pvl.dns.zone.ZoneRecord.PTR(label, fqdn) |
98 |
125 |
99 # relative label |
126 else: |
100 label = pvl.dns.reverse_label(prefix, ip) |
127 log.info("%s %s[%s]: omit", host, prefix, ip) |
101 |
128 |
102 if reverse: |
|
103 alias = pvl.dns.fqdn(reverse) |
|
104 |
|
105 log.info("%s %s[%s]: CNAME %s", host, prefix, ip, alias) |
|
106 |
|
107 yield ip, pvl.dns.zone.ZoneRecord.CNAME(label, alias) |
|
108 |
|
109 elif reverse is None : |
|
110 fqdn = host.fqdn() |
|
111 |
|
112 log.info("%s %s[%s]: PTR %s", host, prefix, ip, fqdn) |
|
113 |
|
114 yield ip, pvl.dns.zone.ZoneRecord.PTR(label, fqdn) |
|
115 |
|
116 else: |
|
117 log.info("%s %s[%s]: omit", host, prefix, ip) |
|
118 |
|
119 def apply_hosts_forward (hosts, origin, |
129 def apply_hosts_forward (hosts, origin, |
120 add_origin = False, |
130 add_origin = False, |
121 check_conflicts = False, |
131 check_conflicts = False, |
122 ) : |
132 ) : |
123 """ |
133 """ |