本文整理汇总了Python中AutoNetkit.dns_advertise_link方法的典型用法代码示例。如果您正苦于以下问题:Python AutoNetkit.dns_advertise_link方法的具体用法?Python AutoNetkit.dns_advertise_link怎么用?Python AutoNetkit.dns_advertise_link使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AutoNetkit
的用法示例。
在下文中一共展示了AutoNetkit.dns_advertise_link方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: allocate_subnets
# 需要导入模块: import AutoNetkit [as 别名]
# 或者: from AutoNetkit import dns_advertise_link [as 别名]
def allocate_subnets(network, address_block=IPNetwork("10.0.0.0/8")):
"""Allocates subnets and IP addresses to links in the network.
Args:
address_block (IPNetwork): The address block to use.
Returns:
ip_as_allocs
Example usage:
>>> network = ank.example_multi_as()
>>> allocate_subnets(network)
>>> print ank.debug_nodes(network.graph, "lo_ip")
{'1a.AS1': IPNetwork('10.0.0.32/32'),
'1b.AS1': IPNetwork('10.0.0.33/32'),
'1c.AS1': IPNetwork('10.0.0.34/32'),
'2a.AS2': IPNetwork('10.1.0.64/32'),
'2b.AS2': IPNetwork('10.1.0.65/32'),
'2c.AS2': IPNetwork('10.1.0.66/32'),
'2d.AS2': IPNetwork('10.1.0.67/32'),
'3a.AS3': IPNetwork('10.2.0.0/32')}
>>> print ank.debug_edges(network.graph, "ip")
{('1a.AS1', '1b.AS1'): IPAddress('10.0.0.10'),
('1a.AS1', '1c.AS1'): IPAddress('10.0.0.22'),
('1b.AS1', '1a.AS1'): IPAddress('10.0.0.9'),
('1b.AS1', '1c.AS1'): IPAddress('10.0.0.26'),
('1b.AS1', '3a.AS3'): IPAddress('10.0.0.17'),
('1c.AS1', '1a.AS1'): IPAddress('10.0.0.21'),
('1c.AS1', '1b.AS1'): IPAddress('10.0.0.25'),
('1c.AS1', '2a.AS2'): IPAddress('10.0.0.29'),
('2a.AS2', '1c.AS1'): IPAddress('10.0.0.30'),
('2a.AS2', '2b.AS2'): IPAddress('10.1.0.10'),
('2a.AS2', '2d.AS2'): IPAddress('10.1.0.26'),
('2b.AS2', '2a.AS2'): IPAddress('10.1.0.9'),
('2b.AS2', '2c.AS2'): IPAddress('10.1.0.18'),
('2c.AS2', '2b.AS2'): IPAddress('10.1.0.17'),
('2c.AS2', '2d.AS2'): IPAddress('10.1.0.30'),
('2d.AS2', '2a.AS2'): IPAddress('10.1.0.25'),
('2d.AS2', '2c.AS2'): IPAddress('10.1.0.29'),
('2d.AS2', '3a.AS3'): IPAddress('10.1.0.33'),
('3a.AS3', '1b.AS1'): IPAddress('10.0.0.18'),
('3a.AS3', '2d.AS2'): IPAddress('10.1.0.34')}
>>> print ank.debug_edges(network.graph, "sn")
{('1a.AS1', '1b.AS1'): IPNetwork('10.0.0.8/30'),
('1a.AS1', '1c.AS1'): IPNetwork('10.0.0.20/30'),
('1b.AS1', '1a.AS1'): IPNetwork('10.0.0.8/30'),
('1b.AS1', '1c.AS1'): IPNetwork('10.0.0.24/30'),
('1b.AS1', '3a.AS3'): IPNetwork('10.0.0.16/30'),
('1c.AS1', '1a.AS1'): IPNetwork('10.0.0.20/30'),
('1c.AS1', '1b.AS1'): IPNetwork('10.0.0.24/30'),
('1c.AS1', '2a.AS2'): IPNetwork('10.0.0.28/30'),
('2a.AS2', '1c.AS1'): IPNetwork('10.0.0.28/30'),
('2a.AS2', '2b.AS2'): IPNetwork('10.1.0.8/30'),
('2a.AS2', '2d.AS2'): IPNetwork('10.1.0.24/30'),
('2b.AS2', '2a.AS2'): IPNetwork('10.1.0.8/30'),
('2b.AS2', '2c.AS2'): IPNetwork('10.1.0.16/30'),
('2c.AS2', '2b.AS2'): IPNetwork('10.1.0.16/30'),
('2c.AS2', '2d.AS2'): IPNetwork('10.1.0.28/30'),
('2d.AS2', '2a.AS2'): IPNetwork('10.1.0.24/30'),
('2d.AS2', '2c.AS2'): IPNetwork('10.1.0.28/30'),
('2d.AS2', '3a.AS3'): IPNetwork('10.1.0.32/30'),
('3a.AS3', '1b.AS1'): IPNetwork('10.0.0.16/30'),
('3a.AS3', '2d.AS2'): IPNetwork('10.1.0.32/30')}
"""
LOG.debug("Allocating subnets")
# Initialise IP list to be graph edge format
ip_as_allocs = {}
# allocates subnets to the edges and loopback in network graph
# Put into dictionary, indexed by ASN (the name attribute of each as graph)
# for easy appending of eBGP links
asgraphs = dict((my_as.asn, my_as) for my_as in ank.get_as_graphs(network))
# Simple method: break address_block into a /16 for each network
#TODO: check this is feasible - ie against required host count
subnet_list = address_block.subnet(16)
ebgp_edges = ank.ebgp_edges(network)
visited_ebgp_edges = set()
for src, dst in sorted(ebgp_edges):
# Add the dst (external peer) to AS of src node so they are allocated
# a subnet. (The AS choice is arbitrary)
if (dst, src) in visited_ebgp_edges:
continue
src_as = asgraphs[src.asn]
src_as.add_edge(src, dst)
# record for DNS purposes
ank.dns_advertise_link(src, dst)
visited_ebgp_edges.add( (src, dst))
for my_as in sorted(asgraphs.values(), key = lambda x: x.asn):
asn = my_as.asn
as_subnet = subnet_list.next()
#.........这里部分代码省略.........