本文整理汇总了Python中AutoNetkit.dns_hiearchy_parents方法的典型用法代码示例。如果您正苦于以下问题:Python AutoNetkit.dns_hiearchy_parents方法的具体用法?Python AutoNetkit.dns_hiearchy_parents怎么用?Python AutoNetkit.dns_hiearchy_parents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AutoNetkit
的用法示例。
在下文中一共展示了AutoNetkit.dns_hiearchy_parents方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: configure_dns
# 需要导入模块: import AutoNetkit [as 别名]
# 或者: from AutoNetkit import dns_hiearchy_parents [as 别名]
#.........这里部分代码省略.........
named_list = []
advertise_links = list(ank.advertise_links(server))
advertise_hosts = list(ank.dns_auth_children(server))
LOG.debug("DNS server %s advertises %s" % (server, advertise_links))
#TODO: make reverse dns handle domains other than /8 /16 /24
advertise_block = ip_as_allocs[server.asn]
# remove trailing fullstop
reverse_identifier = ank.rev_dns_identifier(advertise_block).rstrip(".")
#TODO: look at using advertise_block.network.reverse_dns - check what Bind needs
named_list.append(reverse_identifier)
f_named = open( os.path.join(bind_dir(self.network, server), "named.conf"), 'wb')
f_named.write(named_template.render(
domain = server.domain,
entry_list = named_list,
bind_dir = linux_bind_dir,
logging = False,
))
f_named.close()
for_entry_list = list( (self.interface_id(link.id), link.local_host.dns_host_portion_only, link.ip)
for link in advertise_links)
# Add loopbacks for routers
for_entry_list += ( (self.lo_interface(0), host.dns_host_portion_only, host.lo_ip.ip)
#TODO: make thise check l3 group rather than asn (generalise)
for host in advertise_hosts if host.is_router and host.asn == server.asn)
rev_entry_list = list(
(ank.reverse_subnet(link.ip, advertise_block.prefixlen), self.interface_id(link.id), link.local_host.dns_hostname)
for link in advertise_links)
# Add loopbacks for routers
rev_entry_list += ( (ank.reverse_subnet(host.lo_ip.ip, advertise_block.prefixlen), self.lo_interface(0), host.dns_host_portion_only)
#TODO: make thise check l3 group rather than asn (generalise)
for host in advertise_hosts if host.is_router and host.asn == server.asn)
#TODO: provide better way to get eg eth0.host than string concat inside the template
host_cname_list = []
for host in advertise_hosts:
if host.asn != server.asn:
# host is from another asn, skip.
#TODO: extend this to make sure matches same asn, l3group and l2group
continue
if host.is_router:
# has lo_ip
cname = "%s.%s" % (self.lo_interface(), host.dns_host_portion_only)
else:
# choose an interface - arbitrary choice, choose first host link
interface = self.interface_id(ank.server_interface_id(host))
cname = "%s.%s" % (interface, host.dns_host_portion_only)
host_cname_list.append( (host.dns_host_portion_only, cname))
#Sort to make format nicer
host_cname_list = sorted(host_cname_list, key = lambda x: x[1])
for_entry_list = sorted(for_entry_list)
for_entry_list = sorted(for_entry_list, key = lambda x: x[1])
f_forward = open ( os.path.join(bind_dir(self.network, server), "db.%s" % server.domain), 'wb')
f_forward.write(forward_template.render(
domain = server.domain,
entry_list = for_entry_list,
host_cname_list = host_cname_list,
dns_server = server.dns_hostname,
dns_server_ip = ank.server_ip(server),
))
f_reverse = open(os.path.join(bind_dir(self.network, server), "db.%s" % reverse_identifier), 'wb')
f_reverse.write(reverse_template.render(
domain = server.domain,
identifier = reverse_identifier,
entry_list = rev_entry_list,
dns_server= server.dns_hostname,
))
#TODO: make l2 use l3 for caching
#TODO: ROOT-SERVER can't be part of a domain... - need to correctly handle case of multiple root servers
# and also need to handle this for case of single root server (ie no hiearchy) probably ok as /etc/resolv.conf points to server itself, not through dns hints
root_db_hint = ( ("ROOT-SERVER", ank.server_ip(n)) for n in ank.dns_hiearchy_parents(server))
f_root = open( os.path.join(bind_dir(self.network, server), "db.root"), 'wb')
f_root.write( root_template.render( root_servers = root_db_hint))
for server in dns_servers:
f_resolv = open( os.path.join(etc_dir(self.network, server), "resolv.conf"), 'wb')
f_resolv.write ( resolve_template.render(
nameservers = [ank.server_ip(server)],
domain = server.domain))
# Configure clients
for client in clients:
server_ips = (ank.server_ip(server) for server in ank.dns_hiearchy_parents(client))
server_ips = list(server_ips)
f_resolv = open( os.path.join(etc_dir(self.network, client), "resolv.conf"), 'wb')
f_resolv.write ( resolve_template.render(
nameservers = server_ips,
domain = client.domain))
return