diff --git a/src/hostinfo/named.py b/src/hostinfo/named.py index c7ad2ff4ed476fc54e44e5f3bb0d44deca4e2c58..1c8432ed048a3e7a6876b0a68dc09dc752bddc68 100755 --- a/src/hostinfo/named.py +++ b/src/hostinfo/named.py @@ -31,7 +31,7 @@ def generate(tree, options): pass # - # C. Create reverse mapping for localhost + # C. Create reverse mapping for host # result = [] @@ -141,7 +141,7 @@ class DomainDict: def add_host(self, name, kind, value): if not re.match('^[0-9a-zA-Z.-]+$', name): - raise Exception('Invalid nameserver name "%s"' % name) + raise Exception('Invalid host name "%s"' % name) if not name in self.host: self.host[name] = set() pass @@ -203,17 +203,28 @@ def generate_forward(tree, hosts): result[c.domain[1]].add_host(c.alias[0], 'CNAME', c.name[0]) pass # Add numbered hosts + def add_host(domain, name, address): + if address.version == 4: + result[domain].add_host(name, 'A', str(address.exploded)) + pass + elif address.version == 6: + result[domain].add_host(name, 'AAAA', str(address.exploded)) + pass + for domain,net in [ (s.domain[0],util.network(s)) for s in tree._subnet_ if s.domain[0] and util.network(s)]: for name,address in hosts: + try: + if name.endswith('.'): + d = '.'.join(name.split('.')[1:-1]) + n = name.split('.')[0] + add_host(d, n, address) + continue + except Exception,e: + pass if address in net: - if address.version == 4: - result[domain].add_host(name, 'A', str(address.exploded)) - pass - elif address.version == 6: - result[domain].add_host(name, 'AAAA', str(address.exploded)) - pass + add_host(domain, name,address) pass pass pass