diff --git a/changelogs/fragments/57317-update-bgp-modules-to-fix-some-bugs.yml b/changelogs/fragments/57317-update-bgp-modules-to-fix-some-bugs.yml new file mode 100644 index 00000000000..5cf6411db79 --- /dev/null +++ b/changelogs/fragments/57317-update-bgp-modules-to-fix-some-bugs.yml @@ -0,0 +1,5 @@ +bugfixes: + - Fixed ce_bgp,first the pattern to be searched is need to change, otherwise there is no data to be found.then after running a task with this module,it will not show 'changed' correctly. + - Fixed ce_bgp_af,'changed' of module run restult is not showed, however the module run correctly,and update coommands of result is not correct. + - Fixed ce_bgp_neighbor, find specify bgp as information, as number is necessary and so on. + - Fixed ce_bgp_neighbor_af,update commands should be showed correctly, and xml for filter and edit are also re-factor as the software version upgrade and update. diff --git a/lib/ansible/modules/network/cloudengine/ce_bgp.py b/lib/ansible/modules/network/cloudengine/ce_bgp.py index 0396ed4e3be..cdd711de5bb 100644 --- a/lib/ansible/modules/network/cloudengine/ce_bgp.py +++ b/lib/ansible/modules/network/cloudengine/ce_bgp.py @@ -1254,7 +1254,7 @@ class Bgp(object): return result else: re_find = re.findall( - r'.*(.*).*\s*(.*).*', xml_str) + r'.*(.*).*\s*(.*).*', xml_str) if re_find: return re_find @@ -2127,9 +2127,12 @@ def main(): bgp_enable_exist = ce_bgp_obj.get_bgp_enable(module=module) existing["bgp enable"] = bgp_enable_exist - - asnumber_exist = bgp_enable_exist[0][0] - bgpenable_exist = bgp_enable_exist[0][1] + if bgp_enable_exist: + asnumber_exist = bgp_enable_exist[0][0] + bgpenable_exist = bgp_enable_exist[0][1] + else: + asnumber_exist = None + bgpenable_exist = None if state == "present": bgp_enable_new = (as_number, "true") @@ -2300,7 +2303,9 @@ def main(): if end_tmp: end_state["bgp instance other"] = end_tmp - + if end_state == existing: + changed = False + updates = list() results = dict() results['proposed'] = proposed results['existing'] = existing diff --git a/lib/ansible/modules/network/cloudengine/ce_bgp_af.py b/lib/ansible/modules/network/cloudengine/ce_bgp_af.py index 20bbd5b17f4..b8bb7c887c7 100644 --- a/lib/ansible/modules/network/cloudengine/ce_bgp_af.py +++ b/lib/ansible/modules/network/cloudengine/ce_bgp_af.py @@ -2678,10 +2678,17 @@ class BgpAf(object): ingress_lsp_policy_name = module.params['ingress_lsp_policy_name'] if ingress_lsp_policy_name: conf_str += "%s" % ingress_lsp_policy_name + cmd = "ingress-lsp trigger route-policy %s" % ingress_lsp_policy_name + cmds.append(cmd) originator_prior = module.params['originator_prior'] if originator_prior != 'no_use': conf_str += "%s" % originator_prior + if originator_prior == "true": + cmd = "bestroute routerid-prior-clusterlist" + else: + cmd = "undo bestroute routerid-prior-clusterlist" + cmds.append(cmd) lowest_priority = module.params['lowest_priority'] if lowest_priority != 'no_use': @@ -2697,6 +2704,11 @@ class BgpAf(object): if relay_delay_enable != 'no_use': conf_str += "%s" % relay_delay_enable + if relay_delay_enable == "true": + cmd = "nexthop recursive-lookup restrain enable" + else: + cmd = "nexthop recursive-lookup restrain disable" + cmds.append(cmd) conf_str += CE_MERGE_BGP_ADDRESS_FAMILY_TAIL recv_xml = self.netconf_set_config(module=module, conf_str=conf_str) @@ -2766,7 +2778,7 @@ class BgpAf(object): import_process_id = "0" conf_str = CE_MERGE_BGP_IMPORT_ROUTE_HEADER % ( - vrf_name, af_type, import_protocol, import_process_id) + CE_MERGE_BGP_ADDRESS_FAMILY_TAIL + vrf_name, af_type, import_protocol, import_process_id) + CE_MERGE_BGP_IMPORT_ROUTE_TAIL recv_xml = self.netconf_set_config(module=module, conf_str=conf_str) diff --git a/lib/ansible/modules/network/cloudengine/ce_bgp_neighbor.py b/lib/ansible/modules/network/cloudengine/ce_bgp_neighbor.py index 23f5f2b8c05..796bb109bbd 100644 --- a/lib/ansible/modules/network/cloudengine/ce_bgp_neighbor.py +++ b/lib/ansible/modules/network/cloudengine/ce_bgp_neighbor.py @@ -261,7 +261,7 @@ CE_GET_BGP_PEER_HEADER = """ %s - + %s """ CE_GET_BGP_PEER_TAIL = """ @@ -273,7 +273,6 @@ CE_GET_BGP_PEER_TAIL = """ """ - # merge bgp peer CE_MERGE_BGP_PEER_HEADER = """ @@ -475,6 +474,7 @@ class BgpNeighbor(object): result = dict() need_cfg = False + peerip = module.params['peer_addr'] vrf_name = module.params['vrf_name'] if vrf_name: if len(vrf_name) > 31 or len(vrf_name) == 0: @@ -487,7 +487,7 @@ class BgpNeighbor(object): module.fail_json( msg='Error: The len of description %s is out of [1 - 80].' % description) - conf_str = CE_GET_BGP_PEER_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_PEER_HEADER % (vrf_name, peerip) + \ "" + CE_GET_BGP_PEER_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -510,7 +510,7 @@ class BgpNeighbor(object): module.fail_json( msg='Error: The len of fake_as %s is out of [1 - 11].' % fake_as) - conf_str = CE_GET_BGP_PEER_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_PEER_HEADER % (vrf_name, peerip) + \ "" + CE_GET_BGP_PEER_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -530,7 +530,7 @@ class BgpNeighbor(object): dual_as = module.params['dual_as'] if dual_as != 'no_use': - conf_str = CE_GET_BGP_PEER_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_PEER_HEADER % (vrf_name, peerip) + \ "" + CE_GET_BGP_PEER_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -542,7 +542,7 @@ class BgpNeighbor(object): if re_find: result["dual_as"] = re_find - if re_find[0] != fake_as: + if re_find[0] != dual_as: need_cfg = True else: need_cfg = True @@ -550,10 +550,9 @@ class BgpNeighbor(object): conventional = module.params['conventional'] if conventional != 'no_use': - conf_str = CE_GET_BGP_PEER_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_PEER_HEADER % (vrf_name, peerip) + \ "" + CE_GET_BGP_PEER_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) - if "" in recv_xml: need_cfg = True else: @@ -570,7 +569,7 @@ class BgpNeighbor(object): route_refresh = module.params['route_refresh'] if route_refresh != 'no_use': - conf_str = CE_GET_BGP_PEER_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_PEER_HEADER % (vrf_name, peerip) + \ "" + CE_GET_BGP_PEER_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -590,7 +589,7 @@ class BgpNeighbor(object): four_byte_as = module.params['four_byte_as'] if four_byte_as != 'no_use': - conf_str = CE_GET_BGP_PEER_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_PEER_HEADER % (vrf_name, peerip) + \ "" + CE_GET_BGP_PEER_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -610,7 +609,7 @@ class BgpNeighbor(object): is_ignore = module.params['is_ignore'] if is_ignore != 'no_use': - conf_str = CE_GET_BGP_PEER_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_PEER_HEADER % (vrf_name, peerip) + \ "" + CE_GET_BGP_PEER_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -633,7 +632,7 @@ class BgpNeighbor(object): module.fail_json( msg='Error: The len of local_if_name %s is out of [1 - 63].' % local_if_name) - conf_str = CE_GET_BGP_PEER_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_PEER_HEADER % (vrf_name, peerip) + \ "" + CE_GET_BGP_PEER_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -645,7 +644,7 @@ class BgpNeighbor(object): if re_find: result["local_if_name"] = re_find - if re_find[0] != local_if_name: + if re_find[0].lower() != local_if_name.lower(): need_cfg = True else: need_cfg = True @@ -656,7 +655,7 @@ class BgpNeighbor(object): module.fail_json( msg='Error: The value of ebgp_max_hop %s is out of [1 - 255].' % ebgp_max_hop) - conf_str = CE_GET_BGP_PEER_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_PEER_HEADER % (vrf_name, peerip) + \ "" + CE_GET_BGP_PEER_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -679,7 +678,7 @@ class BgpNeighbor(object): module.fail_json( msg='Error: The value of valid_ttl_hops %s is out of [1 - 255].' % valid_ttl_hops) - conf_str = CE_GET_BGP_PEER_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_PEER_HEADER % (vrf_name, peerip) + \ "" + CE_GET_BGP_PEER_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -699,7 +698,7 @@ class BgpNeighbor(object): connect_mode = module.params['connect_mode'] if connect_mode: - conf_str = CE_GET_BGP_PEER_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_PEER_HEADER % (vrf_name, peerip) + \ "" + CE_GET_BGP_PEER_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -719,7 +718,7 @@ class BgpNeighbor(object): is_log_change = module.params['is_log_change'] if is_log_change != 'no_use': - conf_str = CE_GET_BGP_PEER_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_PEER_HEADER % (vrf_name, peerip) + \ "" + CE_GET_BGP_PEER_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -739,7 +738,7 @@ class BgpNeighbor(object): pswd_type = module.params['pswd_type'] if pswd_type: - conf_str = CE_GET_BGP_PEER_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_PEER_HEADER % (vrf_name, peerip) + \ "" + CE_GET_BGP_PEER_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -762,7 +761,7 @@ class BgpNeighbor(object): module.fail_json( msg='Error: The len of pswd_cipher_text %s is out of [1 - 255].' % pswd_cipher_text) - conf_str = CE_GET_BGP_PEER_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_PEER_HEADER % (vrf_name, peerip) + \ "" + CE_GET_BGP_PEER_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -785,7 +784,7 @@ class BgpNeighbor(object): module.fail_json( msg='Error: The len of keep_alive_time %s is out of [0 - 21845].' % keep_alive_time) - conf_str = CE_GET_BGP_PEER_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_PEER_HEADER % (vrf_name, peerip) + \ "" + CE_GET_BGP_PEER_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -808,7 +807,7 @@ class BgpNeighbor(object): module.fail_json( msg='Error: The value of hold_time %s is out of [0 or 3 - 65535].' % hold_time) - conf_str = CE_GET_BGP_PEER_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_PEER_HEADER % (vrf_name, peerip) + \ "" + CE_GET_BGP_PEER_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -831,7 +830,7 @@ class BgpNeighbor(object): module.fail_json( msg='Error: The value of min_hold_time %s is out of [0 or 20 - 65535].' % min_hold_time) - conf_str = CE_GET_BGP_PEER_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_PEER_HEADER % (vrf_name, peerip) + \ "" + CE_GET_BGP_PEER_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -854,7 +853,7 @@ class BgpNeighbor(object): module.fail_json( msg='Error: The len of key_chain_name %s is out of [1 - 47].' % key_chain_name) - conf_str = CE_GET_BGP_PEER_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_PEER_HEADER % (vrf_name, peerip) + \ "" + CE_GET_BGP_PEER_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -877,7 +876,7 @@ class BgpNeighbor(object): module.fail_json( msg='Error: The value of conn_retry_time %s is out of [1 - 65535].' % conn_retry_time) - conf_str = CE_GET_BGP_PEER_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_PEER_HEADER % (vrf_name, peerip) + \ "" + CE_GET_BGP_PEER_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -900,7 +899,7 @@ class BgpNeighbor(object): module.fail_json( msg='Error: The value of tcp_mss %s is out of [176 - 4096].' % tcp_mss) - conf_str = CE_GET_BGP_PEER_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_PEER_HEADER % (vrf_name, peerip) + \ "" + CE_GET_BGP_PEER_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -920,7 +919,7 @@ class BgpNeighbor(object): mpls_local_ifnet_disable = module.params['mpls_local_ifnet_disable'] if mpls_local_ifnet_disable != 'no_use': - conf_str = CE_GET_BGP_PEER_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_PEER_HEADER % (vrf_name, peerip) + \ "" + CE_GET_BGP_PEER_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -940,7 +939,7 @@ class BgpNeighbor(object): prepend_global_as = module.params['prepend_global_as'] if prepend_global_as != 'no_use': - conf_str = CE_GET_BGP_PEER_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_PEER_HEADER % (vrf_name, peerip) + \ "" + CE_GET_BGP_PEER_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -960,7 +959,7 @@ class BgpNeighbor(object): prepend_fake_as = module.params['prepend_fake_as'] if prepend_fake_as != 'no_use': - conf_str = CE_GET_BGP_PEER_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_PEER_HEADER % (vrf_name, peerip) + \ "" + CE_GET_BGP_PEER_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -1276,14 +1275,14 @@ class BgpNeighbor(object): """ get_bgp_peer """ module = kwargs["module"] - + peerip = module.params['peer_addr'] vrf_name = module.params['vrf_name'] if vrf_name: if len(vrf_name) > 31 or len(vrf_name) == 0: module.fail_json( msg='Error: The len of vrf_name %s is out of [1 - 31].' % vrf_name) - conf_str = CE_GET_BGP_PEER_HEADER % vrf_name + \ + conf_str = CE_GET_BGP_PEER_HEADER % (vrf_name, peerip) + \ "" + CE_GET_BGP_PEER_TAIL xml_str = self.netconf_get_config(module=module, conf_str=conf_str) @@ -1305,14 +1304,14 @@ class BgpNeighbor(object): """ get_bgp_del_peer """ module = kwargs["module"] - + peerip = module.params['peer_addr'] vrf_name = module.params['vrf_name'] if vrf_name: if len(vrf_name) > 31 or len(vrf_name) == 0: module.fail_json( msg='Error: The len of vrf_name %s is out of [1 - 31].' % vrf_name) - conf_str = CE_GET_BGP_PEER_HEADER % vrf_name + CE_GET_BGP_PEER_TAIL + conf_str = CE_GET_BGP_PEER_HEADER % (vrf_name, peerip) + CE_GET_BGP_PEER_TAIL xml_str = self.netconf_get_config(module=module, conf_str=conf_str) @@ -1434,7 +1433,6 @@ class BgpNeighbor(object): conventional = module.params['conventional'] if conventional != 'no_use': conf_str += "%s" % conventional - if conventional == "true": cmd = "peer %s capability-advertise conventional" % peer_addr else: @@ -1494,7 +1492,6 @@ class BgpNeighbor(object): connect_mode = module.params['connect_mode'] if connect_mode: - conf_str += "%s" % connect_mode if connect_mode == "listenOnly": cmd = "peer %s listen-only" % peer_addr @@ -1502,11 +1499,13 @@ class BgpNeighbor(object): elif connect_mode == "connectOnly": cmd = "peer %s connect-only" % peer_addr cmds.append(cmd) - elif connect_mode == "null": + elif connect_mode == "both": + connect_mode = "null" cmd = "peer %s listen-only" % peer_addr cmds.append(cmd) cmd = "peer %s connect-only" % peer_addr cmds.append(cmd) + conf_str += "%s" % connect_mode is_log_change = module.params['is_log_change'] if is_log_change != 'no_use': @@ -1595,6 +1594,12 @@ class BgpNeighbor(object): if prepend_fake_as != 'no_use': conf_str += "%s" % prepend_fake_as + if prepend_fake_as == "true": + cmd = "peer %s prepend-local-as" % peer_addr + else: + cmd = "undo peer %s prepend-local-as" % peer_addr + cmds.append(cmd) + conf_str += CE_MERGE_BGP_PEER_TAIL recv_xml = self.netconf_set_config(module=module, conf_str=conf_str) @@ -1759,7 +1764,7 @@ def main(): local_if_name=dict(type='str'), ebgp_max_hop=dict(type='str'), valid_ttl_hops=dict(type='str'), - connect_mode=dict(choices=['listenOnly', 'connectOnly', 'null']), + connect_mode=dict(choices=['listenOnly', 'connectOnly', 'both']), is_log_change=dict(type='str', default='no_use', choices=['no_use', 'true', 'false']), pswd_type=dict(choices=['null', 'cipher', 'simple']), pswd_cipher_text=dict(type='str', no_log=True), @@ -1913,7 +1918,6 @@ def main(): existing["bgp peer"] = bgp_peer_exist bgp_peer_new = (peer_addr, remote_as) - if len(bgp_peer_exist) == 0: cmd = ce_bgp_peer_obj.create_bgp_peer(module=module) changed = True diff --git a/lib/ansible/modules/network/cloudengine/ce_bgp_neighbor_af.py b/lib/ansible/modules/network/cloudengine/ce_bgp_neighbor_af.py index e828a2c8be0..33f8b1b233a 100644 --- a/lib/ansible/modules/network/cloudengine/ce_bgp_neighbor_af.py +++ b/lib/ansible/modules/network/cloudengine/ce_bgp_neighbor_af.py @@ -402,7 +402,7 @@ CE_GET_BGP_PEER_AF_HEADER = """ %s - + %s """ CE_GET_BGP_PEER_AF_TAIL = """ @@ -539,7 +539,7 @@ class BgpNeighborAf(object): msg='Error: The remote_address %s is invalid.' % remote_address) conf_str = CE_GET_BGP_PEER_AF_HEADER % ( - vrf_name, af_type) + CE_GET_BGP_PEER_AF_TAIL + vrf_name, af_type, remote_address) + CE_GET_BGP_PEER_AF_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) if state == "present": @@ -548,12 +548,11 @@ class BgpNeighborAf(object): else: re_find = re.findall( r'.*(.*).*', recv_xml) - if re_find: result["remote_address"] = re_find result["vrf_name"] = vrf_name result["af_type"] = af_type - if re_find[0] != remote_address: + if remote_address not in re_find: need_cfg = True else: need_cfg = True @@ -584,6 +583,7 @@ class BgpNeighborAf(object): state = module.params['state'] vrf_name = module.params['vrf_name'] af_type = module.params['af_type'] + remote_address = module.params['remote_address'] if state == "absent": result["need_cfg"] = need_cfg @@ -593,15 +593,14 @@ class BgpNeighborAf(object): if advertise_irb != 'no_use': conf_str = CE_GET_BGP_PEER_AF_HEADER % ( - vrf_name, af_type) + "" + CE_GET_BGP_PEER_AF_TAIL + vrf_name, af_type, remote_address) + "" + CE_GET_BGP_PEER_AF_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) if "" in recv_xml: need_cfg = True else: - re_find = re.findall( - r'.*(.*).*', recv_xml) - + re_find = re.findall(r'.*%s\s*' + r'(.*).*' % remote_address, recv_xml) if re_find: result["advertise_irb"] = re_find result["vrf_name"] = vrf_name @@ -615,14 +614,14 @@ class BgpNeighborAf(object): if advertise_arp != 'no_use': conf_str = CE_GET_BGP_PEER_AF_HEADER % ( - vrf_name, af_type) + "" + CE_GET_BGP_PEER_AF_TAIL + vrf_name, af_type, remote_address) + "" + CE_GET_BGP_PEER_AF_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) if "" in recv_xml: need_cfg = True else: - re_find = re.findall( - r'.*(.*).*', recv_xml) + re_find = re.findall(r'.*%s\s*' + r'.*(.*).*' % remote_address, recv_xml) if re_find: result["advertise_arp"] = re_find @@ -637,7 +636,7 @@ class BgpNeighborAf(object): if advertise_remote_nexthop != 'no_use': conf_str = CE_GET_BGP_PEER_AF_HEADER % ( - vrf_name, af_type) + "" + CE_GET_BGP_PEER_AF_TAIL + vrf_name, af_type, remote_address) + "" + CE_GET_BGP_PEER_AF_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) if "" in recv_xml: @@ -659,7 +658,7 @@ class BgpNeighborAf(object): if advertise_community != 'no_use': conf_str = CE_GET_BGP_PEER_AF_HEADER % ( - vrf_name, af_type) + "" + CE_GET_BGP_PEER_AF_TAIL + vrf_name, af_type, remote_address) + "" + CE_GET_BGP_PEER_AF_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) if "" in recv_xml: @@ -681,9 +680,8 @@ class BgpNeighborAf(object): if advertise_ext_community != 'no_use': conf_str = CE_GET_BGP_PEER_AF_HEADER % ( - vrf_name, af_type) + "" + CE_GET_BGP_PEER_AF_TAIL + vrf_name, af_type, remote_address) + "" + CE_GET_BGP_PEER_AF_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) - if "" in recv_xml: need_cfg = True else: @@ -703,7 +701,7 @@ class BgpNeighborAf(object): if discard_ext_community != 'no_use': conf_str = CE_GET_BGP_PEER_AF_HEADER % ( - vrf_name, af_type) + "" + CE_GET_BGP_PEER_AF_TAIL + vrf_name, af_type, remote_address) + "" + CE_GET_BGP_PEER_AF_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) if "" in recv_xml: @@ -725,7 +723,7 @@ class BgpNeighborAf(object): if allow_as_loop_enable != 'no_use': conf_str = CE_GET_BGP_PEER_AF_HEADER % ( - vrf_name, af_type) + "" + CE_GET_BGP_PEER_AF_TAIL + vrf_name, af_type, remote_address) + "" + CE_GET_BGP_PEER_AF_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) if "" in recv_xml: @@ -750,7 +748,7 @@ class BgpNeighborAf(object): msg='the value of allow_as_loop_limit %s is out of [1 - 10].' % allow_as_loop_limit) conf_str = CE_GET_BGP_PEER_AF_HEADER % ( - vrf_name, af_type) + "" + CE_GET_BGP_PEER_AF_TAIL + vrf_name, af_type, remote_address) + "" + CE_GET_BGP_PEER_AF_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) if "" in recv_xml: @@ -772,7 +770,7 @@ class BgpNeighborAf(object): if keep_all_routes != 'no_use': conf_str = CE_GET_BGP_PEER_AF_HEADER % ( - vrf_name, af_type) + "" + CE_GET_BGP_PEER_AF_TAIL + vrf_name, af_type, remote_address) + "" + CE_GET_BGP_PEER_AF_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) if "" in recv_xml: @@ -794,7 +792,7 @@ class BgpNeighborAf(object): if nexthop_configure: conf_str = CE_GET_BGP_PEER_AF_HEADER % ( - vrf_name, af_type) + "" + CE_GET_BGP_PEER_AF_TAIL + vrf_name, af_type, remote_address) + "" + CE_GET_BGP_PEER_AF_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) if "" in recv_xml: @@ -819,7 +817,7 @@ class BgpNeighborAf(object): msg='the value of preferred_value %s is out of [0 - 65535].' % preferred_value) conf_str = CE_GET_BGP_PEER_AF_HEADER % ( - vrf_name, af_type) + "" + CE_GET_BGP_PEER_AF_TAIL + vrf_name, af_type, remote_address) + "" + CE_GET_BGP_PEER_AF_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) if "" in recv_xml: @@ -841,7 +839,7 @@ class BgpNeighborAf(object): if public_as_only != 'no_use': conf_str = CE_GET_BGP_PEER_AF_HEADER % ( - vrf_name, af_type) + "" + CE_GET_BGP_PEER_AF_TAIL + vrf_name, af_type, remote_address) + "" + CE_GET_BGP_PEER_AF_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) if "" in recv_xml: @@ -863,7 +861,7 @@ class BgpNeighborAf(object): if public_as_only_force != 'no_use': conf_str = CE_GET_BGP_PEER_AF_HEADER % ( - vrf_name, af_type) + "" + CE_GET_BGP_PEER_AF_TAIL + vrf_name, af_type, remote_address) + "" + CE_GET_BGP_PEER_AF_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) if "" in recv_xml: @@ -885,7 +883,7 @@ class BgpNeighborAf(object): if public_as_only_limited != 'no_use': conf_str = CE_GET_BGP_PEER_AF_HEADER % ( - vrf_name, af_type) + "" + CE_GET_BGP_PEER_AF_TAIL + vrf_name, af_type, remote_address) + "" + CE_GET_BGP_PEER_AF_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) if "" in recv_xml: @@ -907,7 +905,7 @@ class BgpNeighborAf(object): if public_as_only_replace != 'no_use': conf_str = CE_GET_BGP_PEER_AF_HEADER % ( - vrf_name, af_type) + "" + CE_GET_BGP_PEER_AF_TAIL + vrf_name, af_type, remote_address) + "" + CE_GET_BGP_PEER_AF_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) if "" in recv_xml: @@ -930,7 +928,7 @@ class BgpNeighborAf(object): if public_as_only_skip_peer_as != 'no_use': conf_str = CE_GET_BGP_PEER_AF_HEADER % ( - vrf_name, af_type) + "" + CE_GET_BGP_PEER_AF_TAIL + vrf_name, af_type, remote_address) + "" + CE_GET_BGP_PEER_AF_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) if "" in recv_xml: @@ -956,7 +954,7 @@ class BgpNeighborAf(object): msg='the value of route_limit %s is out of [1 - 4294967295].' % route_limit) conf_str = CE_GET_BGP_PEER_AF_HEADER % ( - vrf_name, af_type) + "" + CE_GET_BGP_PEER_AF_TAIL + vrf_name, af_type, remote_address) + "" + CE_GET_BGP_PEER_AF_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) if "" in recv_xml: @@ -982,7 +980,7 @@ class BgpNeighborAf(object): msg='Error: The value of route_limit_percent %s is out of [1 - 100].' % route_limit_percent) conf_str = CE_GET_BGP_PEER_AF_HEADER % ( - vrf_name, af_type) + "" + CE_GET_BGP_PEER_AF_TAIL + vrf_name, af_type, remote_address) + "" + CE_GET_BGP_PEER_AF_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) if "" in recv_xml: @@ -1004,7 +1002,7 @@ class BgpNeighborAf(object): if route_limit_type: conf_str = CE_GET_BGP_PEER_AF_HEADER % ( - vrf_name, af_type) + "" + CE_GET_BGP_PEER_AF_TAIL + vrf_name, af_type, remote_address) + "" + CE_GET_BGP_PEER_AF_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) if "" in recv_xml: @@ -1031,7 +1029,7 @@ class BgpNeighborAf(object): '[1 - 1200].' % route_limit_idle_timeout) conf_str = CE_GET_BGP_PEER_AF_HEADER % ( - vrf_name, af_type) + "" + CE_GET_BGP_PEER_AF_TAIL + vrf_name, af_type, remote_address) + "" + CE_GET_BGP_PEER_AF_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) if "" in recv_xml: @@ -1057,7 +1055,7 @@ class BgpNeighborAf(object): msg='Error: The value of rt_updt_interval %s is out of [0 - 600].' % rt_updt_interval) conf_str = CE_GET_BGP_PEER_AF_HEADER % ( - vrf_name, af_type) + "" + CE_GET_BGP_PEER_AF_TAIL + vrf_name, af_type, remote_address) + "" + CE_GET_BGP_PEER_AF_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) if "" in recv_xml: @@ -1079,7 +1077,7 @@ class BgpNeighborAf(object): if redirect_ip != 'no_use': conf_str = CE_GET_BGP_PEER_AF_HEADER % ( - vrf_name, af_type) + "" + CE_GET_BGP_PEER_AF_TAIL + vrf_name, af_type, remote_address) + "" + CE_GET_BGP_PEER_AF_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) if "" in recv_xml: @@ -1101,7 +1099,7 @@ class BgpNeighborAf(object): if redirect_ip_vaildation != 'no_use': conf_str = CE_GET_BGP_PEER_AF_HEADER % ( - vrf_name, af_type) + "" + CE_GET_BGP_PEER_AF_TAIL + vrf_name, af_type, remote_address) + "" + CE_GET_BGP_PEER_AF_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) if "" in recv_xml: @@ -1123,7 +1121,7 @@ class BgpNeighborAf(object): if reflect_client != 'no_use': conf_str = CE_GET_BGP_PEER_AF_HEADER % ( - vrf_name, af_type) + "" + CE_GET_BGP_PEER_AF_TAIL + vrf_name, af_type, remote_address) + "" + CE_GET_BGP_PEER_AF_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) if "" in recv_xml: @@ -1145,7 +1143,7 @@ class BgpNeighborAf(object): if substitute_as_enable != 'no_use': conf_str = CE_GET_BGP_PEER_AF_HEADER % ( - vrf_name, af_type) + "" + CE_GET_BGP_PEER_AF_TAIL + vrf_name, af_type, remote_address) + "" + CE_GET_BGP_PEER_AF_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) if "" in recv_xml: @@ -1171,7 +1169,7 @@ class BgpNeighborAf(object): msg='Error: The len of import_rt_policy_name %s is out of [1 - 40].' % import_rt_policy_name) conf_str = CE_GET_BGP_PEER_AF_HEADER % ( - vrf_name, af_type) + "" + CE_GET_BGP_PEER_AF_TAIL + vrf_name, af_type, remote_address) + "" + CE_GET_BGP_PEER_AF_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) if "" in recv_xml: @@ -1197,7 +1195,7 @@ class BgpNeighborAf(object): msg='Error: The len of export_rt_policy_name %s is out of [1 - 40].' % export_rt_policy_name) conf_str = CE_GET_BGP_PEER_AF_HEADER % ( - vrf_name, af_type) + "" + CE_GET_BGP_PEER_AF_TAIL + vrf_name, af_type, remote_address) + "" + CE_GET_BGP_PEER_AF_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) if "" in recv_xml: @@ -1223,7 +1221,7 @@ class BgpNeighborAf(object): msg='Error: The len of import_pref_filt_name %s is out of [1 - 169].' % import_pref_filt_name) conf_str = CE_GET_BGP_PEER_AF_HEADER % ( - vrf_name, af_type) + "" + CE_GET_BGP_PEER_AF_TAIL + vrf_name, af_type, remote_address) + "" + CE_GET_BGP_PEER_AF_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) if "" in recv_xml: @@ -1249,7 +1247,7 @@ class BgpNeighborAf(object): msg='Error: The len of export_pref_filt_name %s is out of [1 - 169].' % export_pref_filt_name) conf_str = CE_GET_BGP_PEER_AF_HEADER % ( - vrf_name, af_type) + "" + CE_GET_BGP_PEER_AF_TAIL + vrf_name, af_type, remote_address) + "" + CE_GET_BGP_PEER_AF_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) if "" in recv_xml: @@ -1275,7 +1273,7 @@ class BgpNeighborAf(object): msg='Error: The value of import_as_path_filter %s is out of [1 - 256].' % import_as_path_filter) conf_str = CE_GET_BGP_PEER_AF_HEADER % ( - vrf_name, af_type) + "" + CE_GET_BGP_PEER_AF_TAIL + vrf_name, af_type, remote_address) + "" + CE_GET_BGP_PEER_AF_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) if "" in recv_xml: @@ -1301,7 +1299,7 @@ class BgpNeighborAf(object): msg='Error: The value of export_as_path_filter %s is out of [1 - 256].' % export_as_path_filter) conf_str = CE_GET_BGP_PEER_AF_HEADER % ( - vrf_name, af_type) + "" + CE_GET_BGP_PEER_AF_TAIL + vrf_name, af_type, remote_address) + "" + CE_GET_BGP_PEER_AF_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) if "" in recv_xml: @@ -1329,7 +1327,7 @@ class BgpNeighborAf(object): 'of [1 - 51].' % import_as_path_name_or_num) conf_str = CE_GET_BGP_PEER_AF_HEADER % ( - vrf_name, af_type) + "" + CE_GET_BGP_PEER_AF_TAIL + vrf_name, af_type, remote_address) + "" + CE_GET_BGP_PEER_AF_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) if "" in recv_xml: @@ -1357,7 +1355,7 @@ class BgpNeighborAf(object): 'of [1 - 51].' % export_as_path_name_or_num) conf_str = CE_GET_BGP_PEER_AF_HEADER % ( - vrf_name, af_type) + "" + CE_GET_BGP_PEER_AF_TAIL + vrf_name, af_type, remote_address) + "" + CE_GET_BGP_PEER_AF_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) if "" in recv_xml: @@ -1383,7 +1381,7 @@ class BgpNeighborAf(object): msg='Error: The len of import_acl_name_or_num %s is out of [1 - 32].' % import_acl_name_or_num) conf_str = CE_GET_BGP_PEER_AF_HEADER % ( - vrf_name, af_type) + "" + CE_GET_BGP_PEER_AF_TAIL + vrf_name, af_type, remote_address) + "" + CE_GET_BGP_PEER_AF_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) if "" in recv_xml: @@ -1409,7 +1407,7 @@ class BgpNeighborAf(object): msg='Error: The len of export_acl_name_or_num %s is out of [1 - 32].' % export_acl_name_or_num) conf_str = CE_GET_BGP_PEER_AF_HEADER % ( - vrf_name, af_type) + "" + CE_GET_BGP_PEER_AF_TAIL + vrf_name, af_type, remote_address) + "" + CE_GET_BGP_PEER_AF_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) if "" in recv_xml: @@ -1430,7 +1428,7 @@ class BgpNeighborAf(object): ipprefix_orf_enable = module.params['ipprefix_orf_enable'] if ipprefix_orf_enable != 'no_use': conf_str = CE_GET_BGP_PEER_AF_HEADER % ( - vrf_name, af_type) + "" + CE_GET_BGP_PEER_AF_TAIL + vrf_name, af_type, remote_address) + "" + CE_GET_BGP_PEER_AF_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) if "" in recv_xml: @@ -1452,7 +1450,7 @@ class BgpNeighborAf(object): if is_nonstd_ipprefix_mod != 'no_use': conf_str = CE_GET_BGP_PEER_AF_HEADER % ( - vrf_name, af_type) + "" + CE_GET_BGP_PEER_AF_TAIL + vrf_name, af_type, remote_address) + "" + CE_GET_BGP_PEER_AF_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) if "" in recv_xml: @@ -1478,7 +1476,7 @@ class BgpNeighborAf(object): msg='Error: The value of orftype %s is out of [0 - 65535].' % orftype) conf_str = CE_GET_BGP_PEER_AF_HEADER % ( - vrf_name, af_type) + "" + CE_GET_BGP_PEER_AF_TAIL + vrf_name, af_type, remote_address) + "" + CE_GET_BGP_PEER_AF_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) if "" in recv_xml: @@ -1500,7 +1498,7 @@ class BgpNeighborAf(object): if orf_mode: conf_str = CE_GET_BGP_PEER_AF_HEADER % ( - vrf_name, af_type) + "" + CE_GET_BGP_PEER_AF_TAIL + vrf_name, af_type, remote_address) + "" + CE_GET_BGP_PEER_AF_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) if "" in recv_xml: @@ -1526,7 +1524,7 @@ class BgpNeighborAf(object): msg='Error: The len of soostring %s is out of [3 - 21].' % soostring) conf_str = CE_GET_BGP_PEER_AF_HEADER % ( - vrf_name, af_type) + "" + CE_GET_BGP_PEER_AF_TAIL + vrf_name, af_type, remote_address) + "" + CE_GET_BGP_PEER_AF_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) if "" in recv_xml: @@ -1548,7 +1546,7 @@ class BgpNeighborAf(object): if default_rt_adv_enable != 'no_use': conf_str = CE_GET_BGP_PEER_AF_HEADER % ( - vrf_name, af_type) + "" + CE_GET_BGP_PEER_AF_TAIL + vrf_name, af_type, remote_address) + "" + CE_GET_BGP_PEER_AF_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) if "" in recv_xml: @@ -1574,7 +1572,7 @@ class BgpNeighborAf(object): msg='Error: The len of default_rt_adv_policy %s is out of [1 - 40].' % default_rt_adv_policy) conf_str = CE_GET_BGP_PEER_AF_HEADER % ( - vrf_name, af_type) + "" + CE_GET_BGP_PEER_AF_TAIL + vrf_name, af_type, remote_address) + "" + CE_GET_BGP_PEER_AF_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) if "" in recv_xml: @@ -1596,7 +1594,7 @@ class BgpNeighborAf(object): if default_rt_match_mode: conf_str = CE_GET_BGP_PEER_AF_HEADER % ( - vrf_name, af_type) + "" + CE_GET_BGP_PEER_AF_TAIL + vrf_name, af_type, remote_address) + "" + CE_GET_BGP_PEER_AF_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) if "" in recv_xml: @@ -1618,7 +1616,7 @@ class BgpNeighborAf(object): if add_path_mode: conf_str = CE_GET_BGP_PEER_AF_HEADER % ( - vrf_name, af_type) + "" + CE_GET_BGP_PEER_AF_TAIL + vrf_name, af_type, remote_address) + "" + CE_GET_BGP_PEER_AF_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) if "" in recv_xml: @@ -1644,7 +1642,7 @@ class BgpNeighborAf(object): msg='Error: The value of adv_add_path_num %s is out of [2 - 64].' % adv_add_path_num) conf_str = CE_GET_BGP_PEER_AF_HEADER % ( - vrf_name, af_type) + "" + CE_GET_BGP_PEER_AF_TAIL + vrf_name, af_type, remote_address) + "" + CE_GET_BGP_PEER_AF_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) if "" in recv_xml: @@ -1666,7 +1664,7 @@ class BgpNeighborAf(object): if origin_as_valid != 'no_use': conf_str = CE_GET_BGP_PEER_AF_HEADER % ( - vrf_name, af_type) + "" + CE_GET_BGP_PEER_AF_TAIL + vrf_name, af_type, remote_address) + "" + CE_GET_BGP_PEER_AF_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) if "" in recv_xml: @@ -1688,7 +1686,7 @@ class BgpNeighborAf(object): if vpls_enable != 'no_use': conf_str = CE_GET_BGP_PEER_AF_HEADER % ( - vrf_name, af_type) + "" + CE_GET_BGP_PEER_AF_TAIL + vrf_name, af_type, remote_address) + "" + CE_GET_BGP_PEER_AF_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) if "" in recv_xml: @@ -1710,7 +1708,7 @@ class BgpNeighborAf(object): if vpls_ad_disable != 'no_use': conf_str = CE_GET_BGP_PEER_AF_HEADER % ( - vrf_name, af_type) + "" + CE_GET_BGP_PEER_AF_TAIL + vrf_name, af_type, remote_address) + "" + CE_GET_BGP_PEER_AF_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) if "" in recv_xml: @@ -1733,7 +1731,7 @@ class BgpNeighborAf(object): if update_pkt_standard_compatible != 'no_use': conf_str = CE_GET_BGP_PEER_AF_HEADER % ( - vrf_name, af_type) + "" + \ + vrf_name, af_type, remote_address) + "" + \ CE_GET_BGP_PEER_AF_TAIL recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) @@ -1773,6 +1771,7 @@ class BgpNeighborAf(object): module.fail_json(msg='Error: Merge bgp peer address family failed.') cmds = [] + cmd = af_type if af_type == "ipv4uni": cmd = "ipv4-family unicast" elif af_type == "ipv4multi": @@ -1802,6 +1801,7 @@ class BgpNeighborAf(object): module.fail_json(msg='Error: Create bgp peer address family failed.') cmds = [] + cmd = af_type if af_type == "ipv4uni": cmd = "ipv4-family unicast" elif af_type == "ipv4multi": @@ -1831,6 +1831,7 @@ class BgpNeighborAf(object): module.fail_json(msg='Error: Delete bgp peer address family failed.') cmds = [] + cmd = af_type if af_type == "ipv4uni": cmd = "ipv4-family unicast" elif af_type == "ipv4multi": @@ -1861,7 +1862,7 @@ class BgpNeighborAf(object): if advertise_irb != 'no_use': conf_str += "%s" % advertise_irb - if advertise_irb == "ture": + if advertise_irb == "true": cmd = "peer %s advertise irb" % remote_address else: cmd = "undo peer %s advertise irb" % remote_address @@ -1871,7 +1872,7 @@ class BgpNeighborAf(object): if advertise_arp != 'no_use': conf_str += "%s" % advertise_arp - if advertise_arp == "ture": + if advertise_arp == "true": cmd = "peer %s advertise arp" % remote_address else: cmd = "undo peer %s advertise arp" % remote_address @@ -2081,6 +2082,12 @@ class BgpNeighborAf(object): if substitute_as_enable != 'no_use': conf_str += "%s" % substitute_as_enable + if substitute_as_enable == "true": + cmd = "peer %s substitute-as" % remote_address + else: + cmd = "undo peer %s substitute-as" % remote_address + cmds.append(cmd) + import_rt_policy_name = module.params['import_rt_policy_name'] if import_rt_policy_name: conf_str += "%s" % import_rt_policy_name @@ -2210,12 +2217,13 @@ class BgpNeighborAf(object): cmd += "peer %s default-route-advertise" % remote_address else: cmd += "undo peer %s default-route-advertise" % remote_address + cmds.append(cmd) default_rt_adv_policy = module.params['default_rt_adv_policy'] if default_rt_adv_policy: conf_str += "%s" % default_rt_adv_policy - - cmd += " route-policy %s" % default_rt_adv_policy + cmd = " route-policy %s" % default_rt_adv_policy + cmds.append(cmd) default_rt_match_mode = module.params['default_rt_match_mode'] if default_rt_match_mode: @@ -2226,17 +2234,27 @@ class BgpNeighborAf(object): elif default_rt_match_mode == "matchany": cmd += " conditional-route-match-any" - if cmd: - cmds.append(cmd) + if cmd: + cmds.append(cmd) add_path_mode = module.params['add_path_mode'] if add_path_mode: conf_str += "%s" % add_path_mode + if add_path_mode == "receive": + cmd += " add-path receive" + elif add_path_mode == "send": + cmd += " add-path send" + elif add_path_mode == "both": + cmd += " add-path both" + if cmd: + cmds.append(cmd) adv_add_path_num = module.params['adv_add_path_num'] if adv_add_path_num: conf_str += "%s" % adv_add_path_num - + cmd += " advertise add-path path-number %s" % adv_add_path_num + if cmd: + cmds.append(cmd) origin_as_valid = module.params['origin_as_valid'] if origin_as_valid != 'no_use': conf_str += "%s" % origin_as_valid