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


Python DMUtils.has_ipv4_prefixes方法代码示例

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


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

示例1: add_routing_instance

# 需要导入模块: from dm_utils import DMUtils [as 别名]
# 或者: from dm_utils.DMUtils import has_ipv4_prefixes [as 别名]
    def add_routing_instance(self, ri_conf):
        ri_name = ri_conf.get("ri_name")
        is_l2 = ri_conf.get("is_l2", False)
        is_l2_l3 = ri_conf.get("is_l2_l3", False)
        import_targets = ri_conf.get("import_targets", set())
        export_targets = ri_conf.get("export_targets", set())
        prefixes = ri_conf.get("prefixes", [])
        gateways = ri_conf.get("gateways", [])
        router_external = ri_conf.get("router_external", False)
        interfaces = ri_conf.get("interfaces", [])
        vni = ri_conf.get("vni", None)
        fip_map = ri_conf.get("fip_map", None)
        network_id = ri_conf.get("network_id", None)
        static_routes = ri_conf.get("static_routes", {})
        no_vrf_table_label = ri_conf.get("no_vrf_table_label", False)
        restrict_proxy_arp = ri_conf.get("restrict_proxy_arp", False)

        self.routing_instances[ri_name] = ri_conf
        ri_config = self.ri_config or RoutingInstances()
        policy_config = self.policy_config or PolicyOptions()
        ri = Instance(name=ri_name)
        ri_config.add_instance(ri)
        ri_opt = None
        if router_external and is_l2 == False:
            ri_opt = RoutingInstanceRoutingOptions(static=Static(route=[Route(name="0.0.0.0/0", next_table="inet.0")]))
            ri.set_routing_options(ri_opt)

        # for both l2 and l3
        ri.set_vrf_import(DMUtils.make_import_name(ri_name))
        ri.set_vrf_export(DMUtils.make_export_name(ri_name))

        has_ipv6_prefixes = DMUtils.has_ipv6_prefixes(prefixes)
        has_ipv4_prefixes = DMUtils.has_ipv4_prefixes(prefixes)

        if not is_l2:
            if ri_opt is None:
                ri_opt = RoutingInstanceRoutingOptions()
                ri.set_routing_options(ri_opt)
            if prefixes and fip_map is None:
                static_config = ri_opt.get_static()
                if not static_config:
                    static_config = Static()
                    ri_opt.set_static(static_config)
                rib_config_v6 = None
                static_config_v6 = None
                for prefix in prefixes:
                    if ":" in prefix and not rib_config_v6:
                        static_config_v6 = Static()
                        rib_config_v6 = RIB(name=ri_name + ".inet6.0")
                        rib_config_v6.set_static(static_config_v6)
                        ri_opt.set_rib(rib_config_v6)
                    if ":" in prefix:
                        static_config_v6.add_route(Route(name=prefix, discard=""))
                    else:
                        static_config.add_route(Route(name=prefix, discard=""))
                    if router_external:
                        self.add_to_global_ri_opts(prefix)

            ri.set_instance_type("vrf")
            if not no_vrf_table_label:
                ri.set_vrf_table_label("")  # only for l3
            if fip_map is None:
                for interface in interfaces:
                    ri.add_interface(Interface(name=interface.name))
            if static_routes:
                self.add_static_routes(ri_opt, static_routes)
            if has_ipv4_prefixes:
                ri_opt.set_auto_export(AutoExport(family=Family(inet=FamilyInet(unicast=""))))
            if has_ipv6_prefixes:
                ri_opt.set_auto_export(AutoExport(family=Family(inet6=FamilyInet6(unicast=""))))
        else:
            ri.set_instance_type("virtual-switch")

        if fip_map is not None:
            if ri_opt is None:
                ri_opt = RoutingInstanceRoutingOptions()
                ri.set_routing_options(ri_opt)
            static_config = ri_opt.get_static()
            if not static_config:
                static_config = Static()
                ri_opt.set_static(static_config)
            static_config.add_route(Route(name="0.0.0.0/0", next_hop=interfaces[0].name))
            ri.add_interface(Interface(name=interfaces[0].name))

            public_vrf_ips = {}
            for pip in fip_map.values():
                if pip["vrf_name"] not in public_vrf_ips:
                    public_vrf_ips[pip["vrf_name"]] = set()
                public_vrf_ips[pip["vrf_name"]].add(pip["floating_ip"])

            for public_vrf, fips in public_vrf_ips.items():
                ri_public = Instance(name=public_vrf)
                ri_config.add_instance(ri_public)
                ri_public.add_interface(Interface(name=interfaces[1].name))

                ri_opt = RoutingInstanceRoutingOptions()
                ri_public.set_routing_options(ri_opt)
                static_config = Static()
                ri_opt.set_static(static_config)

