115 |
115 |
116 else: |
116 else: |
117 log.info("%s %s[%s]: omit", host, prefix, ip) |
117 log.info("%s %s[%s]: omit", host, prefix, ip) |
118 |
118 |
119 def apply_hosts_forward (hosts, origin, |
119 def apply_hosts_forward (hosts, origin, |
120 add_origin = False, |
120 add_origin = False, |
|
121 check_conflicts = False, |
121 ) : |
122 ) : |
122 """ |
123 """ |
123 Generate DNS ZoneRecords for for hosts within the given zone origin. |
124 Generate DNS ZoneRecords for for hosts within the given zone origin. |
124 |
125 |
125 Verifies that there are no overlapping name/type records, or CNAME records from aliases. |
126 Verifies that there are no overlapping name/type records, or CNAME records from aliases. |
126 |
127 |
127 hosts: [Host] - Host's to render |
128 hosts: [Host] - Host's to render |
128 origin: str - generate records relative to given zone origin |
129 origin: str - generate records relative to given zone origin |
129 add_origin: bool - generate an explicit $ORIGIN directive |
130 add_origin: bool - generate an explicit $ORIGIN directive |
|
131 check_conflits: bool- raise HostZoneError on dupliate records for the same name/type |
|
132 overlapping CNAME records will always raise |
130 |
133 |
131 Yields ZoneRecords in Host-order |
134 Yields ZoneRecords in Host-order |
132 """ |
135 """ |
133 |
136 |
134 if add_origin: |
137 if add_origin: |
141 for rr in host_forward(host, origin) : |
144 for rr in host_forward(host, origin) : |
142 if (rr.name, 'CNAME') in by_name_type: |
145 if (rr.name, 'CNAME') in by_name_type: |
143 raise HostZoneError(host, u"{cname} CNAME conflict with {other}".format(cname=rr.name, other=by_name_type[rr.name, 'CNAME'])) |
146 raise HostZoneError(host, u"{cname} CNAME conflict with {other}".format(cname=rr.name, other=by_name_type[rr.name, 'CNAME'])) |
144 elif rr.type == 'CNAME' and rr.name in by_name: |
147 elif rr.type == 'CNAME' and rr.name in by_name: |
145 raise HostZoneError(host, u"{cname} CNAME conflict with {other}".format(cname=rr.name, other=by_name[rr.name])) |
148 raise HostZoneError(host, u"{cname} CNAME conflict with {other}".format(cname=rr.name, other=by_name[rr.name])) |
146 elif (rr.name, rr.type) in by_name_type: |
149 elif check_conflicts and (rr.name, rr.type) in by_name_type: |
147 raise HostZoneError(host, u"{name} {type} conflict with {other}".format(type=rr.type, name=rr.name, other=by_name_type[rr.name, rr.type])) |
150 raise HostZoneError(host, u"{name} {type} conflict with {other}".format(type=rr.type, name=rr.name, other=by_name_type[rr.name, rr.type])) |
148 |
151 |
149 by_name[rr.name] = host |
152 by_name[rr.name] = host |
150 by_name_type[rr.name, rr.type] = host |
153 by_name_type[rr.name, rr.type] = host |
151 |
154 |