From 9a45453ab1941dc4c97fd606144caedc55bfc3bf Mon Sep 17 00:00:00 2001 From: sbalineni Date: Fri, 24 Feb 2017 12:30:30 -0800 Subject: [PATCH] [DM]: Improved naming conventions for DM generated JUNOS config Change-Id: If24cf289800cfd065e0e77943c388e954ccc8713 Partial-Bug: #1468210 --- .../device-manager/device_manager/dm_utils.py | 47 ++++++++++++------- .../device_manager/physical_router_config.py | 12 +++-- 2 files changed, 38 insertions(+), 21 deletions(-) diff --git a/src/config/device-manager/device_manager/dm_utils.py b/src/config/device-manager/device_manager/dm_utils.py index ab2fc8e89d3..36c568e8b76 100644 --- a/src/config/device-manager/device_manager/dm_utils.py +++ b/src/config/device-manager/device_manager/dm_utils.py @@ -16,21 +16,35 @@ class DMUtils(object): MAX_FILTER_TERM_NAME_LENGTH = 63 LO0_INTF_UNIT_START_ID = 1000 + @staticmethod + def contrail_prefix(name=''): + return "_contrail_" + name + @staticmethod def make_vrf_name(name, network_id, vrf_type, is_nat=False): - vrf_name = '' + vrf_name = DMUtils.contrail_prefix(name) + network_id_str = '-' + str(network_id) + nat_postfix = '-nat' + vrf_type_str = '-' + str(vrf_type) + # mx has limitation for vrf name, allowed max 127 chars if not vrf_type: - vrf_name = '_contrail_' + \ - str(network_id) + '_' + name + if is_nat: + post_len = len(network_id_str) + len(nat_postfix) + return vrf_name[:DMUtils.MAX_VRF_NAME_LENGTH - post_len] + network_id_str + nat_postfix + post_len = len(network_id_str) + return vrf_name[:DMUtils.MAX_VRF_NAME_LENGTH - post_len] + network_id_str else: - vrf_name = '_contrail_' + vrf_type + '_' + \ - str(network_id) + '_' + name - # mx has limitation for vrf name, allowed max 127 chars - if is_nat: - return vrf_name[:DMUtils.MAX_VRF_NAME_LENGTH - 4] + '-nat' - return vrf_name[:DMUtils.MAX_VRF_NAME_LENGTH] + if is_nat: + post_len = len(network_id_str) + len(nat_postfix) + len(vrf_type_str) + return vrf_name[:DMUtils.MAX_VRF_NAME_LENGTH - post_len] + vrf_type_str + network_id_str + nat_postfix + post_len = len(network_id_str) + len(vrf_type_str) + return vrf_name[:DMUtils.MAX_VRF_NAME_LENGTH - post_len] + vrf_type_str + network_id_str #end make_vrf_name + @staticmethod + def dynamic_tunnel_name(asn): + return DMUtils.contrail_prefix() + "asn-" + str(asn) + @staticmethod def get_network_gateways(ipam_refs=[]): gateways = {} @@ -59,7 +73,7 @@ def make_import_name(ri_name): @staticmethod def make_community_name(rt_name): - return rt_name.replace(':', '_') + return DMUtils.contrail_prefix(rt_name.replace(':', '_')) # end make_community_name @staticmethod @@ -86,15 +100,15 @@ def make_dnat_rule_name(ri_name): @staticmethod def make_private_vrf_filter_name(ri_name): - ri_prefix = ri_name[:DMUtils.MAX_FILTER_NAME_LENGTH - len('redirect_to_') - len('_vrf')] - return 'redirect_to_' + ri_prefix + '_vrf' + ri_prefix = ri_name[:DMUtils.MAX_FILTER_NAME_LENGTH - len('redirect-to-') - len('-vrf')] + return 'redirect-to-' + ri_prefix + '-vrf' # end make_private_vrf_filter_name @staticmethod def make_public_vrf_filter_name(inet_type): if inet_type == 'inet': inet_type = 'inet4' - return 'redirect_to_public_vrf_filter_' + inet_type + return DMUtils.contrail_prefix('redirect-to-public-vrfs-' + inet_type) # end make_public_filter_name @staticmethod @@ -116,10 +130,11 @@ def make_vrf_term_name(ri_name): # end make_vrf_term_name @staticmethod - def make_bgp_group_name(is_external=False): + def make_bgp_group_name(asn, is_external=False): + name = DMUtils.contrail_prefix() + "asn-" + str(asn) if is_external: - return '__contrail_external__' - return '__contrail__' + return name + "-external" + return name # end make_bgp_group_name @staticmethod diff --git a/src/config/device-manager/device_manager/physical_router_config.py b/src/config/device-manager/device_manager/physical_router_config.py index 1a5f78a5126..c76d56fcf77 100644 --- a/src/config/device-manager/device_manager/physical_router_config.py +++ b/src/config/device-manager/device_manager/physical_router_config.py @@ -232,7 +232,7 @@ def add_static_routes(self, parent, static_routes): def add_dynamic_tunnels(self, tunnel_source_ip, ip_fabric_nets, bgp_router_ips): - dynamic_tunnel = DynamicTunnel(name="__contrail__", + dynamic_tunnel = DynamicTunnel(name=DMUtils.dynamic_tunnel_name(self.get_asn()), source_address=tunnel_source_ip, gre='') if ip_fabric_nets is not None: for subnet in ip_fabric_nets.get("subnet", []): @@ -819,11 +819,11 @@ def _get_bgp_config_xml(self, external=False): bgp_group = BgpGroup() bgp_group.set_comment(DMUtils.bgp_group_comment(self.bgp_obj)) if external: - bgp_group.set_name(DMUtils.make_bgp_group_name(True)) + bgp_group.set_name(DMUtils.make_bgp_group_name(self.get_asn(), True)) bgp_group.set_type('external') bgp_group.set_multihop('') else: - bgp_group.set_name(DMUtils.make_bgp_group_name(False)) + bgp_group.set_name(DMUtils.make_bgp_group_name(self.get_asn(), False)) bgp_group.set_type('internal') bgp_group.set_local_address(self.bgp_params['address']) self.add_families(bgp_group, self.bgp_params) @@ -891,12 +891,14 @@ def _get_neighbor_config_xml(self, bgp_config, peers): nbr.set_peer_as(peer_as) # end _get_neighbor_config_xml + def get_asn(self): + return self.bgp_params.get('local_autonomous_system') or self.bgp_params.get('autonomous_system') + def set_as_config(self): if self.global_routing_options_config is None: self.global_routing_options_config = RoutingOptions(comment=DMUtils.routing_options_comment()) self.global_routing_options_config.set_route_distinguisher_id(self.bgp_params['identifier']) - local_as = self.bgp_params.get('local_autonomous_system') or self.bgp_params.get('autonomous_system') - self.global_routing_options_config.set_autonomous_system(str(local_as)) + self.global_routing_options_config.set_autonomous_system(str(self.get_asn())) # end set_as_config def set_route_targets_config(self):