#.........这里部分代码省略.........
开发者ID:nischalsheth,项目名称:contrail-controller,代码行数:103,代码来源:physical_router_config.py

示例2: add_routing_instance

# 需要导入模块: from dm_utils import DMUtils [as 别名]
# 或者: from dm_utils.DMUtils import has_ipv4_prefixes [as 别名]
    def add_routing_instance(self, ri_conf):
        ri_name = ri_conf.get("ri_name")
        vn = ri_conf.get("vn")
        is_l2 = ri_conf.get("is_l2", False)
        is_l2_l3 = ri_conf.get("is_l2_l3", False)
        import_targets = ri_conf.get("import_targets", set())
        export_targets = ri_conf.get("export_targets", set())
        prefixes = ri_conf.get("prefixes", [])
        gateways = ri_conf.get("gateways", [])
        interfaces = ri_conf.get("interfaces", [])
        vni = ri_conf.get("vni", None)
        network_id = ri_conf.get("network_id", None)

        self.routing_instances[ri_name] = ri_conf
        ri_config = None
        policy_config = self.policy_config or \
                       PolicyOptions(comment=DMUtils.policy_options_comment())
        ri = None
        ri_opt = None
        if not is_l2:
            ri_config = self.ri_config or \
                   RoutingInstances(comment=DMUtils.routing_instances_comment())
            ri = Instance(name=ri_name)
            ri_config.add_instance(ri)
            ri.set_vrf_import(DMUtils.make_import_name(ri_name))
            ri.set_vrf_export(DMUtils.make_export_name(ri_name))

        has_ipv6_prefixes = DMUtils.has_ipv6_prefixes(prefixes)
        has_ipv4_prefixes = DMUtils.has_ipv4_prefixes(prefixes)

        if not is_l2:
            if ri_opt is None:
                ri_opt = RoutingInstanceRoutingOptions()
                ri.set_routing_options(ri_opt)

            ri.set_instance_type("vrf")
            for interface in interfaces:
                ri.add_interface(Interface(name=interface.name))
            family = Family()
            if has_ipv4_prefixes:
                family.set_inet(FamilyInet(unicast=''))
            if has_ipv6_prefixes:
                family.set_inet6(FamilyInet6(unicast=''))
            if has_ipv4_prefixes or has_ipv6_prefixes:
                auto_export = AutoExport(family=family)
                ri_opt.set_auto_export(auto_export)

        # add policies for export route targets
        if self.is_spine():
            ps = PolicyStatement(name=DMUtils.make_export_name(ri_name))
            ps.set_comment(DMUtils.vn_ps_comment(vn, "Export"))
            then = Then()
            ps.add_term(Term(name="t1", then=then))
            for route_target in export_targets:
                comm = Community(add='',
                             community_name=DMUtils.make_community_name(route_target))
                then.add_community(comm)
                then.set_accept('')
            policy_config.add_policy_statement(ps)
            self.add_to_global_switch_opts(DMUtils.make_export_name(ri_name), False)

        # add policies for import route targets
        ps = PolicyStatement(name=DMUtils.make_import_name(ri_name))
        ps.set_comment(DMUtils.vn_ps_comment(vn, "Import"))

        # add term switch policy
        from_ = From()
        term = Term(name=DMUtils.get_switch_policy_name(), fromxx=from_)
        ps.add_term(term)
        from_.add_community(DMUtils.get_switch_policy_name())
        term.set_then(Then(accept=''))

        from_ = From()
        term = Term(name="t1", fromxx=from_)
        ps.add_term(term)
        for route_target in import_targets:
            from_.add_community(DMUtils.make_community_name(route_target))
            if not self.is_spine():
                self.add_vni_option(vni or network_id, route_target)
        term.set_then(Then(accept=''))
        policy_config.add_policy_statement(ps)
        self.add_to_global_switch_opts(DMUtils.make_import_name(ri_name), True)

        # add L2 EVPN and BD config
        interfaces_config = self.interfaces_config
        if (is_l2 and vni is not None and
                self.is_family_configured(self.bgp_params, "e-vpn")):
            # add vlan config
            vlan_conf = self.add_vlan_config(ri_name, vni)
            interfaces_config = self.interfaces_config or Interfaces(comment=DMUtils.interfaces_comment())
            if is_l2_l3 and self.is_spine():
                irb_intf = Interface(name='irb', gratuitous_arp_reply='')
                interfaces_config.add_interface(irb_intf)
                if gateways is not None:
                    intf_unit = Unit(name=str(network_id),
                                     comment=DMUtils.vn_irb_comment(vn, False, is_l2_l3))
                    irb_intf.add_unit(intf_unit)
                    if self.is_spine():
                        intf_unit.set_proxy_macip_advertisement('')
                    family = Family()
