From d6fd4eb8e6b84d51b7344f8a2c9321faf1dd0ce3 Mon Sep 17 00:00:00 2001 From: yanzhangi <51999930+yanzhangi@users.noreply.github.com> Date: Thu, 1 Aug 2019 01:28:46 +0800 Subject: [PATCH] update ce_bgp_af to fix bugs (#59678) * update ce_bgp_af to fix bugs * update ce_bgp_af to fix bugs * update ce_vrrp to fix bugs * update ce_bgp_af to fix bugs * update ce_bgp_af to fix bugs --- .../modules/network/cloudengine/ce_bgp_af.py | 186 ++++++++++-------- 1 file changed, 106 insertions(+), 80 deletions(-) diff --git a/lib/ansible/modules/network/cloudengine/ce_bgp_af.py b/lib/ansible/modules/network/cloudengine/ce_bgp_af.py index b8bb7c887c7..c0918996593 100644 --- a/lib/ansible/modules/network/cloudengine/ce_bgp_af.py +++ b/lib/ansible/modules/network/cloudengine/ce_bgp_af.py @@ -327,7 +327,6 @@ options: ''' EXAMPLES = ''' - - name: CloudEngine BGP address family test hosts: cloudengine connection: local @@ -339,23 +338,19 @@ EXAMPLES = ''' username: "{{ username }}" password: "{{ password }}" transport: cli - tasks: - - name: "Config BGP Address_Family" ce_bgp_af: state: present vrf_name: js af_type: ipv4uni provider: "{{ cli }}" - - name: "Undo BGP Address_Family" ce_bgp_af: state: absent vrf_name: js af_type: ipv4uni provider: "{{ cli }}" - - name: "Config import route" ce_bgp_af: state: present @@ -364,7 +359,6 @@ EXAMPLES = ''' import_protocol: ospf import_process_id: 123 provider: "{{ cli }}" - - name: "Undo import route" ce_bgp_af: state: absent @@ -373,7 +367,6 @@ EXAMPLES = ''' import_protocol: ospf import_process_id: 123 provider: "{{ cli }}" - - name: "Config network route" ce_bgp_af: state: present @@ -382,7 +375,6 @@ EXAMPLES = ''' network_address: 1.1.1.1 mask_len: 24 provider: "{{ cli }}" - - name: "Undo network route" ce_bgp_af: state: absent @@ -436,7 +428,7 @@ CE_GET_BGP_ADDRESS_FAMILY_HEADER = """ %s - + %s """ CE_GET_BGP_ADDRESS_FAMILY_TAIL = """ @@ -479,7 +471,7 @@ CE_CREATE_BGP_ADDRESS_FAMILY_HEADER = """ %s - + %s """ CE_CREATE_BGP_ADDRESS_FAMILY_TAIL = """ @@ -836,6 +828,7 @@ class BgpAf(object): need_cfg = False vrf_name = module.params['vrf_name'] + af_type = module.params['af_type'] if vrf_name: if len(vrf_name) > 31 or len(vrf_name) == 0: module.fail_json( @@ -846,7 +839,7 @@ class BgpAf(object): state = module.params['state'] af_type = module.params['af_type'] - conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % (vrf_name, af_type) + \ CE_GET_BGP_ADDRESS_FAMILY_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -888,6 +881,7 @@ class BgpAf(object): state = module.params['state'] vrf_name = module.params['vrf_name'] + af_type = module.params['af_type'] router_id = module.params['router_id'] if router_id: @@ -895,7 +889,7 @@ class BgpAf(object): module.fail_json( msg='Error: The len of router_id %s is out of [0 - 255].' % router_id) - conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % (vrf_name, af_type) + \ "" + CE_GET_BGP_ADDRESS_FAMILY_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -927,7 +921,7 @@ class BgpAf(object): determin_med = module.params['determin_med'] if determin_med != 'no_use': - conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % (vrf_name, af_type) + \ "" + CE_GET_BGP_ADDRESS_FAMILY_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -959,7 +953,7 @@ class BgpAf(object): ebgp_if_sensitive = module.params['ebgp_if_sensitive'] if ebgp_if_sensitive != 'no_use': - conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % (vrf_name, af_type) + \ "" + CE_GET_BGP_ADDRESS_FAMILY_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -991,7 +985,7 @@ class BgpAf(object): relay_delay_enable = module.params['relay_delay_enable'] if relay_delay_enable != 'no_use': - conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % (vrf_name, af_type) + \ "" + CE_GET_BGP_ADDRESS_FAMILY_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -1031,6 +1025,7 @@ class BgpAf(object): need_cfg = False vrf_name = module.params['vrf_name'] + af_type = module.params['af_type'] max_load_ibgp_num = module.params['max_load_ibgp_num'] if max_load_ibgp_num: @@ -1038,7 +1033,7 @@ class BgpAf(object): module.fail_json( msg='Error: The value of max_load_ibgp_num %s is out of [1 - 65535].' % max_load_ibgp_num) - conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % (vrf_name, af_type) + \ "" + CE_GET_BGP_ADDRESS_FAMILY_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -1059,7 +1054,7 @@ class BgpAf(object): ibgp_ecmp_nexthop_changed = module.params['ibgp_ecmp_nexthop_changed'] if ibgp_ecmp_nexthop_changed != 'no_use': - conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % (vrf_name, af_type) + \ "" + CE_GET_BGP_ADDRESS_FAMILY_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -1083,7 +1078,7 @@ class BgpAf(object): module.fail_json( msg='Error: The value of max_load_ebgp_num %s is out of [1 - 65535].' % max_load_ebgp_num) - conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % (vrf_name, af_type) + \ "" + CE_GET_BGP_ADDRESS_FAMILY_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -1104,7 +1099,7 @@ class BgpAf(object): ebgp_ecmp_nexthop_changed = module.params['ebgp_ecmp_nexthop_changed'] if ebgp_ecmp_nexthop_changed != 'no_use': - conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % (vrf_name, af_type) + \ "" + CE_GET_BGP_ADDRESS_FAMILY_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -1128,7 +1123,7 @@ class BgpAf(object): module.fail_json( msg='Error: The value of maximum_load_balance %s is out of [1 - 65535].' % maximum_load_balance) - conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % (vrf_name, af_type) + \ "" + CE_GET_BGP_ADDRESS_FAMILY_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -1149,7 +1144,7 @@ class BgpAf(object): ecmp_nexthop_changed = module.params['ecmp_nexthop_changed'] if ecmp_nexthop_changed != 'no_use': - conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % (vrf_name, af_type) + \ "" + CE_GET_BGP_ADDRESS_FAMILY_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -1173,7 +1168,7 @@ class BgpAf(object): module.fail_json( msg='Error: The value of default_local_pref %s is out of [0 - 4294967295].' % default_local_pref) - conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % (vrf_name, af_type) + \ "" + CE_GET_BGP_ADDRESS_FAMILY_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -1197,7 +1192,7 @@ class BgpAf(object): module.fail_json( msg='Error: The value of default_med %s is out of [0 - 4294967295].' % default_med) - conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % (vrf_name, af_type) + \ "" + CE_GET_BGP_ADDRESS_FAMILY_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -1218,7 +1213,7 @@ class BgpAf(object): default_rt_import_enable = module.params['default_rt_import_enable'] if default_rt_import_enable != 'no_use': - conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % (vrf_name, af_type) + \ "" + CE_GET_BGP_ADDRESS_FAMILY_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -1242,7 +1237,7 @@ class BgpAf(object): module.fail_json( msg='Error: The len of router_id %s is out of [0 - 255].' % router_id) - conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % (vrf_name, af_type) + \ "" + CE_GET_BGP_ADDRESS_FAMILY_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -1263,7 +1258,7 @@ class BgpAf(object): vrf_rid_auto_sel = module.params['vrf_rid_auto_sel'] if vrf_rid_auto_sel != 'no_use': - conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % (vrf_name, af_type) + \ "" + CE_GET_BGP_ADDRESS_FAMILY_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -1284,7 +1279,7 @@ class BgpAf(object): nexthop_third_party = module.params['nexthop_third_party'] if nexthop_third_party != 'no_use': - conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % (vrf_name, af_type) + \ "" + CE_GET_BGP_ADDRESS_FAMILY_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -1305,7 +1300,7 @@ class BgpAf(object): summary_automatic = module.params['summary_automatic'] if summary_automatic != 'no_use': - conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % (vrf_name, af_type) + \ "" + CE_GET_BGP_ADDRESS_FAMILY_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -1326,7 +1321,7 @@ class BgpAf(object): auto_frr_enable = module.params['auto_frr_enable'] if auto_frr_enable != 'no_use': - conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % (vrf_name, af_type) + \ "" + CE_GET_BGP_ADDRESS_FAMILY_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -1347,7 +1342,7 @@ class BgpAf(object): load_balancing_as_path_ignore = module.params['load_balancing_as_path_ignore'] if load_balancing_as_path_ignore != 'no_use': - conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % (vrf_name, af_type) + \ "" + \ CE_GET_BGP_ADDRESS_FAMILY_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -1369,7 +1364,7 @@ class BgpAf(object): rib_only_enable = module.params['rib_only_enable'] if rib_only_enable != 'no_use': - conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % (vrf_name, af_type) + \ "" + CE_GET_BGP_ADDRESS_FAMILY_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -1393,7 +1388,7 @@ class BgpAf(object): module.fail_json( msg='Error: The len of rib_only_policy_name %s is out of [1 - 40].' % rib_only_policy_name) - conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % (vrf_name, af_type) + \ "" + CE_GET_BGP_ADDRESS_FAMILY_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -1414,7 +1409,7 @@ class BgpAf(object): active_route_advertise = module.params['active_route_advertise'] if active_route_advertise != 'no_use': - conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % (vrf_name, af_type) + \ "" + CE_GET_BGP_ADDRESS_FAMILY_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -1435,7 +1430,7 @@ class BgpAf(object): as_path_neglect = module.params['as_path_neglect'] if as_path_neglect != 'no_use': - conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % (vrf_name, af_type) + \ "" + CE_GET_BGP_ADDRESS_FAMILY_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -1456,7 +1451,7 @@ class BgpAf(object): med_none_as_maximum = module.params['med_none_as_maximum'] if med_none_as_maximum != 'no_use': - conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % (vrf_name, af_type) + \ "" + CE_GET_BGP_ADDRESS_FAMILY_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -1477,7 +1472,7 @@ class BgpAf(object): router_id_neglect = module.params['router_id_neglect'] if router_id_neglect != 'no_use': - conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % (vrf_name, af_type) + \ "" + CE_GET_BGP_ADDRESS_FAMILY_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -1498,7 +1493,7 @@ class BgpAf(object): igp_metric_ignore = module.params['igp_metric_ignore'] if igp_metric_ignore != 'no_use': - conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % (vrf_name, af_type) + \ "" + CE_GET_BGP_ADDRESS_FAMILY_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -1519,7 +1514,7 @@ class BgpAf(object): always_compare_med = module.params['always_compare_med'] if always_compare_med != 'no_use': - conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % (vrf_name, af_type) + \ "" + CE_GET_BGP_ADDRESS_FAMILY_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -1540,7 +1535,7 @@ class BgpAf(object): determin_med = module.params['determin_med'] if determin_med != 'no_use': - conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % (vrf_name, af_type) + \ "" + CE_GET_BGP_ADDRESS_FAMILY_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -1564,7 +1559,7 @@ class BgpAf(object): module.fail_json( msg='Error: The value of preference_external %s is out of [1 - 255].' % preference_external) - conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % (vrf_name, af_type) + \ "" + CE_GET_BGP_ADDRESS_FAMILY_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -1588,7 +1583,7 @@ class BgpAf(object): module.fail_json( msg='Error: The value of preference_internal %s is out of [1 - 255].' % preference_internal) - conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % (vrf_name, af_type) + \ "" + CE_GET_BGP_ADDRESS_FAMILY_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -1612,7 +1607,7 @@ class BgpAf(object): module.fail_json( msg='Error: The value of preference_local %s is out of [1 - 255].' % preference_local) - conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % (vrf_name, af_type) + \ "" + CE_GET_BGP_ADDRESS_FAMILY_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -1636,7 +1631,7 @@ class BgpAf(object): module.fail_json( msg='Error: The len of prefrence_policy_name %s is out of [1 - 40].' % prefrence_policy_name) - conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % (vrf_name, af_type) + \ "" + CE_GET_BGP_ADDRESS_FAMILY_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -1657,7 +1652,7 @@ class BgpAf(object): reflect_between_client = module.params['reflect_between_client'] if reflect_between_client != 'no_use': - conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % (vrf_name, af_type) + \ "" + CE_GET_BGP_ADDRESS_FAMILY_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -1682,7 +1677,7 @@ class BgpAf(object): msg='Error: The value of reflector_cluster_id %s is out of ' '[1 - 4294967295].' % reflector_cluster_id) - conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % (vrf_name, af_type) + \ "" + CE_GET_BGP_ADDRESS_FAMILY_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -1706,7 +1701,7 @@ class BgpAf(object): module.fail_json( msg='Error: The len of reflector_cluster_ipv4 %s is out of [0 - 255].' % reflector_cluster_ipv4) - conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % (vrf_name, af_type) + \ "" + CE_GET_BGP_ADDRESS_FAMILY_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -1730,7 +1725,7 @@ class BgpAf(object): module.fail_json( msg='Error: The len of rr_filter_number %s is out of [1 - 51].' % rr_filter_number) - conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % (vrf_name, af_type) + \ "" + CE_GET_BGP_ADDRESS_FAMILY_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -1751,7 +1746,7 @@ class BgpAf(object): policy_vpn_target = module.params['policy_vpn_target'] if policy_vpn_target != 'no_use': - conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % (vrf_name, af_type) + \ "" + CE_GET_BGP_ADDRESS_FAMILY_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -1772,7 +1767,7 @@ class BgpAf(object): next_hop_sel_depend_type = module.params['next_hop_sel_depend_type'] if next_hop_sel_depend_type: - conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % (vrf_name, af_type) + \ "" + CE_GET_BGP_ADDRESS_FAMILY_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -1798,7 +1793,7 @@ class BgpAf(object): msg='Error: The len of nhp_relay_route_policy_name %s is ' 'out of [1 - 40].' % nhp_relay_route_policy_name) - conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % (vrf_name, af_type) + \ "" + \ CE_GET_BGP_ADDRESS_FAMILY_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -1820,7 +1815,7 @@ class BgpAf(object): ebgp_if_sensitive = module.params['ebgp_if_sensitive'] if ebgp_if_sensitive != 'no_use': - conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % (vrf_name, af_type) + \ "" + CE_GET_BGP_ADDRESS_FAMILY_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -1841,7 +1836,7 @@ class BgpAf(object): reflect_chg_path = module.params['reflect_chg_path'] if reflect_chg_path != 'no_use': - conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % (vrf_name, af_type) + \ "" + CE_GET_BGP_ADDRESS_FAMILY_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -1865,7 +1860,7 @@ class BgpAf(object): module.fail_json( msg='Error: The value of add_path_sel_num %s is out of [2 - 64].' % add_path_sel_num) - conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % (vrf_name, af_type) + \ "" + CE_GET_BGP_ADDRESS_FAMILY_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -1889,7 +1884,7 @@ class BgpAf(object): module.fail_json( msg='Error: The value of route_sel_delay %s is out of [0 - 3600].' % route_sel_delay) - conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % (vrf_name, af_type) + \ "" + CE_GET_BGP_ADDRESS_FAMILY_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -1910,7 +1905,7 @@ class BgpAf(object): allow_invalid_as = module.params['allow_invalid_as'] if allow_invalid_as != 'no_use': - conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % (vrf_name, af_type) + \ "" + CE_GET_BGP_ADDRESS_FAMILY_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -1931,7 +1926,7 @@ class BgpAf(object): policy_ext_comm_enable = module.params['policy_ext_comm_enable'] if policy_ext_comm_enable != 'no_use': - conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % (vrf_name, af_type) + \ "" + CE_GET_BGP_ADDRESS_FAMILY_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -1952,7 +1947,7 @@ class BgpAf(object): supernet_uni_adv = module.params['supernet_uni_adv'] if supernet_uni_adv != 'no_use': - conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % (vrf_name, af_type) + \ "" + CE_GET_BGP_ADDRESS_FAMILY_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -1973,7 +1968,7 @@ class BgpAf(object): supernet_label_adv = module.params['supernet_label_adv'] if supernet_label_adv != 'no_use': - conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % (vrf_name, af_type) + \ "" + CE_GET_BGP_ADDRESS_FAMILY_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -1997,7 +1992,7 @@ class BgpAf(object): module.fail_json( msg='Error: The len of ingress_lsp_policy_name %s is out of [1 - 40].' % ingress_lsp_policy_name) - conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % (vrf_name, af_type) + \ "" + CE_GET_BGP_ADDRESS_FAMILY_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -2018,7 +2013,7 @@ class BgpAf(object): originator_prior = module.params['originator_prior'] if originator_prior != 'no_use': - conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % (vrf_name, af_type) + \ "" + CE_GET_BGP_ADDRESS_FAMILY_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -2039,7 +2034,7 @@ class BgpAf(object): lowest_priority = module.params['lowest_priority'] if lowest_priority != 'no_use': - conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % (vrf_name, af_type) + \ "" + CE_GET_BGP_ADDRESS_FAMILY_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -2060,7 +2055,7 @@ class BgpAf(object): relay_delay_enable = module.params['relay_delay_enable'] if relay_delay_enable != 'no_use': - conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_ADDRESS_FAMILY_HEADER % (vrf_name, af_type) + \ "" + CE_GET_BGP_ADDRESS_FAMILY_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -2229,18 +2224,19 @@ class BgpAf(object): cmds = [] cmd = "ipv4-family vpn-instance %s" % vrf_name - cmds.append(cmd) if af_type == "ipv4multi": cmd = "ipv4-family multicast" elif af_type == "ipv4vpn": cmd = "ipv4-family vpnv4" elif af_type == "ipv6uni": - cmd = "ipv6-family unicast" + cmd = "ipv6-family vpn-instance %s" % vrf_name + if vrf_name == "_public_": + cmd = "ipv6-family unicast" elif af_type == "ipv6vpn": cmd = "ipv6-family vpnv6" elif af_type == "evpn": - cmd = "ipv6-family vpn-instance %s" % vrf_name + cmd = "l2vpn-family evpn" cmds.append(cmd) return cmds @@ -2265,18 +2261,19 @@ class BgpAf(object): cmds = [] cmd = "ipv4-family vpn-instance %s" % vrf_name - cmds.append(cmd) if af_type == "ipv4multi": cmd = "ipv4-family multicast" elif af_type == "ipv4vpn": cmd = "ipv4-family vpnv4" elif af_type == "ipv6uni": - cmd = "ipv6-family unicast" + cmd = "ipv6-family vpn-instance %s" % vrf_name + if vrf_name == "_public_": + cmd = "ipv6-family unicast" elif af_type == "ipv6vpn": cmd = "ipv6-family vpnv6" elif af_type == "evpn": - cmd = "ipv6-family vpn-instance %s" % vrf_name + cmd = "l2vpn-family evpn" cmds.append(cmd) return cmds @@ -2301,18 +2298,19 @@ class BgpAf(object): cmds = [] cmd = "undo ipv4-family vpn-instance %s" % vrf_name - cmds.append(cmd) if af_type == "ipv4multi": cmd = "undo ipv4-family multicast" elif af_type == "ipv4vpn": cmd = "undo ipv4-family vpnv4" elif af_type == "ipv6uni": - cmd = "undo ipv6-family unicast" + cmd = "undo ipv6-family vpn-instance %s" % vrf_name + if vrf_name == "_public_": + cmd = "undo ipv6-family unicast" elif af_type == "ipv6vpn": cmd = "undo ipv6-family vpnv6" elif af_type == "evpn": - cmd = "undo ipv6-family vpn-instance %s" % vrf_name + cmd = "l2vpn-family evpn" cmds.append(cmd) return cmds @@ -2342,7 +2340,9 @@ class BgpAf(object): if ibgp_ecmp_nexthop_changed == "true": cmd = "maximum load-balancing ibgp %s ecmp-nexthop-changed" % max_load_ibgp_num cmds.append(cmd) - + else: + cmd = "undo maximum load-balancing ibgp %s ecmp-nexthop-changed" % max_load_ibgp_num + cmds.append(cmd) max_load_ebgp_num = module.params['max_load_ebgp_num'] if max_load_ebgp_num: conf_str += "%s" % max_load_ebgp_num @@ -2411,12 +2411,19 @@ class BgpAf(object): vrf_rid_auto_sel = module.params['vrf_rid_auto_sel'] if vrf_rid_auto_sel != 'no_use': conf_str += "%s" % vrf_rid_auto_sel - + family = "ipv4-family" + if af_type == "ipv6uni": + family = "ipv6-family" if vrf_rid_auto_sel == "true": - cmd = "router-id %s vpn-instance auto-select" % router_id + cmd = "%s vpn-instance %s" % (family, vrf_name) + cmds.append(cmd) + cmd = "router-id auto-select" + cmds.append(cmd) else: - cmd = "undo router-id %s vpn-instance auto-select" % router_id - cmds.append(cmd) + cmd = "%s vpn-instance %s" % (family, vrf_name) + cmds.append(cmd) + cmd = "undo router-id auto-select" + cmds.append(cmd) nexthop_third_party = module.params['nexthop_third_party'] if nexthop_third_party != 'no_use': @@ -2470,7 +2477,7 @@ class BgpAf(object): cmds.append(cmd) rib_only_policy_name = module.params['rib_only_policy_name'] - if rib_only_policy_name: + if rib_only_policy_name and rib_only_enable == "true": conf_str += "%s" % rib_only_policy_name cmd = "routing-table rib-only route-policy %s" % rib_only_policy_name @@ -2500,7 +2507,7 @@ class BgpAf(object): if med_none_as_maximum != 'no_use': conf_str += "%s" % med_none_as_maximum - if med_none_as_maximum: + if med_none_as_maximum == "true": cmd = "bestroute med-none-as-maximum" else: cmd = "undo bestroute med-none-as-maximum" @@ -2523,7 +2530,9 @@ class BgpAf(object): if igp_metric_ignore == "true": cmd = "bestroute igp-metric-ignore" cmds.append(cmd) - + else: + cmd = "undo bestroute igp-metric-ignore" + cmds.append(cmd) always_compare_med = module.params['always_compare_med'] if always_compare_med != 'no_use': conf_str += "%s" % always_compare_med @@ -2531,7 +2540,9 @@ class BgpAf(object): if always_compare_med == "true": cmd = "compare-different-as-med" cmds.append(cmd) - + else: + cmd = "undo compare-different-as-med" + cmds.append(cmd) determin_med = module.params['determin_med'] if determin_med != 'no_use': conf_str += "%s" % determin_med @@ -2539,6 +2550,9 @@ class BgpAf(object): if determin_med == "true": cmd = "deterministic-med" cmds.append(cmd) + else: + cmd = "undo deterministic-med" + cmds.append(cmd) preference_external = module.params['preference_external'] if preference_external: @@ -2590,10 +2604,17 @@ class BgpAf(object): rr_filter_number = module.params['rr_filter_number'] if rr_filter_number: conf_str += "%s" % rr_filter_number + cmd = 'rr-filter %s' % rr_filter_number + cmds.append(cmd) policy_vpn_target = module.params['policy_vpn_target'] if policy_vpn_target != 'no_use': conf_str += "%s" % policy_vpn_target + if policy_vpn_target == 'true': + cmd = 'policy vpn-target' + else: + cmd = 'undo policy vpn-target' + cmds.append(cmd) next_hop_sel_depend_type = module.params['next_hop_sel_depend_type'] if next_hop_sel_depend_type: @@ -2815,6 +2836,8 @@ class BgpAf(object): cmds = [] cmd = "import-route %s %s" % (import_protocol, import_process_id) + if import_process_id == "0": + cmd = "import-route %s" % import_protocol cmds.append(cmd) return cmds @@ -3383,6 +3406,9 @@ def main(): end_tmp[item] = bgp_import_network_route_rst[item] if end_tmp: end_state["bgp import & network route"] = end_tmp + if end_state == existing: + changed = False + updates = list() results = dict() results['proposed'] = proposed