本文整理汇总了Python中AutoNetkit.advertise_links方法的典型用法代码示例。如果您正苦于以下问题:Python AutoNetkit.advertise_links方法的具体用法?Python AutoNetkit.advertise_links怎么用?Python AutoNetkit.advertise_links使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AutoNetkit
的用法示例。
在下文中一共展示了AutoNetkit.advertise_links方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: configure_dns
# 需要导入模块: import AutoNetkit [as 别名]
# 或者: from AutoNetkit import advertise_links [as 别名]
def configure_dns(self):
"""Generates BIND configuration files for DNS
Can check configs eg:
Forward::
bash-3.2$ named-checkzone -d AS3 ank_lab/netkit_lab/AS3_l3_3_dns_1/etc/bind/db.AS3
loading "AS3" from "ank_lab/netkit_lab/AS3_l3_3_dns_1/etc/bind/db.AS3" class "IN"
zone AS3/IN: loaded serial 2008080101
OK
Reverse::
bash-3.2$ named-checkzone -d 0.10.in-addr.arpa ank_lab/netkit_lab/AS3_l3_3_dns_1/etc/bind/db.0.10.in-addr.arpa.
loading "0.10.in-addr.arpa" from "ank_lab/netkit_lab/AS3_l3_3_dns_1/etc/bind/db.0.10.in-addr.arpa." class "IN"
zone 0.10.in-addr.arpa/IN: loaded serial 2008080101
OK
named::
bash-3.2$ named-checkconf ank_lab/netkit_lab/AS3_l3_3_dns_1/etc/bind/named.conf
"""
import netaddr
ip_localhost = netaddr.IPAddress("127.0.0.1")
linux_bind_dir = "/etc/bind"
resolve_template = lookup.get_template("linux/resolv.mako")
forward_template = lookup.get_template("bind/forward.mako")
named_template = lookup.get_template("bind/named.mako")
reverse_template = lookup.get_template("bind/reverse.mako")
root_template = lookup.get_template("bind/root.mako")
root_dns_template = lookup.get_template("bind/root_dns.mako")
root_dns_named_template = lookup.get_template("bind/root_dns_named.mako")
ip_as_allocs = ank.get_ip_as_allocs(self.network)
dns_servers = ank.dns_servers(self.network)
root_servers = list(ank.root_dns_servers(self.network))
auth_servers = ank.dns.dns_auth_servers(self.network)
caching_servers = ank.dns.dns_cache_servers(self.network)
clients = ank.dns.dns_clients(self.network)
routers = set(self.network.routers())
#TODO: use with for opening files
for server in root_servers:
children = ank.dns.dns_hiearchy_children(server)
child_servers = []
for child in children:
advertise_block = ip_as_allocs[child.asn]
reverse_identifier = ank.rev_dns_identifier(advertise_block)
child_servers.append( (child.domain, reverse_identifier, ank.server_ip(child)))
f_root_db = open(os.path.join(bind_dir(self.network, server), "db.root"), 'wb')
f_root_db.write( root_dns_template.render(
dns_servers = child_servers,
server = server,
))
f_named = open( os.path.join(bind_dir(self.network, server), "named.conf"), 'wb')
f_named.write(root_dns_named_template.render(
logging = False,
))
for server in caching_servers:
#root_db_hint = ( ("ns.AS%s" % n.asn, ank.server_ip(n)) for n in ank.dns_hiearchy_parents(server))
root_db_hint = ( ("ROOT-SERVER", ank.server_ip(n)) for n in root_servers)
root_db_hint = list(root_db_hint)
#TODO: make caching use parent rather than global root
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))
f_named = open( os.path.join(bind_dir(self.network, server), "named.conf"), 'wb')
f_named.write(named_template.render(
entry_list = [],
bind_dir = linux_bind_dir,
logging = False,
))
f_named.close()
for server in auth_servers:
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,
#.........这里部分代码省略.........