#.........这里部分代码省略.........
开发者ID:nischalsheth,项目名称:contrail-controller,代码行数:103,代码来源:qfx_conf.py

示例3: add_routing_instance

# 需要导入模块: from dm_utils import DMUtils [as 别名]
# 或者: from dm_utils.DMUtils import has_ipv4_prefixes [as 别名]
    def add_routing_instance(self, ri_conf):
        ri_name = ri_conf.get("ri_name")
        is_l2 = ri_conf.get("is_l2", False)
        is_l2_l3 = ri_conf.get("is_l2_l3", False)
        import_targets = ri_conf.get("import_targets", set())
        export_targets = ri_conf.get("export_targets", set())
        prefixes = ri_conf.get("prefixes", [])
        gateways = ri_conf.get("gateways", [])
        router_external = ri_conf.get("router_external", False)
        interfaces = ri_conf.get("interfaces", [])
        vni = ri_conf.get("vni", None)
        fip_map = ri_conf.get("fip_map", None)
        network_id = ri_conf.get("network_id", None)
        static_routes = ri_conf.get("static_routes", {})
        no_vrf_table_label = ri_conf.get("no_vrf_table_label", False)
        restrict_proxy_arp = ri_conf.get("restrict_proxy_arp", False)

        self.routing_instances[ri_name] = ri_conf

        ri_config = self.ri_config or etree.Element("routing-instances")
        policy_config = self.policy_config or etree.Element("policy-options")
        ri = etree.SubElement(ri_config, "instance")
        etree.SubElement(ri, "name").text = ri_name
        ri_opt = None
        if router_external and is_l2 == False:
            ri_opt = etree.SubElement(ri, "routing-options")
            static_config = etree.SubElement(ri_opt, "static")
            route_config = etree.SubElement(static_config, "route")
            etree.SubElement(route_config, "name").text = "0.0.0.0/0"
            etree.SubElement(route_config, "next-table").text = "inet.0"

        # for both l2 and l3
        etree.SubElement(ri, "vrf-import").text = DMUtils.make_import_name(ri_name)
        etree.SubElement(ri, "vrf-export").text = DMUtils.make_export_name(ri_name)

        has_ipv6_prefixes = DMUtils.has_ipv6_prefixes(prefixes)
        has_ipv4_prefixes = DMUtils.has_ipv4_prefixes(prefixes)

        if not is_l2:
            if ri_opt is None:
                ri_opt = etree.SubElement(ri, "routing-options")
            if prefixes and fip_map is None:
                static_config = etree.SubElement(ri_opt, "static")
                rib_config_v6 = None
                static_config_v6 = None
                for prefix in prefixes:
                    if ':' in prefix and not rib_config_v6:
                        rib_config_v6 = etree.SubElement(ri_opt, "rib")
                        etree.SubElement(rib_config_v6, "name").text = ri_name + ".inet6.0"
                        static_config_v6 = etree.SubElement(rib_config_v6, "static")
                    if ':' in prefix:
                        route_config = etree.SubElement(static_config_v6, "route")
                    else:
                        route_config = etree.SubElement(static_config, "route")
                    etree.SubElement(route_config, "name").text = prefix
                    etree.SubElement(route_config, "discard")
                    if router_external:
                        self.add_to_global_ri_opts(prefix)

            etree.SubElement(ri, "instance-type").text = "vrf"
            if not no_vrf_table_label:
                etree.SubElement(ri, "vrf-table-label")  # only for l3
            if fip_map is None:
                for interface in interfaces:
                    if_element = etree.SubElement(ri, "interface")
                    etree.SubElement(if_element, "name").text = interface.name
            if ri_opt is None:
                ri_opt = etree.SubElement(ri, "routing-options")
            if static_routes:
                self.add_static_routes(ri_opt, static_routes)
            if has_ipv4_prefixes:
                auto_export = """<auto-export>
                                <family><inet><unicast/></inet></family>
                            </auto-export>"""
                ri_opt.append(etree.fromstring(auto_export))
            if has_ipv6_prefixes:
                auto_export = """<auto-export>
                                <family><inet6><unicast/></inet6></family>
                            </auto-export>"""
                ri_opt.append(etree.fromstring(auto_export))
        else:
            etree.SubElement(ri, "instance-type").text = "virtual-switch"

        if fip_map is not None:
            if ri_opt is None:
                ri_opt = etree.SubElement(ri, "routing-options")
            static_config = etree.SubElement(ri_opt, "static")
            route_config = etree.SubElement(static_config, "route")
            etree.SubElement(route_config, "name").text = "0.0.0.0/0"
            etree.SubElement(
                route_config, "next-hop").text = interfaces[0].name
            if_element = etree.SubElement(ri, "interface")
            etree.SubElement(if_element, "name").text = interfaces[0].name
            public_vrf_ips = {}
            for pip in fip_map.values():
                if pip["vrf_name"] not in public_vrf_ips:
                    public_vrf_ips[pip["vrf_name"]] = set()
                public_vrf_ips[pip["vrf_name"]].add(pip["floating_ip"])

            for public_vrf, fips in public_vrf_ips.items():
