Skip to content

Commit

Permalink
[ignore] Add function in module_utils/mso.py to format interface_desc…
Browse files Browse the repository at this point in the history
…riptions for payload data.
  • Loading branch information
gmicol committed Oct 31, 2024
1 parent 46a8dd3 commit b1f8c14
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
13 changes: 13 additions & 0 deletions plugins/module_utils/mso.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 3 additions & 16 deletions plugins/modules/ndo_virtual_port_channel_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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))

Expand Down

0 comments on commit b1f8c14

Please sign in to comment.