diff --git a/plugins/module_utils/mso.py b/plugins/module_utils/mso.py index f66d4cbb..79836197 100644 --- a/plugins/module_utils/mso.py +++ b/plugins/module_utils/mso.py @@ -318,6 +318,19 @@ def write_file(module, url, dest, content, resp, tmpsrc=None): os.remove(tmpsrc) +def format_interface_descriptions(interface_descriptions, node=None): + formated_interface_descriptions = [ + { + "nodeID": node if node is not None else interface_description.get("node"), + "interfaceID": interface_description.get("interface_id"), + "description": interface_description.get("description"), + } + for interface_description in interface_descriptions + ] + + return formated_interface_descriptions + + class MSOModule(object): def __init__(self, module): self.module = module diff --git a/plugins/modules/ndo_virtual_port_channel_interface.py b/plugins/modules/ndo_virtual_port_channel_interface.py index 3bf38836..1112ef80 100644 --- a/plugins/modules/ndo_virtual_port_channel_interface.py +++ b/plugins/modules/ndo_virtual_port_channel_interface.py @@ -167,7 +167,7 @@ virtual_port_channel_interface_uuid: 0134c73f-4427-4109-9eea-5110ecdf10ea state: present -- name: Query an Virtual Port Channel Interface using it's name in the template +- name: Query an Virtual Port Channel Interface using its name in the template cisco.mso.ndo_virtual_port_channel_interface: host: mso_host username: admin @@ -177,7 +177,7 @@ state: query register: query_one -- name: Query an Virtual Port Channel Interface using it's uuid in the template +- name: Query an Virtual Port Channel Interface using its uuid in the template cisco.mso.ndo_virtual_port_channel_interface: host: mso_host username: admin @@ -196,7 +196,7 @@ state: query register: query_all -- name: Delete an Virtual Port Channel Interface using it's name +- name: Delete an Virtual Port Channel Interface using its name cisco.mso.ndo_virtual_port_channel_interface: host: mso_host username: admin @@ -205,7 +205,7 @@ virtual_port_channel_interface: ansible_virtual_port_channel_interface_changed state: absent -- name: Delete an Virtual Port Channel Interface using it's uuid +- name: Delete an Virtual Port Channel Interface using its uuid cisco.mso.ndo_virtual_port_channel_interface: host: mso_host username: admin @@ -223,6 +223,7 @@ from ansible_collections.cisco.mso.plugins.module_utils.mso import ( MSOModule, mso_argument_spec, + format_interface_descriptions, ) from ansible_collections.cisco.mso.plugins.module_utils.template import ( MSOTemplate, @@ -347,14 +348,7 @@ def main(): match.details["node2Details"]["memberInterfaces"] = interfaces_node_2 if interface_descriptions: - interface_descriptions = [ - { - "nodeID": interface.get("node"), - "interfaceID": interface.get("interface_id"), - "description": interface.get("description"), - } - for interface in interface_descriptions - ] + interface_descriptions = format_interface_descriptions(interface_descriptions) if interface_descriptions != match.details.get("interfaceDescriptions"): ops.append(dict(op="replace", path="{0}/{1}/interfaceDescriptions".format(path, match.index), value=interface_descriptions)) match.details["interfaceDescriptions"] = interface_descriptions @@ -379,14 +373,7 @@ def main(): if description is not None: payload["description"] = description if interface_descriptions: - payload["interfaceDescriptions"] = [ - { - "nodeID": interface.get("node"), - "interfaceID": interface.get("interface_id"), - "description": interface.get("description"), - } - for interface in interface_descriptions - ] + payload["interfaceDescriptions"] = format_interface_descriptions(interface_descriptions) ops.append(dict(op="add", path="{0}/-".format(path), value=payload))