Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a new module to manage Port Channel Interfaces in Fabric Resource Policies Template. (DCNE-52) #539

Merged
merged 14 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions plugins/module_utils/mso.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,40 @@ def write_file(module, url, dest, content, resp, tmpsrc=None):
os.remove(tmpsrc)


def format_interface_descriptions(mso, interface_descriptions, node=None):
if interface_descriptions:

def format_range_interfaces(format_dict):
ids = format_dict.get("interfaceID")
if re.fullmatch(r"((\d+/)+\d+$)", ids):
yield format_dict
elif re.fullmatch(r"((\d+/)+\d+-\d+$)", ids):
slots = ids.rsplit("/", 1)[0]
range_start, range_stop = ids.rsplit("/", 1)[1].split("-")
if int(range_stop) > int(range_start):
for x in range(int(range_start), int(range_stop) + 1):
copy_format_dict = deepcopy(format_dict)
copy_format_dict.update(interfaceID="{0}/{1}".format(slots, x))
yield copy_format_dict
else:
mso.fail_json(msg="Range start is greater than or equal to range stop for range of IDs '{0}'".format(ids))
else:
mso.fail_json(msg="Incorrect interface ID or range of IDs. Got '{0}'".format(ids))

return [
item
for interface_description in interface_descriptions
for item in format_range_interfaces(
{
"nodeID": node if node is not None else interface_description.get("node"),
"interfaceID": interface_description.get("interface_id", interface_description.get("interfaceID")),
"description": interface_description.get("description"),
}
)
]
return []


class MSOModule(object):
def __init__(self, module):
self.module = module
Expand Down
11 changes: 11 additions & 0 deletions plugins/module_utils/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,14 @@ def get_l3out_node_routing_policy_object(self, uuid=None, name=None, fail_module
"L3Out Node Routing Policy", existing_l3out_node_routing_policy, [KVPair("uuid", uuid) if uuid else KVPair("name", name)], fail_module
)
return existing_l3out_node_routing_policy # Query all objects

def get_interface_policy_group_uuid(self, interface_policy_group):
"""
Get the UUID of an Interface Policy Group by name.
:param interface_policy_group: Name of the Interface Policy Group to search for -> Str
:return: UUID of the Interface Policy Group. -> Str
"""
existing_policy_groups = self.template.get("fabricPolicyTemplate", {}).get("template", {}).get("interfacePolicyGroups", [])
kv_list = [KVPair("name", interface_policy_group)]
match = self.get_object_by_key_value_pairs("Interface Policy Groups", existing_policy_groups, kv_list, fail_module=True)
return match.details.get("uuid")
Loading
Loading