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

Added ndo_l3out_node_group_policy module to manage L3Out Node Group Policy (DCNE-181) #555

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,37 @@ def get_interface_policy_group_uuid(self, interface_policy_group):
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")

def get_l3out_object(self, uuid=None, name=None, fail_module=False):
"""
Get the L3Out by uuid or name.
:param uuid: UUID of the L3Out to search for -> Str
:param name: Name of the L3Out to search for -> Str
:param fail_module: When match is not found fail the ansible module -> Bool
:return: Dict | None | List[Dict] | List[]: The processed result which could be:
When the UUID | Name is existing in the search list -> Dict
When the UUID | Name is not existing in the search list -> None
When both UUID and Name are None, and the search list is not empty -> List[Dict]
When both UUID and Name are None, and the search list is empty -> List[]
"""
existing_l3outs = self.template.get("l3outTemplate", {}).get("l3outs", [])
if uuid or name: # Query a specific object
return self.get_object_by_key_value_pairs("L3Out", existing_l3outs, [KVPair("uuid", uuid) if uuid else KVPair("name", name)], fail_module)
return existing_l3outs # Query all objects

def get_l3out_node_group(self, name, l3out_object, fail_module=False):
"""
Get the L3Out Node Group Policy by name.
:param name: Name of the L3Out Node Group Policy to search for -> Str
:param l3out_object: L3Out object to search Node Group Policy -> Dict
:param fail_module: When match is not found fail the ansible module -> Bool
:return: Dict | None | List[Dict] | List[]: The processed result which could be:
When the Name is existing in the search list -> Dict
When the Name is not existing in the search list -> None
When the Name is None, and the search list is not empty -> List[Dict]
When the Name is None, and the search list is empty -> List[]
"""
existing_l3out_node_groups = l3out_object.get("nodeGroups", [])
if name: # Query a specific object
return self.get_object_by_key_value_pairs("L3Out Node Group Policy", existing_l3out_node_groups, [KVPair("name", name)], fail_module)
return existing_l3out_node_groups # Query all objects
19 changes: 10 additions & 9 deletions plugins/module_utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,6 @@ def generate_api_endpoint(path, **kwargs):
:param kwargs: Keyword arguments representing query parameters. -> Dict
:return: A string representing the full API endpoint with query parameters. -> Str
"""
# if not kwargs:
# return path

# query_strings = ["{0}={1}".format(key, value) for key, value in kwargs.items()]
# query_string = "&".join(query_strings)
# full_url = "{0}?{1}".format(path, query_string)

# return full_url

return path if not kwargs else "{0}?{1}".format(path, "&".join(["{0}={1}".format(key, value) for key, value in kwargs.items()]))


Expand Down Expand Up @@ -145,3 +136,13 @@ def recursive_delete(data, path, keys):

for key in remove_data:
recursive_delete(existing_data, update_path, key if isinstance(key, tuple) else (key,))


def check_if_all_elements_are_none(values):
"""
Checks if all the elements in the provided list are None.

:param values: List of values to check. -> List
:return: True if all elements are None, False otherwise. -> boo
"""
return all(value is None for value in values)
Loading
Loading