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
pull/60573/merge
yanzhangi 5 years ago committed by ansibot
parent db0f290ca3
commit 5f35916b22

@ -892,7 +892,7 @@ class Bgp(object):
"<vrfName></vrfName>" + CE_GET_BGP_INSTANCE_TAIL "<vrfName></vrfName>" + CE_GET_BGP_INSTANCE_TAIL
recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) 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 state == "present":
if "<data/>" in recv_xml: if "<data/>" in recv_xml:
@ -940,7 +940,7 @@ class Bgp(object):
module.fail_json( module.fail_json(
msg='Error: The router_id %s is invalid.' % router_id) 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 "<routerId></routerId>" + CE_GET_BGP_INSTANCE_TAIL
recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) recv_xml = self.netconf_get_config(module=module, conf_str=conf_str)
@ -976,7 +976,7 @@ class Bgp(object):
module.fail_json( module.fail_json(
msg='Error: Please input vrf_name.') 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 "<vrfRidAutoSel></vrfRidAutoSel>" + CE_GET_BGP_INSTANCE_TAIL
recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) recv_xml = self.netconf_get_config(module=module, conf_str=conf_str)
@ -1006,7 +1006,7 @@ class Bgp(object):
module.fail_json( module.fail_json(
msg='keepalive_time %s is out of [0 - 21845].' % keepalive_time) msg='keepalive_time %s is out of [0 - 21845].' % keepalive_time)
else: 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 "<keepaliveTime></keepaliveTime>" + CE_GET_BGP_INSTANCE_TAIL
recv_xml = self.netconf_get_config( recv_xml = self.netconf_get_config(
module=module, conf_str=conf_str) module=module, conf_str=conf_str)
@ -1047,7 +1047,7 @@ class Bgp(object):
module.fail_json( module.fail_json(
msg='hold_time %s is out of [3 - 65535].' % hold_time) msg='hold_time %s is out of [3 - 65535].' % hold_time)
else: 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 "<holdTime></holdTime>" + CE_GET_BGP_INSTANCE_TAIL
recv_xml = self.netconf_get_config( recv_xml = self.netconf_get_config(
module=module, conf_str=conf_str) module=module, conf_str=conf_str)
@ -1088,7 +1088,7 @@ class Bgp(object):
module.fail_json( module.fail_json(
msg='min_hold_time %s is out of [0, or 20 - 65535].' % min_hold_time) msg='min_hold_time %s is out of [0, or 20 - 65535].' % min_hold_time)
else: 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 "<minHoldTime></minHoldTime>" + CE_GET_BGP_INSTANCE_TAIL
recv_xml = self.netconf_get_config( recv_xml = self.netconf_get_config(
module=module, conf_str=conf_str) module=module, conf_str=conf_str)
@ -1129,7 +1129,7 @@ class Bgp(object):
module.fail_json( module.fail_json(
msg='conn_retry_time %s is out of [1 - 65535].' % conn_retry_time) msg='conn_retry_time %s is out of [1 - 65535].' % conn_retry_time)
else: 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 "<connRetryTime></connRetryTime>" + CE_GET_BGP_INSTANCE_TAIL
recv_xml = self.netconf_get_config( recv_xml = self.netconf_get_config(
module=module, conf_str=conf_str) module=module, conf_str=conf_str)
@ -1168,7 +1168,7 @@ class Bgp(object):
module.fail_json( module.fail_json(
msg='Error: Please input vrf_name.') 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 "<ebgpIfSensitive></ebgpIfSensitive>" + CE_GET_BGP_INSTANCE_TAIL
recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) recv_xml = self.netconf_get_config(module=module, conf_str=conf_str)
@ -1206,7 +1206,7 @@ class Bgp(object):
module.fail_json( module.fail_json(
msg='Error: Please input vrf_name.') 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 "<defaultAfType></defaultAfType>" + CE_GET_BGP_INSTANCE_TAIL
recv_xml = self.netconf_get_config(module=module, conf_str=conf_str) recv_xml = self.netconf_get_config(module=module, conf_str=conf_str)
@ -1471,7 +1471,8 @@ class Bgp(object):
cmds.append(cmd) cmds.append(cmd)
confed_id_number = module.params['confed_id_number'] 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>" conf_str += "<confedIdNumber></confedIdNumber>"
cmd = "undo confederation id" cmd = "undo confederation id"
@ -1543,8 +1544,7 @@ class Bgp(object):
if suppress_interval: if suppress_interval:
conf_str += "<suppressInterval>60</suppressInterval>" conf_str += "<suppressInterval>60</suppressInterval>"
cmd = "nexthop recursive-lookup restrain suppress-interval %s hold-interval %s " \ cmd = "undo nexthop recursive-lookup restrain suppress-interval hold-interval clear-interval"
"clear-interval %s" % (suppress_interval, hold_interval, clear_interval)
cmds.append(cmd) cmds.append(cmd)
if hold_interval: if hold_interval:
@ -1675,14 +1675,26 @@ class Bgp(object):
if "<ok/>" not in recv_xml: if "<ok/>" not in recv_xml:
module.fail_json(msg='Error: Merge bgp instance failed.') 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): def create_bgp_instance(self, **kwargs):
""" create_bgp_instance """ """ create_bgp_instance """
module = kwargs["module"] module = kwargs["module"]
conf_str = CE_CREATE_BGP_INSTANCE_HEADER conf_str = CE_CREATE_BGP_INSTANCE_HEADER
cmds = []
vrf_name = module.params['vrf_name'] vrf_name = module.params['vrf_name']
if vrf_name: if vrf_name:
if vrf_name == "_public_":
return cmds
conf_str += "<vrfName>%s</vrfName>" % vrf_name conf_str += "<vrfName>%s</vrfName>" % vrf_name
conf_str += CE_CREATE_BGP_INSTANCE_TAIL conf_str += CE_CREATE_BGP_INSTANCE_TAIL
@ -1692,8 +1704,6 @@ class Bgp(object):
if "<ok/>" not in recv_xml: if "<ok/>" not in recv_xml:
module.fail_json(msg='Error: Create bgp instance failed.') module.fail_json(msg='Error: Create bgp instance failed.')
cmds = []
if vrf_name != "_public_": if vrf_name != "_public_":
cmd = "ipv4-family vpn-instance %s" % vrf_name cmd = "ipv4-family vpn-instance %s" % vrf_name
cmds.append(cmd) cmds.append(cmd)
@ -1735,14 +1745,23 @@ class Bgp(object):
cmds = [] 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'] vrf_rid_auto_sel = module.params['vrf_rid_auto_sel']
if vrf_rid_auto_sel != 'no_use': if vrf_rid_auto_sel != 'no_use':
conf_str += "<vrfRidAutoSel>%s</vrfRidAutoSel>" % vrf_rid_auto_sel conf_str += "<vrfRidAutoSel>%s</vrfRidAutoSel>" % vrf_rid_auto_sel
if vrf_rid_auto_sel == "true": if vrf_rid_auto_sel == "true":
cmd = "router-id vpn-instance auto-select" cmd = "router-id auto-select"
else: else:
cmd = "undo router-id vpn-instance auto-select" cmd = "undo router-id auto-select"
cmds.append(cmd) cmds.append(cmd)
router_id = module.params['router_id'] router_id = module.params['router_id']
@ -1790,22 +1809,6 @@ class Bgp(object):
cmd = "undo ebgp-interface-sensitive" cmd = "undo ebgp-interface-sensitive"
cmds.append(cmd) 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 conf_str += CE_MERGE_BGP_INSTANCE_TAIL
recv_xml = self.netconf_set_config(module=module, conf_str=conf_str) 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'] vrf_rid_auto_sel = module.params['vrf_rid_auto_sel']
if vrf_rid_auto_sel != 'no_use': 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" cmd = "undo router-id vpn-instance auto-select"
cmds.append(cmd) cmds.append(cmd)
@ -1958,7 +1961,7 @@ class Bgp(object):
if ebgp_if_sensitive != 'no_use': if ebgp_if_sensitive != 'no_use':
conf_str += "<ebgpIfSensitive>%s</ebgpIfSensitive>" % "true" conf_str += "<ebgpIfSensitive>%s</ebgpIfSensitive>" % "true"
cmd = "undo ebgp-interface-sensitive" cmd = "ebgp-interface-sensitive"
cmds.append(cmd) cmds.append(cmd)
default_af_type = module.params['default_af_type'] 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( need_bgp_instance_other_rst = ce_bgp_obj.check_bgp_instance_other_args(
module=module) module=module)
router_id_exist = ce_bgp_obj.get_bgp_instance(module=module)
existing["bgp instance"] = router_id_exist
# bgp enable/disable # bgp enable/disable
if need_bgp_enable: if need_bgp_enable:
bgp_enable_exist = ce_bgp_obj.get_bgp_enable(module=module) bgp_enable_exist = ce_bgp_obj.get_bgp_enable(module=module)
existing["bgp enable"] = bgp_enable_exist existing["bgp enable"] = bgp_enable_exist
if bgp_enable_exist: if bgp_enable_exist:
asnumber_exist = bgp_enable_exist[0][0] asnumber_exist = bgp_enable_exist[0][1]
bgpenable_exist = bgp_enable_exist[0][1] bgpenable_exist = bgp_enable_exist[0][0]
else: else:
asnumber_exist = None asnumber_exist = None
bgpenable_exist = None bgpenable_exist = None
if state == "present": if state == "present":
bgp_enable_new = (as_number, "true") bgp_enable_new = ("true", as_number)
if bgp_enable_new in bgp_enable_exist: if bgp_enable_new in bgp_enable_exist:
pass pass
@ -2149,7 +2155,8 @@ def main():
updates.append(item) updates.append(item)
else: 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 pass
elif bgpenable_exist == "false": elif bgpenable_exist == "false":
pass pass
@ -2234,20 +2241,18 @@ def main():
end_state["confederation peer as"] = confed_end end_state["confederation peer as"] = confed_end
# bgp instance # bgp instance
router_id_exist = ce_bgp_obj.get_bgp_instance(module=module) if need_bgp_instance and default_af_type != "ipv6uni":
existing["bgp instance"] = router_id_exist router_id_new = vrf_name
if need_bgp_instance:
router_id_new = (vrf_name)
if state == "present": if state == "present":
if len(router_id_exist) == 0: if len(router_id_exist) == 0:
cmd = ce_bgp_obj.create_bgp_instance(module=module) cmd = ce_bgp_obj.create_bgp_instance(module=module)
changed = True changed = True
updates.append(cmd) updates.extend(cmd)
elif router_id_new not in router_id_exist: 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 changed = True
updates.extend(cmd)
else: else:
if not need_bgp_instance_other_rst["need_cfg"]: if not need_bgp_instance_other_rst["need_cfg"]:
if vrf_name != "_public_": if vrf_name != "_public_":
@ -2261,9 +2266,6 @@ def main():
for item in cmd: for item in cmd:
updates.append(item) updates.append(item)
router_id_end = ce_bgp_obj.get_bgp_instance(module=module)
end_state["bgp instance"] = router_id_end
# bgp instance other # bgp instance other
exist_tmp = dict() exist_tmp = dict()
for item in need_bgp_instance_other_rst: 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( need_bgp_instance_other_rst = ce_bgp_obj.check_bgp_instance_other_args(
module=module) module=module)
router_id_end = ce_bgp_obj.get_bgp_instance(module=module)
end_state["bgp instance"] = router_id_end
end_tmp = dict() end_tmp = dict()
for item in need_bgp_instance_other_rst: for item in need_bgp_instance_other_rst:
if item != "need_cfg": if item != "need_cfg":

Loading…
Cancel
Save