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


Python utils.is_cidr_host函数代码示例

本文整理汇总了Python中neutron.common.utils.is_cidr_host函数的典型用法代码示例。如果您正苦于以下问题:Python is_cidr_host函数的具体用法?Python is_cidr_host怎么用?Python is_cidr_host使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了is_cidr_host函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: scan_fip_ports

    def scan_fip_ports(self, ri):
        # don't scan if not dvr or count is not None
        if ri.dist_fip_count is not None:
            return

        # scan system for any existing fip ports
        ri.dist_fip_count = 0
        rtr_2_fip_interface = self.get_rtr_ext_device_name(ri.router_id)
        if ip_lib.device_exists(rtr_2_fip_interface, namespace=ri.ns_name):
            device = ip_lib.IPDevice(rtr_2_fip_interface, namespace=ri.ns_name)
            existing_cidrs = [addr["cidr"] for addr in device.addr.list()]
            fip_cidrs = [c for c in existing_cidrs if common_utils.is_cidr_host(c)]
            ri.dist_fip_count = len(fip_cidrs)
开发者ID:antonioUnina,项目名称:neutron,代码行数:13,代码来源:dvr_fip_ns.py

示例2: process_floating_ip_addresses

    def process_floating_ip_addresses(self, interface_name):
        """Configure IP addresses on router's external gateway interface.

        Ensures addresses for existing floating IPs and cleans up
        those that should not longer be configured.
        """

        fip_statuses = {}
        if interface_name is None:
            LOG.debug('No Interface for floating IPs router: %s',
                      self.router['id'])
            return fip_statuses

        device = ip_lib.IPDevice(interface_name, namespace=self.ns_name)
        existing_cidrs = self.get_router_cidrs(device)
        new_cidrs = set()
        gw_cidrs = self._get_gw_ips_cidr()

        floating_ips = self.get_floating_ips()
        # Loop once to ensure that floating ips are configured.
        for fip in floating_ips:
            fip_ip = fip['floating_ip_address']
            ip_cidr = common_utils.ip_to_cidr(fip_ip)
            new_cidrs.add(ip_cidr)
            fip_statuses[fip['id']] = lib_constants.FLOATINGIP_STATUS_ACTIVE
            if ip_cidr not in existing_cidrs:
                fip_statuses[fip['id']] = self.add_floating_ip(
                    fip, interface_name, device)
                LOG.debug('Floating ip %(id)s added, status %(status)s',
                          {'id': fip['id'],
                           'status': fip_statuses.get(fip['id'])})
            elif (fip_ip in self.fip_map and
                  self.fip_map[fip_ip] != fip['fixed_ip_address']):
                LOG.debug("Floating IP was moved from fixed IP "
                          "%(old)s to %(new)s",
                          {'old': self.fip_map[fip_ip],
                           'new': fip['fixed_ip_address']})
                fip_statuses[fip['id']] = self.move_floating_ip(fip)
            elif fip_statuses[fip['id']] == fip['status']:
                # mark the status as not changed. we can't remove it because
                # that's how the caller determines that it was removed
                fip_statuses[fip['id']] = FLOATINGIP_STATUS_NOCHANGE
        fips_to_remove = (
            ip_cidr for ip_cidr in existing_cidrs - new_cidrs - gw_cidrs
            if common_utils.is_cidr_host(ip_cidr))
        for ip_cidr in fips_to_remove:
            LOG.debug("Removing floating ip %s from interface %s in "
                      "namespace %s", ip_cidr, interface_name, self.ns_name)
            self.remove_floating_ip(device, ip_cidr)

        return fip_statuses
开发者ID:2020human,项目名称:neutron,代码行数:51,代码来源:router_info.py

示例3: scan_fip_ports

    def scan_fip_ports(self, ri):
        # don't scan if not dvr or count is not None
        if ri.dist_fip_count is not None:
            return

        # scan system for any existing fip ports
        ri.dist_fip_count = 0
        rtr_2_fip_interface = self.get_rtr_ext_device_name(ri.router_id)
        device = ip_lib.IPDevice(rtr_2_fip_interface, namespace=ri.ns_name)
        if device.exists():
            existing_cidrs = [addr["cidr"] for addr in device.addr.list()]
            fip_cidrs = [c for c in existing_cidrs if common_utils.is_cidr_host(c)]
            for fip_cidr in fip_cidrs:
                fip_ip = fip_cidr.split("/")[0]
                rule_pr = self._rule_priorities.allocate(fip_ip)
                ri.floating_ips_dict[fip_ip] = rule_pr
            ri.dist_fip_count = len(fip_cidrs)
开发者ID:promptworks,项目名称:neutron,代码行数:17,代码来源:dvr_fip_ns.py

