本文整理汇总了Python中dm_utils.DMUtils类的典型用法代码示例。如果您正苦于以下问题:Python DMUtils类的具体用法?Python DMUtils怎么用?Python DMUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DMUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_inet_public_vrf_filter
def add_inet_public_vrf_filter(self, forwarding_options_config, firewall_config, inet_type):
fo = Family()
inet_filter = InetFilter(input=DMUtils.make_public_vrf_filter_name(inet_type))
if inet_type == "inet6":
fo.set_inet6(FamilyInet6(filter=inet_filter))
else:
fo.set_inet(FamilyInet(filter=inet_filter))
forwarding_options_config.add_family(fo)
f = FirewallFilter(name=DMUtils.make_public_vrf_filter_name(inet_type))
ff = firewall_config.get_family()
if not ff:
ff = FirewallFamily()
firewall_config.set_family(ff)
if inet_type == "inet6":
inet6 = ff.get_inet6()
if not inet6:
inet6 = FirewallInet()
ff.set_inet6(inet6)
inet6.add_filter(f)
else:
inet = ff.get_inet()
if not inet:
inet = FirewallInet()
ff.set_inet(inet)
inet.add_filter(f)
term = Term(name="default-term", then=Then(accept=""))
f.add_term(term)
return f
示例2: build_l2_evpn_interface_config
def build_l2_evpn_interface_config(self, interfaces_config, interfaces, vn=None):
ifd_map = {}
for interface in interfaces:
ifd_map.setdefault(interface.ifd_name, []).append(interface)
for ifd_name, interface_list in ifd_map.items():
intf = Interface(name=ifd_name)
interfaces_config.add_interface(intf)
if interface_list[0].is_untagged():
if (len(interface_list) > 1):
self._logger.error(
"invalid logical interfaces config for ifd %s" % (
ifd_name))
continue
intf.set_encapsulation("ethernet-bridge")
intf.add_unit(Unit(name=interface_list[0].unit,
comment=DMUtils.l2_evpn_intf_unit_comment(vn, False),
family=Family(bridge='')))
else:
intf.set_flexible_vlan_tagging('')
intf.set_encapsulation("flexible-ethernet-services")
for interface in interface_list:
intf.add_unit(Unit(name=interface.unit,
comment=DMUtils.l2_evpn_intf_unit_comment(vn,
True, interface.vlan_tag),
encapsulation='vlan-bridge',
vlan_id=str(interface.vlan_tag)))
示例3: _build_ri_config
def _build_ri_config(self, vn, ri_name, ri_obj, interfaces, export_targets,
import_targets, feature_config):
encapsulation_priorities = self._get_encapsulation_priorities()
highest_encapsulation = encapsulation_priorities[0]
network_id = vn.vn_network_id
vxlan_id = vn.get_vxlan_vni()
ri = RoutingInstance(name=ri_name, virtual_network_mode='l2',
export_targets=export_targets, import_targets=import_targets,
virtual_network_id=str(network_id), vxlan_id=str(vxlan_id),
is_public_network=vn.router_external)
ri.set_virtual_network_id(str(network_id))
ri.set_vxlan_id(str(vxlan_id))
ri.set_is_public_network(vn.router_external)
vlan = None
if highest_encapsulation == 'VXLAN':
ri.set_routing_instance_type('virtual-switch')
vlan = Vlan(name=DMUtils.make_bridge_name(vxlan_id), vxlan_id=vxlan_id)
vlan.set_comment(DMUtils.vn_bd_comment(vn, 'VXLAN'))
feature_config.add_vlans(vlan)
for interface in interfaces:
self._add_ref_to_list(vlan.get_interfaces(), interface.li_name)
elif highest_encapsulation in ['MPLSoGRE', 'MPLSoUDP']:
ri.set_routing_instance_type('evpn')
self._build_l2_evpn_interface_config(interfaces, vn, vlan)
return ri
示例4: build_l2_evpn_interface_config
def build_l2_evpn_interface_config(self, interfaces_config, interfaces, vn, vlan_conf):
ifd_map = {}
for interface in interfaces:
ifd_map.setdefault(interface.ifd_name, []).append(interface)
for ifd_name, interface_list in ifd_map.items():
intf = Interface(name=ifd_name)
interfaces_config.add_interface(intf)
intf.set_flexible_vlan_tagging('')
intf.set_encapsulation("extended-vlan-bridge")
if interface_list[0].is_untagged():
if (len(interface_list) > 1):
self._logger.error(
"invalid logical interfaces config for ifd %s" % (
ifd_name))
continue
intf.add_unit(Unit(name=interface_list[0].unit,
comment=DMUtils.l2_evpn_intf_unit_comment(vn, False),
vlan_id="4094"))
vlan_conf.add_interface(Interface(name=ifd_name + ".0"))
else:
for interface in interface_list:
intf.add_unit(Unit(name=interface.unit,
comment=DMUtils.l2_evpn_intf_unit_comment(vn,
True, interface.vlan_tag),
vlan_id=str(interface.vlan_tag)))
vlan_conf.add_interface(Interface(name=ifd_name + "." + str(interface.vlan_tag)))
示例5: set_route_targets_config
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))
comm.add_members(route_target)
self.policy_config.add_community(comm)
示例6: build_ae_config
def build_ae_config(self, esi_map):
if esi_map:
self.set_chassis_config()
interfaces_config = self.interfaces_config or \
Interfaces(comment=DMUtils.interfaces_comment())
# self.ae_id_map should have all esi => ae_id mapping
# esi_map should have esi => interface memberships
for esi, ae_id in self.physical_router.ae_id_map.items():
# config ae interface
ae_name = "ae" + str(ae_id)
intf = Interface(name=ae_name)
interfaces_config.add_interface(intf)
priority = DMUtils.lacp_system_priority()
system_id = esi[-17:] #last 17 charcaters from esi for ex: 00:00:00:00:00:05
lacp = Lacp(active='', system_priority=priority, \
system_id=system_id, admin_key=1)
intf.set_aggregated_ether_options(AggregatedEtherOptions(lacp=lacp))
# associate 'ae' membership
pi_list = esi_map.get(esi)
for pi in pi_list or []:
intf = Interface(name=pi.name)
interfaces_config.add_interface(intf)
etherOptions = EtherOptions(ieee_802_3ad=Ieee802(bundle=ae_name))
intf.set_gigether_options(etherOptions)
self.interfaces_config = interfaces_config
示例7: add_inet_vrf_filter
def add_inet_vrf_filter(self, firewall_config, vrf_name):
firewall_config.set_family("inet")
f = FirewallFilter(name=DMUtils.make_private_vrf_filter_name(vrf_name))
f.set_comment(DMUtils.vrf_filter_comment(vrf_name))
firewall_config.add_firewall_filters(f)
term = Term(name="default-term", then=Then(accept_or_reject=True))
f.add_terms(term)
return f
示例8: add_inet_public_vrf_filter
def add_inet_public_vrf_filter(self, firewall_config, inet_type):
firewall_config.set_family(inet_type)
f = FirewallFilter(name=DMUtils.make_public_vrf_filter_name(inet_type))
f.set_comment(DMUtils.public_vrf_filter_comment())
firewall_config.add_firewall_filters(f)
term = Term(name="default-term", then=Then(accept_or_reject=True))
f.add_terms(term)
return f
示例9: build_underlay_bgp
def build_underlay_bgp(self):
if self.physical_router.allocated_asn is None:
self._logger.error("physical router %s(%s) does not have asn"
" allocated" % (self.physical_router.name,
self.physical_router.uuid))
return
for pi_obj, li_obj, iip_obj in self.\
fetch_pi_li_iip(self.physical_router.physical_interfaces):
if pi_obj and li_obj and iip_obj and iip_obj.instance_ip_address:
pi, li_map = self.set_default_pi(pi_obj.name, 'regular')
pi.set_comment(DMUtils.ip_clos_comment())
li = self.set_default_li(li_map, li_obj.name,
int(li_obj.name.split('.')[-1]))
li.set_comment(DMUtils.ip_clos_comment())
self.add_ip_address(li, iip_obj.instance_ip_address)
self._logger.debug("looking for peers for physical"
" interface %s(%s)" % (pi_obj.name,
pi_obj.uuid))
# Add this bgp object only if it has a peer
underlay_asn = self.physical_router.allocated_asn
bgp_name = DMUtils.make_underlay_bgp_group_name(underlay_asn,
li_obj.name, is_external=True)
bgp = Bgp(name=bgp_name,
ip_address=iip_obj.instance_ip_address,
autonomous_system=underlay_asn,
type_='external',
comment=DMUtils.ip_clos_comment())
peers = {}
# Assumption: PIs are connected for IP-CLOS peering only
for peer_pi_obj, peer_li_obj, peer_iip_obj in\
self.fetch_pi_li_iip(pi_obj.physical_interfaces):
if peer_pi_obj and peer_li_obj and peer_iip_obj and\
peer_iip_obj.instance_ip_address:
peer_pr = PhysicalRouterDM.get(
peer_pi_obj.physical_router)
if peer_pr is None:
self._logger.error(
"unable to read peer physical router %s"
% peer_pi_obj.physical_router)
elif peer_pr.allocated_asn is None:
self._logger.error(
"peer physical router %s does not have"
" asn allocated" % peer_pi_obj.physical_router)
elif peer_pr != self.physical_router:
peer = Bgp(name=peer_pr.name,
ip_address=peer_iip_obj.instance_ip_address,
autonomous_system=peer_pr.allocated_asn,
comment=peer_pr.name)
peers[peer_pr.name] = peer
if peers:
bgp.set_peers(self.get_values_sorted_by_key(peers))
self.bgp_map[bgp_name] = bgp
示例10: init_global_switch_opts
def init_global_switch_opts(self):
if self.global_switch_options_config is None:
self.global_switch_options_config = SwitchOptions(comment=DMUtils.switch_options_comment())
self.global_switch_options_config.set_vtep_source_interface("lo0.0")
if not self.routing_instances:
# no vn config then no need to configure vrf target
return
self.global_switch_options_config.add_vrf_target(VniTarget(auto=''))
switch_options_community = DMUtils.get_switch_vrf_import(self.get_asn())
self.global_switch_options_config.add_vrf_target(VniTarget(community=switch_options_community))
示例11: set_route_targets_config
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)
示例12: add_lo0_unit_0_interface
def add_lo0_unit_0_interface(self, loopback_ip=''):
if not loopback_ip:
return
if not self.interfaces_config:
self.interfaces_config = Interfaces(comment=DMUtils.interfaces_comment())
lo_intf = Interface(name="lo0")
self.interfaces_config.add_interface(lo_intf)
fam_inet = FamilyInet(address=[Address(name=loopback_ip + "/32",
primary='', preferred='')])
intf_unit = Unit(name="0", family=Family(inet=fam_inet),
comment=DMUtils.lo0_unit_0_comment())
lo_intf.add_unit(intf_unit)
示例13: add_inet_filter_term
def add_inet_filter_term(self, ri_name, prefixes, inet_type):
if inet_type == "inet6":
prefixes = DMUtils.get_ipv6_prefixes(prefixes)
else:
prefixes = DMUtils.get_ipv4_prefixes(prefixes)
from_ = From()
for prefix in prefixes:
from_.add_destination_address(prefix)
then_ = Then()
then_.add_routing_instance(ri_name)
return Term(name=DMUtils.make_vrf_term_name(ri_name), fromxx=from_, then=then_)
示例14: build_firewall_filters
def build_firewall_filters(self, sg, acl, is_egress=False):
acl_rule_present = False
if not sg or not acl or not acl.vnc_obj:
return
acl = acl.vnc_obj
entries = acl.get_access_control_list_entries()
if not entries:
return
rules = entries.get_acl_rule() or []
if not rules:
return
self.firewall_config = self.firewall_config or\
Firewall(DMUtils.firewall_comment())
for rule in rules:
if not self.has_terms(rule):
continue
match = rule.get_match_condition()
if not match:
continue
acl_rule_present = True
break
if acl_rule_present:
filter_name = DMUtils.make_sg_firewall_name(sg.name, acl.uuid)
f = FirewallFilter(name=filter_name)
f.set_comment(DMUtils.make_sg_firewall_comment(sg.name, acl.uuid))
# allow arp ether type always
self.add_ether_type_term(f, 'arp')
# allow dhcp/dns always
self.add_dns_dhcp_terms(f)
for rule in rules:
if not self.has_terms(rule):
continue
match = rule.get_match_condition()
if not match:
continue
rule_uuid = rule.get_rule_uuid()
dst_addr_match = match.get_dst_address()
dst_port_match = match.get_dst_port()
ether_type_match = match.get_ethertype()
protocol_match = match.get_protocol()
src_addr_match = match.get_src_address()
src_port_match = match.get_src_port()
term = self.add_filter_term(f, rule_uuid)
self.add_addr_term(term, dst_addr_match, False)
self.add_addr_term(term, src_addr_match, True)
self.add_port_term(term, dst_port_match, False)
# source port match is not needed for now (BMS source port)
#self.add_port_term(term, src_port_match, True)
self.add_protocol_term(term, protocol_match)
self.firewall_config.add_firewall_filters(f)
示例15: add_inet_filter_term
def add_inet_filter_term(self, ri_name, prefixes, inet_type):
term = etree.Element("term")
etree.SubElement(term, "name").text = DMUtils.make_vrf_term_name(ri_name)
from_ = etree.SubElement(term, "from")
if inet_type == 'inet6':
prefixes = DMUtils.get_ipv6_prefixes(prefixes)
else:
prefixes = DMUtils.get_ipv4_prefixes(prefixes)
for prefix in prefixes:
etree.SubElement(from_, "destination-address").text = prefix
then_ = etree.SubElement(term, "then")
etree.SubElement(then_, "routing-instance").text = ri_name
return term