本文整理汇总了Python中ipaddr.IPNetwork.iter_subnets方法的典型用法代码示例。如果您正苦于以下问题:Python IPNetwork.iter_subnets方法的具体用法?Python IPNetwork.iter_subnets怎么用?Python IPNetwork.iter_subnets使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ipaddr.IPNetwork
的用法示例。
在下文中一共展示了IPNetwork.iter_subnets方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: configure_second_admin_cobbler
# 需要导入模块: from ipaddr import IPNetwork [as 别名]
# 或者: from ipaddr.IPNetwork import iter_subnets [as 别名]
def configure_second_admin_cobbler(self):
dhcp_template = '/etc/cobbler/dnsmasq.template'
remote = self.d_env.get_admin_remote()
admin_net2 = self.d_env.admin_net2
second_admin_if = settings.INTERFACES.get(admin_net2)
second_admin_ip = str(
self.d_env.nodes().admin.get_ip_address_by_network_name(admin_net2))
admin_net2_object = self.d_env.get_network(name=admin_net2)
second_admin_network = admin_net2_object.ip.ip
second_admin_netmask = admin_net2_object.ip.netmask
network = IPNetwork('{0}/{1}'.format(second_admin_network,
second_admin_netmask))
discovery_subnet = [net for net in network.iter_subnets(1)][-1]
first_discovery_address = str(discovery_subnet.network)
last_discovery_address = str(discovery_subnet.broadcast - 1)
new_range = ('interface={4}\\n'
'dhcp-range=internal2,{0},{1},{2}\\n'
'dhcp-option=net:internal2,option:router,{3}\\n'
'pxe-service=net:internal2,x86PC,"Install",pxelinux,{3}\\n'
'dhcp-boot=net:internal2,pxelinux.0,boothost,{3}\\n').\
format(first_discovery_address, last_discovery_address,
second_admin_netmask, second_admin_ip, second_admin_if)
cmd = ("dockerctl shell cobbler sed -r '$a \{0}' -i {1};"
"dockerctl shell cobbler cobbler sync").format(new_range,
dhcp_template)
result = remote.execute(cmd)
assert_equal(result['exit_code'], 0, ('Failed to add second admin'
'network to cobbler: {0}').format(result))
示例2: configure_second_admin_cobbler
# 需要导入模块: from ipaddr import IPNetwork [as 别名]
# 或者: from ipaddr.IPNetwork import iter_subnets [as 别名]
def configure_second_admin_cobbler(self):
dhcp_template = '/etc/cobbler/dnsmasq.template'
remote = self.get_admin_remote()
main_admin_ip = str(self.nodes().admin.
get_ip_address_by_network_name(self.admin_net))
second_admin_ip = str(self.nodes().admin.
get_ip_address_by_network_name(self.admin_net2))
second_admin_network = self.get_network(self.admin_net2).split('/')[0]
second_admin_netmask = self.get_net_mask(self.admin_net2)
network = IPNetwork('{0}/{1}'.format(second_admin_network,
second_admin_netmask))
discovery_subnet = [net for net in network.iter_subnets(1)][-1]
first_discovery_address = str(discovery_subnet.network)
last_discovery_address = str(discovery_subnet.broadcast - 1)
new_range = ('dhcp-range=internal2,{0},{1},{2}\\n'
'dhcp-option=net:internal2,option:router,{3}\\n'
'dhcp-boot=net:internal2,pxelinux.0,boothost,{4}\\n').\
format(first_discovery_address, last_discovery_address,
second_admin_netmask, second_admin_ip, main_admin_ip)
cmd = ("dockerctl shell cobbler sed -r '$a \{0}' -i {1};"
"dockerctl shell cobbler cobbler sync").format(new_range,
dhcp_template)
result = remote.execute(cmd)
assert_equal(result['exit_code'], 0, ('Failed to add second admin'
'network to cobbler: {0}').format(result))