summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryanzhangi <51999930+yanzhangi@users.noreply.github.com>2019-09-18 09:46:34 +0800
committerToshio Kuratomi <a.badger@gmail.com>2019-10-12 09:17:09 -0700
commit0e160ade912501e1739534621416dcb8c89207f3 (patch)
treefd162a65dd44100ed911496355381080410e0298
parent6c757c0989e8b05a710ae59bf8285b9a35e8b801 (diff)
downloadansible-0e160ade912501e1739534621416dcb8c89207f3.tar.gz
update ce_bgp to fix bugs (#60573)
* update ce_bgp to fix bugs * update ce_bgp to fix bugs * update ce_bgp to fix bugs * update ce_bgp to fix bugs * Update ce_bgp to fix bugs (cherry picked from commit 5f35916b2262f4345dcf9019eefb5f62d3b866b8)
-rw-r--r--lib/ansible/modules/network/cloudengine/ce_bgp.py101
1 files changed, 53 insertions, 48 deletions
diff --git a/lib/ansible/modules/network/cloudengine/ce_bgp.py b/lib/ansible/modules/network/cloudengine/ce_bgp.py
index cdd711de5b..a3a6029881 100644
--- a/lib/ansible/modules/network/cloudengine/ce_bgp.py
+++ b/lib/ansible/modules/network/cloudengine/ce_bgp.py
@@ -892,7 +892,7 @@ class Bgp(object):
"<vrfName></vrfName>" + CE_GET_BGP_INSTANCE_TAIL
recv_xml = self.netconf_get_config(module=module, conf_str=conf_str)
- check_vrf_name = (vrf_name)
+ check_vrf_name = vrf_name
if state == "present":
if "<data/>" in recv_xml:
@@ -940,7 +940,7 @@ class Bgp(object):
module.fail_json(
msg='Error: The router_id %s is invalid.' % router_id)
- conf_str = CE_GET_BGP_INSTANCE_HEADER + \
+ conf_str = CE_GET_BGP_INSTANCE_HEADER + "<vrfName>%s</vrfName>" % vrf_name + \
"<routerId></routerId>" + CE_GET_BGP_INSTANCE_TAIL
recv_xml = self.netconf_get_config(module=module, conf_str=conf_str)
@@ -976,7 +976,7 @@ class Bgp(object):
module.fail_json(
msg='Error: Please input vrf_name.')
- conf_str = CE_GET_BGP_INSTANCE_HEADER + \
+ conf_str = CE_GET_BGP_INSTANCE_HEADER + "<vrfName>%s</vrfName>" % vrf_name + \
"<vrfRidAutoSel></vrfRidAutoSel>" + CE_GET_BGP_INSTANCE_TAIL
recv_xml = self.netconf_get_config(module=module, conf_str=conf_str)
@@ -1006,7 +1006,7 @@ class Bgp(object):
module.fail_json(
msg='keepalive_time %s is out of [0 - 21845].' % keepalive_time)
else:
- conf_str = CE_GET_BGP_INSTANCE_HEADER + \
+ conf_str = CE_GET_BGP_INSTANCE_HEADER + "<vrfName>%s</vrfName>" % vrf_name + \
"<keepaliveTime></keepaliveTime>" + CE_GET_BGP_INSTANCE_TAIL
recv_xml = self.netconf_get_config(
module=module, conf_str=conf_str)
@@ -1047,7 +1047,7 @@ class Bgp(object):
module.fail_json(
msg='hold_time %s is out of [3 - 65535].' % hold_time)
else:
- conf_str = CE_GET_BGP_INSTANCE_HEADER + \
+ conf_str = CE_GET_BGP_INSTANCE_HEADER + "<vrfName>%s</vrfName>" % vrf_name + \
"<holdTime></holdTime>" + CE_GET_BGP_INSTANCE_TAIL
recv_xml = self.netconf_get_config(
module=module, conf_str=conf_str)
@@ -1088,7 +1088,7 @@ class Bgp(object):
module.fail_json(
msg='min_hold_time %s is out of [0, or 20 - 65535].' % min_hold_time)
else:
- conf_str = CE_GET_BGP_INSTANCE_HEADER + \
+ conf_str = CE_GET_BGP_INSTANCE_HEADER + "<vrfName>%s</vrfName>" % vrf_name + \
"<minHoldTime></minHoldTime>" + CE_GET_BGP_INSTANCE_TAIL
recv_xml = self.netconf_get_config(
module=module, conf_str=conf_str)
@@ -1129,7 +1129,7 @@ class Bgp(object):
module.fail_json(
msg='conn_retry_time %s is out of [1 - 65535].' % conn_retry_time)
else:
- conf_str = CE_GET_BGP_INSTANCE_HEADER + \
+ conf_str = CE_GET_BGP_INSTANCE_HEADER + "<vrfName>%s</vrfName>" % vrf_name + \
"<connRetryTime></connRetryTime>" + CE_GET_BGP_INSTANCE_TAIL
recv_xml = self.netconf_get_config(
module=module, conf_str=conf_str)
@@ -1168,7 +1168,7 @@ class Bgp(object):
module.fail_json(
msg='Error: Please input vrf_name.')
- conf_str = CE_GET_BGP_INSTANCE_HEADER + \
+ conf_str = CE_GET_BGP_INSTANCE_HEADER + "<vrfName>%s</vrfName>" % vrf_name + \
"<ebgpIfSensitive></ebgpIfSensitive>" + CE_GET_BGP_INSTANCE_TAIL
recv_xml = self.netconf_get_config(module=module, conf_str=conf_str)
@@ -1206,7 +1206,7 @@ class Bgp(object):
module.fail_json(
msg='Error: Please input vrf_name.')
- conf_str = CE_GET_BGP_INSTANCE_HEADER + \
+ conf_str = CE_GET_BGP_INSTANCE_HEADER + "<vrfName>%s</vrfName>" % vrf_name + \
"<defaultAfType></defaultAfType>" + CE_GET_BGP_INSTANCE_TAIL
recv_xml = self.netconf_get_config(module=module, conf_str=conf_str)
@@ -1471,7 +1471,8 @@ class Bgp(object):
cmds.append(cmd)
confed_id_number = module.params['confed_id_number']
- if confed_id_number:
+ confed_peer_as_num = module.params['confed_peer_as_num']
+ if confed_id_number and not confed_peer_as_num:
conf_str += "<confedIdNumber></confedIdNumber>"
cmd = "undo confederation id"
@@ -1543,8 +1544,7 @@ class Bgp(object):
if suppress_interval:
conf_str += "<suppressInterval>60</suppressInterval>"
- cmd = "nexthop recursive-lookup restrain suppress-interval %s hold-interval %s " \
- "clear-interval %s" % (suppress_interval, hold_interval, clear_interval)
+ cmd = "undo nexthop recursive-lookup restrain suppress-interval hold-interval clear-interval"
cmds.append(cmd)
if hold_interval:
@@ -1675,14 +1675,26 @@ class Bgp(object):
if "<ok/>" not in recv_xml:
module.fail_json(msg='Error: Merge bgp instance failed.')
+ cmds = []
+
+ if vrf_name != "_public_":
+ cmd = "ipv4-family vpn-instance %s" % vrf_name
+ cmds.append(cmd)
+
+ return cmds
+
def create_bgp_instance(self, **kwargs):
""" create_bgp_instance """
module = kwargs["module"]
conf_str = CE_CREATE_BGP_INSTANCE_HEADER
+ cmds = []
+
vrf_name = module.params['vrf_name']
if vrf_name:
+ if vrf_name == "_public_":
+ return cmds
conf_str += "<vrfName>%s</vrfName>" % vrf_name
conf_str += CE_CREATE_BGP_INSTANCE_TAIL
@@ -1692,8 +1704,6 @@ class Bgp(object):
if "<ok/>" not in recv_xml:
module.fail_json(msg='Error: Create bgp instance failed.')
- cmds = []
-
if vrf_name != "_public_":
cmd = "ipv4-family vpn-instance %s" % vrf_name
cmds.append(cmd)
@@ -1735,14 +1745,23 @@ class Bgp(object):
cmds = []
+ default_af_type = module.params['default_af_type']
+ if default_af_type:
+ conf_str += "<defaultAfType>%s</defaultAfType>" % default_af_type
+
+ if vrf_name != "_public_":
+ if default_af_type == "ipv6uni":
+ cmd = "ipv6-family vpn-instance %s" % vrf_name
+ cmds.append(cmd)
+
vrf_rid_auto_sel = module.params['vrf_rid_auto_sel']
if vrf_rid_auto_sel != 'no_use':
conf_str += "<vrfRidAutoSel>%s</vrfRidAutoSel>" % vrf_rid_auto_sel
if vrf_rid_auto_sel == "true":
- cmd = "router-id vpn-instance auto-select"
+ cmd = "router-id auto-select"
else:
- cmd = "undo router-id vpn-instance auto-select"
+ cmd = "undo router-id auto-select"
cmds.append(cmd)
router_id = module.params['router_id']
@@ -1790,22 +1809,6 @@ class Bgp(object):
cmd = "undo ebgp-interface-sensitive"
cmds.append(cmd)
- default_af_type = module.params['default_af_type']
- if default_af_type:
- conf_str += "<defaultAfType>%s</defaultAfType>" % default_af_type
-
- if vrf_name != "_public_":
- if default_af_type == "ipv6uni":
- cmd = "ipv6-family vpn-instance %s" % vrf_name
- cmds.append(cmd)
- else:
- cmd = "ipv4-family vpn-instance %s" % vrf_name
- cmds.append(cmd)
- else:
- if vrf_name != "_public_":
- cmd = "ipv4-family vpn-instance %s" % vrf_name
- cmds.append(cmd)
-
conf_str += CE_MERGE_BGP_INSTANCE_TAIL
recv_xml = self.netconf_set_config(module=module, conf_str=conf_str)
@@ -1921,7 +1924,7 @@ class Bgp(object):
vrf_rid_auto_sel = module.params['vrf_rid_auto_sel']
if vrf_rid_auto_sel != 'no_use':
- conf_str += "<vrfRidAutoSel>%s</vrfRidAutoSel>" % vrf_rid_auto_sel
+ conf_str += "<vrfRidAutoSel>%s</vrfRidAutoSel>" % "false"
cmd = "undo router-id vpn-instance auto-select"
cmds.append(cmd)
@@ -1958,7 +1961,7 @@ class Bgp(object):
if ebgp_if_sensitive != 'no_use':
conf_str += "<ebgpIfSensitive>%s</ebgpIfSensitive>" % "true"
- cmd = "undo ebgp-interface-sensitive"
+ cmd = "ebgp-interface-sensitive"
cmds.append(cmd)
default_af_type = module.params['default_af_type']
@@ -2122,20 +2125,23 @@ def main():
need_bgp_instance_other_rst = ce_bgp_obj.check_bgp_instance_other_args(
module=module)
+ router_id_exist = ce_bgp_obj.get_bgp_instance(module=module)
+ existing["bgp instance"] = router_id_exist
+
# bgp enable/disable
if need_bgp_enable:
bgp_enable_exist = ce_bgp_obj.get_bgp_enable(module=module)
existing["bgp enable"] = bgp_enable_exist
if bgp_enable_exist:
- asnumber_exist = bgp_enable_exist[0][0]
- bgpenable_exist = bgp_enable_exist[0][1]
+ asnumber_exist = bgp_enable_exist[0][1]
+ bgpenable_exist = bgp_enable_exist[0][0]
else:
asnumber_exist = None
bgpenable_exist = None
if state == "present":
- bgp_enable_new = (as_number, "true")
+ bgp_enable_new = ("true", as_number)
if bgp_enable_new in bgp_enable_exist:
pass
@@ -2149,7 +2155,8 @@ def main():
updates.append(item)
else:
- if need_bgp_enable_other_rst["need_cfg"] or need_bgp_confed or need_bgp_instance_other_rst["need_cfg"]:
+ if need_bgp_enable_other_rst["need_cfg"] or need_bgp_confed or \
+ need_bgp_instance_other_rst["need_cfg"] or need_bgp_instance:
pass
elif bgpenable_exist == "false":
pass
@@ -2234,20 +2241,18 @@ def main():
end_state["confederation peer as"] = confed_end
# bgp instance
- router_id_exist = ce_bgp_obj.get_bgp_instance(module=module)
- existing["bgp instance"] = router_id_exist
- if need_bgp_instance:
- router_id_new = (vrf_name)
+ if need_bgp_instance and default_af_type != "ipv6uni":
+ router_id_new = vrf_name
if state == "present":
if len(router_id_exist) == 0:
cmd = ce_bgp_obj.create_bgp_instance(module=module)
changed = True
- updates.append(cmd)
+ updates.extend(cmd)
elif router_id_new not in router_id_exist:
- ce_bgp_obj.merge_bgp_instance(module=module)
+ cmd = ce_bgp_obj.merge_bgp_instance(module=module)
changed = True
-
+ updates.extend(cmd)
else:
if not need_bgp_instance_other_rst["need_cfg"]:
if vrf_name != "_public_":
@@ -2261,9 +2266,6 @@ def main():
for item in cmd:
updates.append(item)
- router_id_end = ce_bgp_obj.get_bgp_instance(module=module)
- end_state["bgp instance"] = router_id_end
-
# bgp instance other
exist_tmp = dict()
for item in need_bgp_instance_other_rst:
@@ -2296,6 +2298,9 @@ def main():
need_bgp_instance_other_rst = ce_bgp_obj.check_bgp_instance_other_args(
module=module)
+ router_id_end = ce_bgp_obj.get_bgp_instance(module=module)
+ end_state["bgp instance"] = router_id_end
+
end_tmp = dict()
for item in need_bgp_instance_other_rst:
if item != "need_cfg":