示例4: process_floating_ip_addresses

    def process_floating_ip_addresses(self, interface_name):
        """Configure IP addresses on router's external gateway interface.

        Ensures addresses for existing floating IPs and cleans up
        those that should not longer be configured.
        """

        fip_statuses = {}
        if interface_name is None:
            LOG.debug("No Interface for floating IPs router: %s", self.router["id"])
            return fip_statuses

        device = ip_lib.IPDevice(interface_name, namespace=self.ns_name)
        existing_cidrs = self.get_router_cidrs(device)
        new_cidrs = set()

        floating_ips = self.get_floating_ips()
        # Loop once to ensure that floating ips are configured.
        for fip in floating_ips:
            fip_ip = fip["floating_ip_address"]
            ip_cidr = common_utils.ip_to_cidr(fip_ip)
            new_cidrs.add(ip_cidr)
            fip_statuses[fip["id"]] = l3_constants.FLOATINGIP_STATUS_ACTIVE
            if ip_cidr not in existing_cidrs:
                fip_statuses[fip["id"]] = self.add_floating_ip(fip, interface_name, device)
                LOG.debug(
                    "Floating ip %(id)s added, status %(status)s",
                    {"id": fip["id"], "status": fip_statuses.get(fip["id"])},
                )

                # mark the status as not changed. we can't remove it because
                # that's how the caller determines that it was removed
                if fip_statuses[fip["id"]] == fip["status"]:
                    fip_statuses[fip["id"]] = FLOATINGIP_STATUS_NOCHANGE
        fips_to_remove = (ip_cidr for ip_cidr in existing_cidrs - new_cidrs if common_utils.is_cidr_host(ip_cidr))
        for ip_cidr in fips_to_remove:
            LOG.debug(
                "Removing floating ip %s from interface %s in " "namespace %s", ip_cidr, interface_name, self.ns_name
            )
            self.remove_floating_ip(device, ip_cidr)

        return fip_statuses
开发者ID:takeshineshiro,项目名称:neutron,代码行数:42,代码来源:router_info.py

示例5: process_floating_ip_addresses

    def process_floating_ip_addresses(self, interface_name):
        """Configure IP addresses on router's external gateway interface.

        Ensures addresses for existing floating IPs and cleans up
        those that should not longer be configured.
        """

        fip_statuses = {}
        if interface_name is None:
            LOG.debug('No Interface for floating IPs router: %s',
                      self.router['id'])
            return fip_statuses

        device = ip_lib.IPDevice(interface_name, namespace=self.ns_name)
        existing_cidrs = self.get_router_cidrs(device)
        new_cidrs = set()

        floating_ips = self.get_floating_ips()
        # Loop once to ensure that floating ips are configured.
        for fip in floating_ips:
            fip_ip = fip['floating_ip_address']
            ip_cidr = common_utils.ip_to_cidr(fip_ip)
            new_cidrs.add(ip_cidr)
            fip_statuses[fip['id']] = l3_constants.FLOATINGIP_STATUS_ACTIVE
            if ip_cidr not in existing_cidrs:
                fip_statuses[fip['id']] = self.add_floating_ip(
                    fip, interface_name, device)
                LOG.debug('Floating ip %(id)s added, status %(status)s',
                          {'id': fip['id'],
                           'status': fip_statuses.get(fip['id'])})

        fips_to_remove = (
            ip_cidr for ip_cidr in existing_cidrs - new_cidrs
            if common_utils.is_cidr_host(ip_cidr))
        for ip_cidr in fips_to_remove:
            self.remove_floating_ip(device, ip_cidr)

        return fip_statuses
开发者ID:boopalans,项目名称:neutron,代码行数:38,代码来源:router_info.py

示例6: scan_fip_ports

 def scan_fip_ports(self, ri):
     # scan system for any existing fip ports
     rtr_2_fip_interface = self.get_rtr_ext_device_name(ri.router_id)
     device = ip_lib.IPDevice(rtr_2_fip_interface, namespace=ri.ns_name)
     if device.exists():
         if len(ri.get_router_cidrs(device)):
             self.rtr_fip_connect = True
         else:
             self.rtr_fip_connect = False
         # On upgrade, there could be stale IP addresses configured, check
         # and remove them once.
         # TODO(haleyb): this can go away after a cycle or two
         if not self._stale_fips_checked:
             stale_cidrs = (
                 ip for ip in router_info.RouterInfo.get_router_cidrs(
                     ri, device)
                 if common_utils.is_cidr_host(ip))
             for ip_cidr in stale_cidrs:
                 LOG.debug("Removing stale floating ip %s from interface "
                           "%s in namespace %s",
                           ip_cidr, rtr_2_fip_interface, ri.ns_name)
                 device.delete_addr_and_conntrack_state(ip_cidr)
             self._stale_fips_checked = True
开发者ID:igordcard,项目名称:neutron,代码行数:23,代码来源:dvr_fip_ns.py

示例7: test_is_cidr_host_ipv6_32

 def test_is_cidr_host_ipv6_32(self):
     self.assertFalse(utils.is_cidr_host('2000::1/32'))
开发者ID:cisco-openstack,项目名称:neutron,代码行数:2,代码来源:test_utils.py

示例8: test_is_cidr_host_ipv6_netaddr

 def test_is_cidr_host_ipv6_netaddr(self):
     net = netaddr.IPNetwork("2000::1")
     self.assertTrue(utils.is_cidr_host(net))
开发者ID:cisco-openstack,项目名称:neutron,代码行数:3,代码来源:test_utils.py

示例9: test_is_cidr_host_ipv6

 def test_is_cidr_host_ipv6(self):
     self.assertTrue(utils.is_cidr_host('2000::1/128'))
开发者ID:cisco-openstack,项目名称:neutron,代码行数:2,代码来源:test_utils.py

示例10: test_is_cidr_host_ipv4

 def test_is_cidr_host_ipv4(self):
     self.assertTrue(utils.is_cidr_host('15.1.2.3/32'))
开发者ID:cisco-openstack,项目名称:neutron,代码行数:2,代码来源:test_utils.py


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