#.........这里部分代码省略.........
开发者ID:tcpcloud,项目名称:contrail-controller,代码行数:103,代码来源:physical_router_config.py

示例4: add_routing_instance

# 需要导入模块: from dm_utils import DMUtils [as 别名]
# 或者: from dm_utils.DMUtils import has_ipv4_prefixes [as 别名]
    def add_routing_instance(self, ri_conf):
        ri_name = ri_conf.get("ri_name")
        vn = ri_conf.get("vn")
        is_l2 = ri_conf.get("is_l2", False)
        is_l2_l3 = ri_conf.get("is_l2_l3", False)
        import_targets = ri_conf.get("import_targets", set())
        export_targets = ri_conf.get("export_targets", set())
        prefixes = ri_conf.get("prefixes", [])
        gateways = ri_conf.get("gateways", [])
        router_external = ri_conf.get("router_external", False)
        is_dci = ri_conf.get("is_dci_network", False)
        connected_dci_network = ri_conf.get("connected_dci_network")
        interfaces = ri_conf.get("interfaces", [])
        vni = ri_conf.get("vni", None)
        fip_map = ri_conf.get("fip_map", None)
        network_id = ri_conf.get("network_id", None)
        is_internal_vn = True if '_contrail_lr_internal_vn_' in vn.name else False
        is_dci_vn = True if '_contrail_dci_internal_vn_' in vn.name else False
        encapsulation_priorities = \
           ri_conf.get("encapsulation_priorities") or ["MPLSoGRE"]

        ri = RoutingInstance(name=ri_name)
        if vn:
            is_nat = True if fip_map else False
            ri.set_comment(DMUtils.vn_ri_comment(vn, is_l2, is_l2_l3, is_nat,
                                                 router_external))
        self.ri_map[ri_name] = ri

        ri.set_virtual_network_id(str(network_id))
        ri.set_vxlan_id(str(vni))
        ri.set_virtual_network_is_internal(is_internal_vn or is_dci_vn)
        ri.set_is_public_network(router_external)
        if is_l2_l3:
            ri.set_virtual_network_mode('l2-l3')
        elif is_l2:
            ri.set_virtual_network_mode('l2')
        else:
            ri.set_virtual_network_mode('l3')

        has_ipv6_prefixes = DMUtils.has_ipv6_prefixes(prefixes)
        has_ipv4_prefixes = DMUtils.has_ipv4_prefixes(prefixes)

        if not is_l2:
            ri.set_routing_instance_type("vrf")
            if fip_map is None:
                for interface in interfaces:
                    self.add_ref_to_list(ri.get_interfaces(), interface.name)
                if prefixes:
                    for prefix in prefixes:
                        ri.add_static_routes(self.get_route_for_cidr(prefix))
                        ri.add_prefixes(self.get_subnet_for_cidr(prefix))
        else:
            if encapsulation_priorities[0] == "VXLAN":
                ri.set_routing_instance_type("virtual-switch")
            elif (any(x in encapsulation_priorities for x in ["MPLSoGRE", "MPLSoUDP"])):
                ri.set_routing_instance_type("evpn")

        if is_internal_vn:
            self.internal_vn_ris.append(ri)
        if is_dci_vn:
            self.dci_vn_ris.append(ri)

        if is_internal_vn or router_external or is_dci_vn:
            self.add_bogus_lo0(ri, network_id, vn)

        if self.is_gateway() and is_l2_l3:
            self.add_irb_config(ri_conf)
            self.attach_irb(ri_conf, ri)

        if fip_map is not None:
            self.add_ref_to_list(ri.get_interfaces(), interfaces[0].name)

            public_vrf_ips = {}
            for pip in fip_map.values():
                if pip["vrf_name"] not in public_vrf_ips:
                    public_vrf_ips[pip["vrf_name"]] = set()
                public_vrf_ips[pip["vrf_name"]].add(pip["floating_ip"])

            for public_vrf, fips in public_vrf_ips.items():
                ri_public = RoutingInstance(name=public_vrf)
                self.ri_map[public_vrf] = ri_public
                self.add_ref_to_list(ri_public.get_interfaces(), interfaces[1].name)
                floating_ips = []
                for fip in fips:
                    ri_public.add_static_routes(
                        Route(prefix=fip,
                              prefix_len=32,
                              next_hop=interfaces[1].name,
                              comment=DMUtils.fip_egress_comment()))
                    floating_ips.append(FloatingIpMap(floating_ip=fip + "/32"))
                ri_public.add_floating_ip_list(FloatingIpList(
                    public_routing_instance=public_vrf,
                    floating_ips=floating_ips))

        # add firewall config for public VRF
        if router_external and is_l2 is False:
            self.firewall_config = self.firewall_config or Firewall(
                comment=DMUtils.firewall_comment())
            if has_ipv4_prefixes and not self.inet4_forwarding_filter:
                # create single instance inet4 filter
#.........这里部分代码省略.........
开发者ID:rombie,项目名称:contrail-controller,代码行数:103,代码来源:ansible_role_common.py


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