本文整理汇总了Python中dm_utils.DMUtils.make_ip_term_name方法的典型用法代码示例。如果您正苦于以下问题:Python DMUtils.make_ip_term_name方法的具体用法?Python DMUtils.make_ip_term_name怎么用?Python DMUtils.make_ip_term_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dm_utils.DMUtils
的用法示例。
在下文中一共展示了DMUtils.make_ip_term_name方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_routing_instance
# 需要导入模块: from dm_utils import DMUtils [as 别名]
# 或者: from dm_utils.DMUtils import make_ip_term_name [as 别名]
#.........这里部分代码省略.........
family = Family()
intf_unit.set_family(family)
inet = None
inet6 = None
for (irb_ip, gateway) in gateways:
if ":" in irb_ip:
if not inet6:
inet6 = FamilyInet6()
family.set_inet6(inet6)
addr = Address()
inet6.add_address(addr)
else:
if not inet:
inet = FamilyInet()
family.set_inet(inet)
addr = Address()
inet.add_address(addr)
addr.set_name(irb_ip)
if len(gateway) and gateway != "0.0.0.0":
addr.set_virtual_gateway_address(gateway)
lo_intf = Interface(name="lo0")
interfaces_config.add_interface(lo_intf)
fam_inet = FamilyInet(address=[Address(name=self.bgp_params["address"] + "/32", primary="", preferred="")])
intf_unit = Unit(name="0", family=Family(inet=fam_inet))
lo_intf.add_unit(intf_unit)
self.build_l2_evpn_interface_config(interfaces_config, interfaces)
# fip services config
services_config = self.services_config
if fip_map is not None:
services_config = self.services_config or Services()
service_name = DMUtils.make_services_set_name(ri_name)
service_set = ServiceSet(name=service_name)
services_config.add_service_set(service_set)
nat_rule = NATRules(name=service_name + "-sn-rule")
service_set.add_nat_rules(NATRules(name=DMUtils.make_snat_rule_name(ri_name)))
service_set.add_nat_rules(NATRules(name=DMUtils.make_dnat_rule_name(ri_name)))
next_hop_service = NextHopService(
inside_service_interface=interfaces[0].name, outside_service_interface=interfaces[1].name
)
service_set.set_next_hop_service(next_hop_service)
nat = NAT(allow_overlapping_nat_pools="")
services_config.add_nat(nat)
snat_rule = Rule(name=DMUtils.make_snat_rule_name(ri_name), match_direction="input")
nat.add_rule(snat_rule)
dnat_rule = Rule(name=DMUtils.make_dnat_rule_name(ri_name), match_direction="output")
nat.add_rule(dnat_rule)
for pip, fip_vn in fip_map.items():
fip = fip_vn["floating_ip"]
term = Term(name=DMUtils.make_ip_term_name(pip))
snat_rule.set_term(term)
# private ip
from_ = From(source_address=[pip + "/32"])
term.set_from(from_)
# public ip
then_ = Then()
term.set_then(then_)
translated = Translated(source_prefix=fip + "/32", translation_type=TranslationType(basic_nat44=""))
then_.set_translated(translated)
term = Term(name=DMUtils.make_ip_term_name(fip))
dnat_rule.set_term(term)
# public ip
from_ = From(destination_address=[fip + "/32"])
term.set_from(from_)
# private ip
then_ = Then()
term.set_then(then_)
translated = Translated(destination_prefix=pip + "/32", translation_type=TranslationType(dnat_44=""))
then_.set_translated(translated)
interfaces_config = self.interfaces_config or Interfaces()
si_intf = Interface(name=interfaces[0].ifd_name)
interfaces_config.add_interface(si_intf)
intf_unit = Unit(name=interfaces[0].unit)
si_intf.add_unit(intf_unit)
family = Family(inet=FamilyInet())
intf_unit.set_family(family)
intf_unit.set_service_domain("inside")
intf_unit = Unit(name=interfaces[1].unit)
si_intf.add_unit(intf_unit)
family = Family(inet=FamilyInet())
intf_unit.set_family(family)
intf_unit.set_service_domain("outside")
self.forwarding_options_config = forwarding_options_config
self.firewall_config = firewall_config
self.policy_config = policy_config
self.proto_config = proto_config
self.interfaces_config = interfaces_config
self.services_config = services_config
self.route_targets |= import_targets | export_targets
self.ri_config = ri_config
示例2: add_routing_instance
# 需要导入模块: from dm_utils import DMUtils [as 别名]
# 或者: from dm_utils.DMUtils import make_ip_term_name [as 别名]
#.........这里部分代码省略.........
family = etree.SubElement(intf_unit, "family")
inet = etree.SubElement(family, "inet")
addr = etree.SubElement(inet, "address")
etree.SubElement(addr, "name").text = self.bgp_params[
'address'] + "/32"
etree.SubElement(addr, "primary")
etree.SubElement(addr, "preferred")
self.build_l2_evpn_interface_config(interfaces_config, interfaces)
# fip services config
services_config = self.services_config
if fip_map is not None:
services_config = self.services_config or etree.Element("services")
# mx has limitation for service-set and nat-rule name length,
# allowed max 63 chars
service_name = DMUtils.make_services_set_name(ri_name)
service_set = etree.SubElement(services_config, "service-set")
etree.SubElement(service_set, "name").text = service_name
nat_rule = etree.SubElement(service_set, "nat-rules")
etree.SubElement(nat_rule, "name").text = DMUtils.make_snat_rule_name(ri_name)
nat_rule = etree.SubElement(service_set, "nat-rules")
etree.SubElement(nat_rule, "name").text = DMUtils.make_dnat_rule_name(ri_name)
next_hop_service = etree.SubElement(
service_set, "next-hop-service")
etree.SubElement(
next_hop_service,
"inside-service-interface").text = interfaces[0].name
etree.SubElement(
next_hop_service,
"outside-service-interface").text = interfaces[1].name
nat = etree.SubElement(services_config, "nat")
etree.SubElement(nat, "allow-overlapping-nat-pools")
snat_rule = etree.SubElement(nat, "rule")
etree.SubElement(
snat_rule, "name").text = DMUtils.make_snat_rule_name(ri_name)
etree.SubElement(snat_rule, "match-direction").text = "input"
dnat_rule = etree.SubElement(nat, "rule")
etree.SubElement(
dnat_rule, "name").text = DMUtils.make_dnat_rule_name(ri_name)
etree.SubElement(dnat_rule, "match-direction").text = "output"
for pip, fip_vn in fip_map.items():
fip = fip_vn["floating_ip"]
term = etree.SubElement(snat_rule, "term")
etree.SubElement(
term, "name").text = DMUtils.make_ip_term_name(pip)
from_ = etree.SubElement(term, "from")
src_addr = etree.SubElement(from_, "source-address")
# private ip
etree.SubElement(src_addr, "name").text = pip + "/32"
then_ = etree.SubElement(term, "then")
translated = etree.SubElement(then_, "translated")
etree.SubElement(
translated,
"source-prefix").text = fip + "/32" # public ip
translation_type = etree.SubElement(
translated, "translation-type")
etree.SubElement(translation_type, "basic-nat44")
term = etree.SubElement(dnat_rule, "term")
etree.SubElement(
term, "name").text = DMUtils.make_ip_term_name(fip)
from_ = etree.SubElement(term, "from")
src_addr = etree.SubElement(from_, "destination-address")
etree.SubElement(
src_addr, "name").text = fip + "/32" # public ip
then_ = etree.SubElement(term, "then")
translated = etree.SubElement(then_, "translated")
etree.SubElement(
translated,
"destination-prefix").text = pip + "/32" # source ip
translation_type = etree.SubElement(
translated, "translation-type")
etree.SubElement(translation_type, "dnat-44")
interfaces_config = self.interfaces_config or etree.Element(
"interfaces")
si_intf = etree.SubElement(interfaces_config, "interface")
etree.SubElement(si_intf, "name").text = interfaces[0].ifd_name
intf_unit = etree.SubElement(si_intf, "unit")
etree.SubElement(intf_unit, "name").text = interfaces[0].unit
family = etree.SubElement(intf_unit, "family")
etree.SubElement(family, "inet")
etree.SubElement(intf_unit, "service-domain").text = "inside"
intf_unit = etree.SubElement(si_intf, "unit")
etree.SubElement(intf_unit, "name").text = interfaces[1].unit
family = etree.SubElement(intf_unit, "family")
etree.SubElement(family, "inet")
etree.SubElement(intf_unit, "service-domain").text = "outside"
self.forwarding_options_config = forwarding_options_config
self.firewall_config = firewall_config
self.policy_config = policy_config
self.proto_config = proto_config
self.interfaces_config = interfaces_config
self.services_config = services_config
self.route_targets |= import_targets | export_targets
self.ri_config = ri_config