本文整理汇总了Python中dm_utils.DMUtils.make_community_name方法的典型用法代码示例。如果您正苦于以下问题:Python DMUtils.make_community_name方法的具体用法?Python DMUtils.make_community_name怎么用?Python DMUtils.make_community_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dm_utils.DMUtils
的用法示例。
在下文中一共展示了DMUtils.make_community_name方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: set_route_targets_config
# 需要导入模块: from dm_utils import DMUtils [as 别名]
# 或者: from dm_utils.DMUtils import make_community_name [as 别名]
def set_route_targets_config(self):
if self.policy_config is None:
self.policy_config = PolicyOptions(comment=DMUtils.policy_options_comment())
for route_target in self.route_targets:
comm = CommunityType(name=DMUtils.make_community_name(route_target),
members=route_target)
self.policy_config.add_community(comm)
# add community for switch options
comm = CommunityType(name=DMUtils.get_switch_policy_name(),
members=DMUtils.get_switch_vrf_import(self.get_asn()))
self.policy_config.add_community(comm)
示例2: add_routing_instance
# 需要导入模块: from dm_utils import DMUtils [as 别名]
# 或者: from dm_utils.DMUtils import make_community_name [as 别名]
#.........这里部分代码省略.........
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)
for fip in fips:
static_config.add_route(Route(name=fip + "/32", next_hop=interfaces[1].name))
# add policies for export route targets
ps = PolicyStatement(name=DMUtils.make_export_name(ri_name))
then = Then()
ps.set_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)
if fip_map is not None:
# for nat instance
then.set_reject("")
else:
then.set_accept("")
policy_config.add_policy_statement(ps)
# add policies for import route targets
ps = PolicyStatement(name=DMUtils.make_import_name(ri_name))
from_ = From()
term = Term(name="t1", fromxx=from_)
ps.set_term(term)
for route_target in import_targets:
from_.add_community(DMUtils.make_community_name(route_target))
term.set_then(Then(accept=""))
ps.set_then(Then(reject=""))
policy_config.add_policy_statement(ps)
# add firewall config for public VRF
forwarding_options_config = self.forwarding_options_config
firewall_config = self.firewall_config
if router_external and is_l2 == False:
forwarding_options_config = self.forwarding_options_config or ForwardingOptions()
firewall_config = self.firewall_config or Firewall()
if has_ipv4_prefixes and not self.inet4_forwarding_filter:
# create single instance inet4 filter
self.inet4_forwarding_filter = self.add_inet_public_vrf_filter(
forwarding_options_config, firewall_config, "inet"
)
if has_ipv6_prefixes and not self.inet6_forwarding_filter:
# create single instance inet6 filter
示例3: add_routing_instance
# 需要导入模块: from dm_utils import DMUtils [as 别名]
# 或者: from dm_utils.DMUtils import make_community_name [as 别名]
#.........这里部分代码省略.........
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():
ri_public = etree.SubElement(ri_config, "instance")
etree.SubElement(ri_public, "name").text = public_vrf
ri_opt = etree.SubElement(ri_public, "routing-options")
static_config = etree.SubElement(ri_opt, "static")
if_element = etree.SubElement(ri_public, "interface")
etree.SubElement(if_element, "name").text = interfaces[1].name
for fip in fips:
route_config = etree.SubElement(static_config, "route")
etree.SubElement(route_config, "name").text = fip + "/32"
etree.SubElement(
route_config, "next-hop").text = interfaces[1].name
# add policies for export route targets
ps = etree.SubElement(policy_config, "policy-statement")
etree.SubElement(ps, "name").text = DMUtils.make_export_name(ri_name)
term = etree.SubElement(ps, "term")
etree.SubElement(term, "name").text = "t1"
then = etree.SubElement(term, "then")
for route_target in export_targets:
comm = etree.SubElement(then, "community")
etree.SubElement(comm, "add")
etree.SubElement(
comm, "community-name").text = DMUtils.make_community_name(route_target)
if fip_map is not None:
# for nat instance
etree.SubElement(then, "reject")
else:
etree.SubElement(then, "accept")
# add policies for import route targets
ps = etree.SubElement(policy_config, "policy-statement")
etree.SubElement(ps, "name").text = DMUtils.make_import_name(ri_name)
term = etree.SubElement(ps, "term")
etree.SubElement(term, "name").text = "t1"
from_ = etree.SubElement(term, "from")
for route_target in import_targets:
target_name = DMUtils.make_community_name(route_target)
etree.SubElement(from_, "community").text = target_name
then = etree.SubElement(term, "then")
etree.SubElement(then, "accept")
then = etree.SubElement(ps, "then")
etree.SubElement(then, "reject")
# add firewall config for public VRF
forwarding_options_config = self.forwarding_options_config
firewall_config = self.firewall_config
if router_external and is_l2 == False:
forwarding_options_config = (self.forwarding_options_config or
etree.Element("forwarding-options"))
firewall_config = self.firewall_config or etree.Element("firewall")
if has_ipv4_prefixes and not self.inet4_forwarding_filter:
#create single instance inet4 filter
self.inet4_forwarding_filter = self.add_inet_public_vrf_filter(
forwarding_options_config,
firewall_config, "inet4", "inet")
示例4: add_routing_instance
# 需要导入模块: from dm_utils import DMUtils [as 别名]
# 或者: from dm_utils.DMUtils import make_community_name [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()
#.........这里部分代码省略.........