diff --git a/lib/ansible/modules/network/cloudengine/ce_mlag_interface.py b/lib/ansible/modules/network/cloudengine/ce_mlag_interface.py index 5c791ab6693..d3813876f4a 100644 --- a/lib/ansible/modules/network/cloudengine/ce_mlag_interface.py +++ b/lib/ansible/modules/network/cloudengine/ce_mlag_interface.py @@ -152,6 +152,7 @@ CE_NC_GET_MLAG_INFO = """ + %s @@ -162,7 +163,7 @@ CE_NC_CREATE_MLAG_INFO = """ - + %s %s %s @@ -178,7 +179,6 @@ CE_NC_DELETE_MLAG_INFO = """ %s - %s %s @@ -265,7 +265,7 @@ CE_NC_CREATE_MLAG_ERROR_DOWN_INFO = """ - + 1 %s @@ -386,7 +386,7 @@ class MlagInterface(object): """ get mlag info.""" mlag_info = dict() - conf_str = CE_NC_GET_MLAG_INFO + conf_str = CE_NC_GET_MLAG_INFO % ("Eth-Trunk%s" % self.eth_trunk_id) xml_str = get_nc_config(self.module, conf_str) if "" in xml_str: return mlag_info @@ -398,7 +398,7 @@ class MlagInterface(object): mlag_info["mlagInfos"] = list() root = ElementTree.fromstring(xml_str) dfs_mlag_infos = root.findall( - "data/mlag/mlagInstances/mlagInstance") + "./mlag/mlagInstances/mlagInstance") if dfs_mlag_infos: for dfs_mlag_info in dfs_mlag_infos: @@ -424,7 +424,7 @@ class MlagInterface(object): root = ElementTree.fromstring(xml_str) global_info = root.findall( - "data/ifmtrunk/lacpSysInfo/lacpMlagGlobal") + "./ifmtrunk/lacpSysInfo/lacpMlagGlobal") if global_info: for tmp in global_info: @@ -450,7 +450,7 @@ class MlagInterface(object): root = ElementTree.fromstring(xml_str) global_info = root.findall( - "data/ifmtrunk/TrunkIfs/TrunkIf/lacpMlagIf") + "./ifmtrunk/TrunkIfs/TrunkIf/lacpMlagIf") if global_info: for tmp in global_info: @@ -475,7 +475,7 @@ class MlagInterface(object): mlag_error_down_info["mlagErrorDownInfos"] = list() root = ElementTree.fromstring(xml_str) mlag_error_infos = root.findall( - "data/mlag/errordowns/errordown") + "./mlag/errordowns/errordown") if mlag_error_infos: for mlag_error_info in mlag_error_infos: @@ -506,7 +506,12 @@ class MlagInterface(object): for _, value in enumerate(mac, start=0): if value.lower() not in valid_char: return False - + if all((int(mac_list[0], base=16) == 0, int(mac_list[1], base=16) == 0, int(mac_list[2], base=16) == 0)): + return False + a = "000" + mac_list[0] + b = "000" + mac_list[1] + c = "000" + mac_list[2] + self.mlag_system_id = "-".join([a[-4:], b[-4:], c[-4:]]) return True def check_params(self): @@ -582,7 +587,7 @@ class MlagInterface(object): eth_trunk += self.eth_trunk_id for info in self.mlag_info["mlagInfos"]: - if info["mlagId"] == self.mlag_id and info["localMlagPort"] == eth_trunk: + if info["localMlagPort"] == eth_trunk: return True return False @@ -713,7 +718,7 @@ class MlagInterface(object): mlag_port = "Eth-Trunk" mlag_port += self.eth_trunk_id conf_str = CE_NC_DELETE_MLAG_INFO % ( - self.dfs_group_id, self.mlag_id, mlag_port) + self.dfs_group_id, mlag_port) recv_xml = set_nc_config(self.module, conf_str) if "" not in recv_xml: self.module.fail_json( @@ -786,20 +791,27 @@ class MlagInterface(object): if self.is_mlag_interface_info_exist(): mlag_port = "Eth-Trunk" mlag_port += self.eth_trunk_id - + conf_str = CE_NC_SET_LACP_MLAG_INFO_HEAD % mlag_port cmd = "interface %s" % mlag_port self.cli_add_command(cmd) if self.mlag_priority_id: cmd = "lacp m-lag priority %s" % self.mlag_priority_id + conf_str += "" self.cli_add_command(cmd, True) if self.mlag_system_id: cmd = "lacp m-lag system-id %s" % self.mlag_system_id + conf_str += "" self.cli_add_command(cmd, True) if self.commands: - self.cli_load_config(self.commands) + conf_str += CE_NC_SET_LACP_MLAG_INFO_TAIL + recv_xml = set_nc_config(self.module, conf_str) + if "" not in recv_xml: + self.module.fail_json( + msg='Error: set mlag interface atrribute info failed.') + self.changed = True def set_mlag_global(self): @@ -829,17 +841,24 @@ class MlagInterface(object): def delete_mlag_global(self): """delete mlag global attribute info""" + xml_str = '' if self.is_mlag_global_info_exist(): if self.mlag_priority_id: cmd = "lacp m-lag priority %s" % self.mlag_priority_id + xml_str += '' self.cli_add_command(cmd, True) if self.mlag_system_id: cmd = "lacp m-lag system-id %s" % self.mlag_system_id + xml_str += '' self.cli_add_command(cmd, True) - if self.commands: - self.cli_load_config(self.commands) + if xml_str != '': + conf_str = CE_NC_SET_GLOBAL_LACP_MLAG_INFO_HEAD + xml_str + CE_NC_SET_GLOBAL_LACP_MLAG_INFO_TAIL + recv_xml = set_nc_config(self.module, conf_str) + if "" not in recv_xml: + self.module.fail_json( + msg='Error: set mlag interface atrribute info failed.') self.changed = True def get_proposed(self): @@ -878,18 +897,18 @@ class MlagInterface(object): if self.eth_trunk_id: if self.mlag_trunk_attribute_info: if self.mlag_system_id: - self.end_state["lacpMlagSysId"] = self.mlag_trunk_attribute_info[ + self.existing["lacpMlagSysId"] = self.mlag_trunk_attribute_info[ "lacpMlagSysId"] if self.mlag_priority_id: - self.end_state["lacpMlagPriority"] = self.mlag_trunk_attribute_info[ + self.existing["lacpMlagPriority"] = self.mlag_trunk_attribute_info[ "lacpMlagPriority"] else: if self.mlag_global_info: if self.mlag_system_id: - self.end_state["lacpMlagSysId"] = self.mlag_global_info[ + self.existing["lacpMlagSysId"] = self.mlag_global_info[ "lacpMlagSysId"] if self.mlag_priority_id: - self.end_state["lacpMlagPriority"] = self.mlag_global_info[ + self.existing["lacpMlagPriority"] = self.mlag_global_info[ "lacpMlagPriority"] if self.interface or self.mlag_error_down: @@ -980,6 +999,8 @@ class MlagInterface(object): msg='Error: interface, mlag_error_down must be config at the same time.') self.get_end_state() + if self.existing == self.end_state: + self.changed = False self.results['changed'] = self.changed self.results['proposed'] = self.proposed self.results['existing'] = self.existing