本文整理汇总了Python中netaddr.IPNetwork.next方法的典型用法代码示例。如果您正苦于以下问题:Python IPNetwork.next方法的具体用法?Python IPNetwork.next怎么用?Python IPNetwork.next使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类netaddr.IPNetwork
的用法示例。
在下文中一共展示了IPNetwork.next方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: allocate_tap_ips
# 需要导入模块: from netaddr import IPNetwork [as 别名]
# 或者: from netaddr.IPNetwork import next [as 别名]
def allocate_tap_ips(self):
#TODO: take tap subnet parameter
lab_topology = self.nidb.topology[self.host]
from netaddr import IPNetwork
address_block = IPNetwork("172.16.0.0/16").iter_hosts()
lab_topology.tap_host = address_block.next()
lab_topology.tap_vm = address_block.next() # for tunnel host
for node in self.nidb.nodes("is_l3device", host = self.host):
#TODO: check this works for switches
node.tap.ip = address_block.next()
示例2: allocate_tap_ips
# 需要导入模块: from netaddr import IPNetwork [as 别名]
# 或者: from netaddr.IPNetwork import next [as 别名]
def allocate_tap_ips(self):
"""Allocates TAP IPs"""
settings = autonetkit.config.settings
lab_topology = self.nidb.topology[self.host]
from netaddr import IPNetwork
address_block = IPNetwork(settings.get("tapsn")
or "172.16.0.0/16").iter_hosts() # added for backwards compatibility
lab_topology.tap_host = address_block.next()
lab_topology.tap_vm = address_block.next() # for tunnel host
for node in sorted(self.nidb.nodes("is_l3device", host=self.host)):
node.tap.ip = address_block.next()
示例3: allocate_tap_ipsOriginal
# 需要导入模块: from netaddr import IPNetwork [as 别名]
# 或者: from netaddr.IPNetwork import next [as 别名]
def allocate_tap_ipsOriginal(self):
#TODO: take tap subnet parameter
lab_topology = self.nidb.topology[self.host] #TODO: also store platform
from netaddr import IPNetwork
address_block = IPNetwork("172.16.0.0/16").iter_hosts() #TODO: read this from config
lab_topology.tap_host = address_block.next()
lab_topology.tap_vm = address_block.next() # for tunnel host
for node in sorted(self.nidb.nodes("is_l3device", host = self.host)):
#TODO: fix sorting order
#TODO: check this works for switches
node.tap.ip = address_block.next()
示例4: allocate_tap_ips
# 需要导入模块: from netaddr import IPNetwork [as 别名]
# 或者: from netaddr.IPNetwork import next [as 别名]
def allocate_tap_ips(self):
# TODO: take tap subnet parameter
lab_topology = self.nidb.topology[self.host]
# TODO: also store platform
from netaddr import IPNetwork
address_block = IPNetwork(settings.get("tapsn")
or "172.16.0.0/16").iter_hosts() # added for backwards compatibility
lab_topology.tap_host = address_block.next()
lab_topology.tap_vm = address_block.next() # for tunnel host
for node in sorted(self.nidb.nodes("is_l3device", host=self.host)):
# TODO: fix sorting order
# TODO: check this works for switches
node.tap.ip = address_block.next()
示例5: _get_context_file
# 需要导入模块: from netaddr import IPNetwork [as 别名]
# 或者: from netaddr.IPNetwork import next [as 别名]
def _get_context_file(self, service_name, cloud):
"""Override default _get_context_file. Here we generate the context
file for managers rather than for agents."""
conpaas_home = self.config_parser.get('conpaas', 'CONF_DIR')
cloud_scripts_dir = os.path.join(conpaas_home, 'scripts', 'cloud')
mngr_scripts_dir = os.path.join(conpaas_home, 'scripts', 'manager')
mngr_cfg_dir = os.path.join(conpaas_home, 'config', 'manager')
director = self.config_parser.get('director', 'DIRECTOR_URL')
# Values to be passed to the context file template
tmpl_values = {}
# Get contextualization script for the cloud
try:
tmpl_values['cloud_script'] = file_get_contents(
os.path.join(cloud_scripts_dir, cloud))
except IOError:
tmpl_values['cloud_script'] = ''
# Get manager setup file
mngr_setup = file_get_contents(
os.path.join(mngr_scripts_dir, 'manager-setup'))
tmpl_values['mngr_setup'] = mngr_setup.replace('%DIRECTOR_URL%',
director)
# Get cloud config values from director.cfg
cloud_sections = ['iaas']
if self.config_parser.has_option('iaas', 'OTHER_CLOUDS'):
cloud_sections.extend(
[cloud_name for cloud_name
in self.config_parser.get('iaas', 'OTHER_CLOUDS').split(',')
if self.config_parser.has_section(cloud_name)])
def __extract_cloud_cfg(section_name):
tmpl_values['cloud_cfg'] += "["+section_name+"]\n"
for key, value in self.config_parser.items(section_name):
tmpl_values['cloud_cfg'] += key.upper() + " = " + value + "\n"
tmpl_values['cloud_cfg'] = ''
for section_name in cloud_sections:
__extract_cloud_cfg(section_name)
# Get manager config file
mngr_cfg = file_get_contents(
os.path.join(mngr_cfg_dir, 'default-manager.cfg'))
# Add service-specific config file (if any)
mngr_service_cfg = os.path.join(mngr_cfg_dir,
service_name + '-manager.cfg')
if os.path.isfile(mngr_service_cfg):
mngr_cfg += file_get_contents(mngr_service_cfg)
# Modify manager config file setting the required variables
mngr_cfg = mngr_cfg.replace('%DIRECTOR_URL%', director)
mngr_cfg = mngr_cfg.replace('%CONPAAS_SERVICE_TYPE%', service_name)
mngr_cfg = mngr_cfg.replace('%CLOUD_NAME%', self.cloud_name);
# mngr_cfg = mngr_cfg.replace('%CLOUD_TYPE%', cloud_type);
cloud = self.get_cloud_by_name(self.cloud_name)
# OpenNebula, EC2. etc
mngr_cfg = mngr_cfg.replace('%CLOUD_TYPE%',
self.config_parser.get(self.cloud_name, 'DRIVER'))
if self.config_parser.has_option(self.cloud_name, 'INST_TYPE'):
mngr_cfg = mngr_cfg.replace('%CLOUD_MACHINE_TYPE%',
self.config_parser.get(self.cloud_name, 'INST_TYPE'))
if self.config_parser.has_option(self.cloud_name, 'COST_PER_TIME'):
mngr_cfg = mngr_cfg.replace('%CLOUD_COST_PER_TIME%',
self.config_parser.get(self.cloud_name, 'COST_PER_TIME'))
if self.config_parser.has_option(self.cloud_name, 'MAX_VMS'):
mngr_cfg = mngr_cfg.replace('%CLOUD_MAX_VMS%',
self.config_parser.get(self.cloud_name, 'MAX_VMS'))
if self.config_parser.has_option('iaas', 'MAX_VMS_ALL_CLOUDS'):
mngr_cfg = mngr_cfg.replace('%CLOUD_MAX_VMS_ALL_CLOUDS%',
self.config_parser.get('iaas', 'MAX_VMS_ALL_CLOUDS'))
# mngr_cfg = mngr_cfg.replace('%CLOUD_COST_PER_TIME%', cloud_cost_per_time);
for option_name in 'SERVICE_ID', 'USER_ID', 'APP_ID':
mngr_cfg = mngr_cfg.replace('%CONPAAS_' + option_name + '%',
self.config_parser.get("manager",
option_name))
# Check if we want to use IPOP. If so, add IPOP directives to manager
# config file
if self.config_parser.has_option('manager', 'IPOP_SUBNET'):
ipop_subnet = self.config_parser.get('manager', 'IPOP_SUBNET')
mngr_cfg += '\nIPOP_SUBNET = %s' % ipop_subnet
ipop_network = IPNetwork(ipop_subnet).iter_hosts()
# Skip the first IP address. IPOP uses it for internal purposes
ipop_network.next()
#.........这里部分代码省略.........
示例6: get_available_network_subnet
# 需要导入模块: from netaddr import IPNetwork [as 别名]
# 或者: from netaddr.IPNetwork import next [as 别名]
def get_available_network_subnet(start_subnet=NETWORK_SUBNET_START):
"""Returns the next unused network subnet available to a Docker network in CIDR format."""
subnet = IPNetwork(start_subnet)
while overlaps_network_subnet(str(subnet)):
subnet = subnet.next(1)
return str(subnet)
示例7: add
# 需要导入模块: from netaddr import IPNetwork [as 别名]
# 或者: from netaddr.IPNetwork import next [as 别名]
def add(caller_id, address, mask):
networks = []
for net in AvailableNetwork.objects.all():
networks.append(net.to_ipnetwork())
networks.sort()
# Find duplicate
ipnet = IPNetwork('%s/%d' % (address, mask))
for i in xrange(len(networks)):
if ipnet.prefixlen > networks[i].prefixlen and ipnet > networks[i].previous() and ipnet < networks[i].next():
raise CMException('network_exists')
elif ipnet.prefixlen < networks[i].prefixlen and ipnet.previous() < networks[i] and ipnet.next() > networks[i]:
raise CMException('network_exists')
# Add new network
new_net = AvailableNetwork()
new_net.address = ipnet.network
new_net.mask = mask
if ipnet.is_private():
new_net.state = available_network_states['ok']
else:
new_net.state = available_network_states['locked']
new_net.save()