当前位置: 首页>>代码示例>>Python>>正文


Python IPNetwork.next方法代码示例

本文整理汇总了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()
开发者ID:sk2,项目名称:ANK-NG,代码行数:12,代码来源:compiler.py

示例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()
开发者ID:backb1,项目名称:autonetkit,代码行数:13,代码来源:netkit.py

示例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()
开发者ID:wilko77,项目名称:STRIP,代码行数:13,代码来源:compiler.py

示例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()
开发者ID:ptokponnon,项目名称:autonetkit,代码行数:15,代码来源:compiler.py

示例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()
#.........这里部分代码省略.........
开发者ID:ema,项目名称:conpaas,代码行数:103,代码来源:cloud.py

示例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)
开发者ID:dknupp,项目名称:clusterdock,代码行数:8,代码来源:docker_utils.py

示例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()
开发者ID:cc1-cloud,项目名称:cc1,代码行数:27,代码来源:network.py


注:本文中的netaddr.IPNetwork.next方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。