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


Python NetworkManager.is_range_intersection方法代码示例

本文整理汇总了Python中nailgun.network.manager.NetworkManager.is_range_intersection方法的典型用法代码示例。如果您正苦于以下问题:Python NetworkManager.is_range_intersection方法的具体用法?Python NetworkManager.is_range_intersection怎么用?Python NetworkManager.is_range_intersection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在nailgun.network.manager.NetworkManager的用法示例。


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

示例1: test_ip_range_intersection

# 需要导入模块: from nailgun.network.manager import NetworkManager [as 别名]
# 或者: from nailgun.network.manager.NetworkManager import is_range_intersection [as 别名]
    def test_ip_range_intersection(self):
        nm = NetworkManager()
        self.assertEqual(nm.is_range_in_cidr(
            IPRange('192.168.0.0', '192.168.255.255'),
            IPNetwork('192.168.1.0/24')
        ), True)
        self.assertEqual(nm.is_range_in_cidr(
            IPRange('164.174.47.1', '191.0.0.0'),
            IPNetwork('192.168.1.0/24')
        ), False)
        self.assertEqual(nm.is_range_in_cidr(
            IPRange('192.168.0.0', '192.168.255.255'),
            IPRange('164.174.47.1', '191.0.0.0')
        ), False)
        self.assertEqual(nm.is_range_in_cidr(
            IPNetwork('192.168.1.0/8'),
            IPNetwork('192.168.1.0/24')
        ), True)

        self.assertEqual(nm.is_range_intersection(
            IPRange('192.168.0.0', '192.168.255.255'),
            IPNetwork('192.168.1.0/24')
        ), True)
        self.assertEqual(nm.is_range_intersection(
            IPRange('164.174.47.1', '191.0.0.0'),
            IPNetwork('192.168.1.0/24')
        ), False)
        self.assertEqual(nm.is_range_intersection(
            IPRange('192.168.0.0', '192.168.255.255'),
            IPRange('164.174.47.1', '191.0.0.0')
        ), False)
        self.assertEqual(nm.is_range_intersection(
            IPNetwork('192.168.1.0/8'),
            IPNetwork('192.168.1.0/24')
        ), True)
        self.assertEqual(nm.is_range_intersection(
            IPRange('192.168.0.0', '192.168.130.255'),
            IPRange('192.168.128.0', '192.168.255.255'),
        ), True)

        self.assertEqual(nm.is_cidr_intersection(
            IPNetwork('192.168.0.0/20'),
            IPNetwork('192.168.1.0/24')
        ), True)
        self.assertEqual(nm.is_cidr_intersection(
            IPNetwork('164.164.0.0/14'),
            IPNetwork('192.168.1.0/24')
        ), False)
        self.assertEqual(nm.is_cidr_intersection(
            IPNetwork('164.174.47.0/25'),
            IPNetwork('164.174.47.128/25')
        ), False)
        self.assertEqual(nm.is_cidr_intersection(
            IPNetwork('192.168.1.0/8'),
            IPNetwork('192.168.1.0/24')
        ), True)
开发者ID:AlexeyKasatkin,项目名称:fuel-web,代码行数:58,代码来源:test_checknetworkstask.py

示例2: nova_net_check

# 需要导入模块: from nailgun.network.manager import NetworkManager [as 别名]
# 或者: from nailgun.network.manager.NetworkManager import is_range_intersection [as 别名]
    def nova_net_check(cls, task, data, check_admin_untagged):
        # If not set in data then fetch from db
        if 'net_manager' in data:
            netmanager = data['net_manager']
        else:
            netmanager = task.cluster.net_manager

        if 'networks' in data:
            networks = data['networks']
        else:
            networks = map(lambda x: x.__dict__, task.cluster.network_groups)

        result = []
        err_msgs = []

        # checking if there are untagged
        # networks on the same interface
        # (main) as admin network
        if check_admin_untagged:
            untagged_nets = set(
                n["id"] for n in filter(
                    lambda n: (n["vlan_start"] is None), networks))
            if untagged_nets:
                logger.info(
                    "Untagged networks found, "
                    "checking admin network intersection...")
                admin_interfaces = map(lambda node: node.admin_interface,
                                       task.cluster.nodes)
                found_intersection = []

                for iface in admin_interfaces:
                    nets = dict(
                        (n.id, n.name)
                        for n in iface.assigned_networks)

                    err_nets = set(nets.keys()) & untagged_nets
                    if err_nets:
                        err_net_names = [
                            '"{0}"'.format(nets[i]) for i in err_nets]
                        found_intersection.append(
                            [iface.node.name, err_net_names])

                if found_intersection:
                    nodes_with_errors = [
                        u'Node "{0}": {1}'.format(
                            name,
                            ", ".join(_networks)
                        ) for name, _networks in found_intersection]
                    err_msg = u"Some untagged networks are " \
                              "assigned to the same physical interface as " \
                              "admin (PXE) network. You can whether turn " \
                              "on tagging for these OpenStack " \
                              "networks or move them to another physical " \
                              "interface:\n{0}".format("\n".join(
                                  nodes_with_errors))
                    raise errors.NetworkCheckError(err_msg, add_client=False)

        net_man = NetworkManager()
        admin_ng = net_man.get_admin_network_group()
        admin_range = netaddr.IPNetwork(admin_ng.cidr)
        for ng in networks:
            net_errors = []
            sub_ranges = []
            ng_db = db().query(NetworkGroup).get(ng['id'])
            if not ng_db:
                net_errors.append("id")
                err_msgs.append(u"Invalid network ID: {0}".format(ng['id']))
            else:
                if ng.get('cidr'):
                    fnet = netaddr.IPNetwork(ng['cidr'])
                    if net_man.is_range_intersection(fnet, admin_range):
                        net_errors.append("cidr")
                        err_msgs.append(
                            u"Intersection with admin "
                            "network(s) '{0}' found".format(
                                admin_ng.cidr
                            )
                        )
                    if fnet.size < ng['network_size'] * ng['amount']:
                        net_errors.append("cidr")
                        err_msgs.append(
                            u"CIDR size for network '{0}' "
                            "is less than required".format(
                                ng.get('name') or ng_db.name or ng_db.id
                            )
                        )
                # Check for intersection with Admin network
                if 'ip_ranges' in ng:
                    for k, v in enumerate(ng['ip_ranges']):
                        ip_range = netaddr.IPRange(v[0], v[1])
                        if net_man.is_range_intersection(admin_range,
                                                         ip_range):
                            net_errors.append("cidr")
                            err_msgs.append(
                                u"IP range {0} - {1} in {2} network intersects"
                                " with admin range of {3}".format(
                                    v[0], v[1],
                                    ng.get('name') or ng_db.name or ng_db.id,
                                    admin_ng.cidr
                                )
#.........这里部分代码省略.........
开发者ID:dshulyak,项目名称:fuel-web,代码行数:103,代码来源:task.py


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