本文整理汇总了Python中AutoNetkit.label方法的典型用法代码示例。如果您正苦于以下问题:Python AutoNetkit.label方法的具体用法?Python AutoNetkit.label怎么用?Python AutoNetkit.label使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AutoNetkit
的用法示例。
在下文中一共展示了AutoNetkit.label方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: allocate_dns_servers
# 需要导入模块: import AutoNetkit [as 别名]
# 或者: from AutoNetkit import label [as 别名]
def allocate_dns_servers(network):
"""Allocates DNS according to rules defined above
TODO: allow 3 level (ie no pop caching, clients connect to AS server)
TODO: make DNS servers standalone rather that co-hosted with router
TODO: note set dns level on dns graph, but ibgp level on physical graph - inconsistent!
"""
dns_graph = nx.DiGraph()
dns_advertise_graph = nx.DiGraph()
LOG.debug("DNS currently disabled")
hierarchical_dns = config.settings['DNS']['hierarchical']
if hierarchical_dns:
LOG.info("Configuring hierarchical DNS")
dns_levels = 4
else:
dns_levels = 1
LOG.debug("Non-hierarchical DNS not yet implemented")
#TODO: do "flat" dns - one root server, add all other devices as children for both resolving and authoritative
return
def nodes_by_eccentricity(graph):
if len(graph) == 1:
return graph.nodes()
# need to crop the global shortest paths otherwise get
#NetworkXError: Graph not connected: infinite path length
eccentricities = nx.eccentricity(graph)
return sorted(eccentricities.keys(), key = lambda n: eccentricities[n])
def format_asn(asn):
"""Returns unique format for asn, so don't confuse with property of the same,
eg if ibgp_l2_cluster = 1 in as2, it could match as1 routers as 1==1
so set asn_1 so 1 != asn_1"""
return "asn_%s" % asn
def get_l2_cluster(node):
"""syntactic sugar to access cluster"""
return dns_graph.node[node].get("dns_l2_cluster")
def get_l3_cluster(node):
"""syntactic sugar to access cluster"""
return dns_graph.node[node].get("dns_l3_cluster")
def level(u):
return int(dns_graph.node[u]['level'])
servers_per_l2_cluster = config.settings['DNS']['Server Count']['l2 cluster']
servers_per_l3_cluster = config.settings['DNS']['Server Count']['l3 cluster']
root_dns_servers = config.settings['DNS']['Server Count']['root']
global_eccentricities = nodes_by_eccentricity(network.graph)
#TODO: add count of each cluster occurence so can round servers down - dont want 3 servers in a one router network!
# Add routers, these form the level 1 clients
dns_graph.add_nodes_from(network.graph.nodes(), level=1)
for node, data in network.graph.nodes(data=True):
#TODO: the cluster should never be manually set, so can remove checks
if not data.get("dns_l2_cluster"):
dns_graph.node[node]['dns_l2_cluster'] = data.get("pop") or format_asn(network.asn(node))
if not data.get("dns_l3_cluster"):
dns_graph.node[node]['dns_l3_cluster'] = format_asn(network.asn(node))
for my_as in ank.get_as_graphs(network):
asn = my_as.asn
if not nx.is_strongly_connected(my_as):
LOG.info("AS%s not fully connected, skipping DNS configuration" % asn)
continue
l2_clusters = list(set(dns_graph.node[n].get("dns_l2_cluster") for n in my_as))
for l2_cluster in l2_clusters:
for index in range(servers_per_l2_cluster):
label = "l2_%s_dns_%s" % (l2_cluster, index+1)
if l2_cluster == format_asn(asn):
# Don't put asn into server name twice "AS2_asn_2_l2dns_1" vs "asn_2_l2dns_1"
server_name = "%s_l2dns_%s" % (l2_cluster, index+1)
else:
server_name = "AS%s_%s_l2dns_%s" % (asn, l2_cluster, index+1)
#TODO: see what other properties to retain
node_name = network.add_device(server_name, asn=asn,
device_type='server', label=label)
dns_graph.add_node(node_name, level=2, dns_l2_cluster=l2_cluster,
asn = asn, dns_l3_cluster = format_asn(asn))
for index in range(servers_per_l3_cluster):
label = "l3_%s_dns_%s" % (asn, index+1)
server_name = "AS%s_l3dns_%s" % (asn, index+1)
node_name = network.add_device(server_name, asn=asn,
device_type='server', label=label)
#TODO: check if need to add l2 here - was coded before, possible mistake?
dns_graph.add_node(node_name, level=3,
asn = asn, dns_l3_cluster = format_asn(asn))
# and level 4 connections
#TODO: need to determine the right place to put the server - order issue between allocating for root as need an ASN for the device before know best place - for now use asn = 1, and move if needed
for index in range(root_dns_servers):
#.........这里部分代码省略.........