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

Network wireless profile workflow manager dev #140

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
bfb493b
Add assurance issue settings workflow manager
Kandarimegha Feb 1, 2025
fe465fb
new branch for application policy
syed-khadeerahmed Feb 2, 2025
47633ca
assurance healthscore workflow manager
Kandarimegha Feb 2, 2025
08163af
remove commented code
Kandarimegha Feb 3, 2025
2f0487a
Assurance workflow manager
Kandarimegha Feb 3, 2025
9de091a
Pull req move to dev repo
md-rafeek Feb 3, 2025
7c026e6
Network switch profile workflow manager
md-rafeek Feb 3, 2025
e447476
Network wireless profile workflow code completed
md-rafeek Feb 3, 2025
782e4ce
Network wireless profile workflow code completed
md-rafeek Feb 3, 2025
9b10725
Path trace workflow minor code changes in comments
md-rafeek Feb 3, 2025
8897468
Path trace UT cases added
md-rafeek Feb 3, 2025
5b0fdf0
Network switch profile with UT and IT added
md-rafeek Feb 10, 2025
cd48cd8
Merge branch 'network_switch_profile_workflow_manager_dev' of github.…
md-rafeek Feb 10, 2025
0abaeb9
UT completed
syed-khadeerahmed Feb 10, 2025
a00da17
network_wireless_profile UT and IT added
md-rafeek Feb 10, 2025
0f27d40
removed extra log
Kandarimegha Feb 10, 2025
89d0f0f
network_switch_profile_workflow_manager completed
md-rafeek Feb 12, 2025
8ef72da
network_switch_profile_workflow_manager completed
md-rafeek Feb 12, 2025
8502ee6
Merge branch 'network_switch_profile_workflow_manager_dev' of github.…
md-rafeek Feb 13, 2025
c49ecb8
network_wireless_profile_workflow_manager minor fix
md-rafeek Feb 13, 2025
c71f85d
documentation update
Kandarimegha Feb 18, 2025
56135b7
Delete playbooks/assurance_healthscore_settings_workflow_manager.yml
Kandarimegha Feb 18, 2025
89d7662
Yaml Document changed for switch profile
md-rafeek Feb 18, 2025
fcaa165
Path trace Addressed the review comments
md-rafeek Feb 21, 2025
80497ee
Path trace workflow Addressed all code review comments
md-rafeek Feb 21, 2025
ba97eb3
address review comments
Kandarimegha Feb 23, 2025
d87290e
Merge branch 'healthscore_workflow_manager' of https://github.com/Kan…
Kandarimegha Feb 23, 2025
af5345d
Switch profile changes in dnac move to network_profiles
md-rafeek Feb 23, 2025
49bd4bf
Network Switch profile Addressed code review Comments
md-rafeek Feb 23, 2025
c1f022b
Merge branch 'network_switch_profile_workflow_manager_dev' of github.…
md-rafeek Feb 23, 2025
dc66f61
Minor correction on Path trace
md-rafeek Feb 24, 2025
5edf5b4
add log
Kandarimegha Feb 24, 2025
479d0c7
doc updation
Kandarimegha Feb 24, 2025
c99818b
Path trace code reveiw comments addressed
md-rafeek Feb 24, 2025
8105263
Switch profile addressed code review and bug fixed
md-rafeek Feb 24, 2025
ac2a3a5
Merge branch 'network_switch_profile_workflow_manager_dev' of github.…
md-rafeek Feb 24, 2025
e914cd8
1st review compleated
syed-khadeerahmed Feb 25, 2025
ceddae6
doc update
Kandarimegha Feb 25, 2025
c6b66d1
Doc string changed in path trace have function
md-rafeek Feb 25, 2025
ee9ef22
addressed review comments
Kandarimegha Feb 25, 2025
00843ff
minor change
Kandarimegha Feb 25, 2025
183240b
Merge pull request #7 from cisco-en-programmability/main
madhansansel Feb 25, 2025
daada3c
Address review comments and done sanity test
Kandarimegha Feb 26, 2025
423b506
Addressed all 45 code review comments
md-rafeek Feb 26, 2025
dce3316
fixing the review comments
syed-khadeerahmed Feb 26, 2025
37a4447
Switch profile some common changes for code quality
md-rafeek Feb 26, 2025
8df76b0
Merge branch 'network_switch_profile_workflow_manager_dev' of github.…
md-rafeek Feb 26, 2025
9a4e930
Switch profile some common changes for code quality
md-rafeek Feb 26, 2025
a2feec5
Modification
Kandarimegha Feb 26, 2025
1710196
modification
Kandarimegha Feb 26, 2025
79497a6
changes as per review
Kandarimegha Feb 26, 2025
648bfda
Addressed code review comments
Kandarimegha Feb 26, 2025
0418b6c
Address core review for path trace
md-rafeek Feb 27, 2025
848ae83
Address core review for path trace
md-rafeek Feb 27, 2025
4c50a92
Address core review for path trace
md-rafeek Feb 27, 2025
6225b4b
Address core review for path trace
md-rafeek Feb 27, 2025
656c2f5
Address core review for path trace
md-rafeek Feb 27, 2025
bd46446
Address core review for path trace
md-rafeek Feb 27, 2025
14b7051
Merge branch 'main' of https://github.com/cisco-en-programmability/ca…
md-rafeek Feb 27, 2025
2431b4e
Address core review for path trace
md-rafeek Feb 27, 2025
17c3106
Address core review for path trace
md-rafeek Feb 27, 2025
f971729
Address core review for path trace
md-rafeek Feb 27, 2025
ef22db1
review comments fixed
syed-khadeerahmed Feb 27, 2025
cd355ff
fixed review comments
syed-khadeerahmed Feb 27, 2025
a282702
addressed review comment
Kandarimegha Feb 27, 2025
7dd20ee
update example playbook
Kandarimegha Feb 27, 2025
ddb49e4
Code reveiw comment addressed for path trace
md-rafeek Feb 28, 2025
9b3aacf
Code reveiw comment addressed for path trace
md-rafeek Feb 28, 2025
bc10efc
Code reveiw comment addressed for path trace
md-rafeek Feb 28, 2025
7c409a3
Code reveiw comment addressed for path trace
md-rafeek Feb 28, 2025
28e932a
Merge pull request #1 from Kandarimegha/assurance_workflow_manager
madhansansel Feb 28, 2025
f6f3a69
Merge pull request #9 from cisco-en-programmability/main
madhansansel Feb 28, 2025
0dbcf6c
Merge pull request #4 from md-rafeek/pathtrace_workflow_manager_dev
madhansansel Feb 28, 2025
4e47e20
Merge pull request #3 from Kandarimegha/healthscore_workflow_manager
madhansansel Feb 28, 2025
1645c21
Modified code for severity validation
Kandarimegha Feb 28, 2025
3fb9bb6
Merge branch 'main' of https://github.com/cisco-en-programmability/ca…
Kandarimegha Feb 28, 2025
de35356
update severity value in exmple
Kandarimegha Feb 28, 2025
97fe721
minor modification
Kandarimegha Feb 28, 2025
5a5d952
Merge pull request #10 from Kandarimegha/assurance_workflow_manager
madhansansel Feb 28, 2025
bfce56f
fixed review comments
syed-khadeerahmed Feb 28, 2025
c50830c
Merge pull request #2 from syed-khadeerahmed/application_policy_workf…
madhansansel Feb 28, 2025
d096fa0
Merge branch 'main' of https://github.com/cisco-en-programmability/ca…
md-rafeek Mar 2, 2025
f7e48ed
Merge branch 'network_switch_profile_workflow_manager_dev' of github.…
md-rafeek Mar 2, 2025
ae7bdd6
Merge pull request #11 from cisco-en-programmability/main
madhansansel Mar 3, 2025
8ed0057
Merge pull request #12 from cisco-en-programmability/main
madhansansel Mar 4, 2025
6d4e16d
Network wireless profile code refactor and added functionality
md-rafeek Mar 4, 2025
c295a0f
Merge branch 'main' of https://github.com/cisco-en-programmability/ca…
md-rafeek Mar 4, 2025
5fba2e3
Sanity check for Wireless profile
md-rafeek Mar 4, 2025
b6f14f1
Sanity check for Wireless profile
md-rafeek Mar 4, 2025
9372da2
Sanity check for Wireless profile
md-rafeek Mar 4, 2025
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
Prev Previous commit
Next Next commit
Network Switch profile Addressed code review Comments
  • Loading branch information
md-rafeek committed Feb 23, 2025
commit 49bd4bf077adc513a9a458d39eef995be75217a5
22 changes: 17 additions & 5 deletions playbooks/network_switch_profile_workflow_manager.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,21 @@
dnac_task_poll_interval: 1
state: merged
config:
- switch_profile:
- profile_name: "test_sw_1"
onboarding_templates: ["Ansible_PNP_Switch"]
day_n_templates: ["Template Provisioning To Device"]
site_names: ["Global/Chennai/LTTS/FLOOR11", "Global/Madurai/LTTS/FLOOR1"]
- profile_name: "test_switch_1"
onboarding_templates:
- "Ansible_PNP_Switch"
- "test_template"
day_n_templates:
- "Template Provisioning To Device"
site_names:
- "Global/APO"
- "Global/Abc"
- profile_name: "test_switch_2"
onboarding_templates:
- "Ansible_PNP_Switch"
day_n_templates:
- "Template Provisioning To Device"
site_names:
- "Global/Chennai"
- "Global/Madurai"
register: output_list
368 changes: 368 additions & 0 deletions plugins/module_utils/network_profiles.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,368 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright (c) 2024, Cisco Systems
# GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)

from __future__ import absolute_import, division, print_function

__metaclass__ = type
__author__ = ["A Mohamed Rafeek, Madhan Sankaranarayanan"]

from ansible_collections.cisco.dnac.plugins.module_utils.dnac import (
DnacBase
)


class NetworkProfileFunctions(DnacBase):
"""Class containing member attributes for network profile workflow manager module"""

def __init__(self, module):
super().__init__(module)

def check_site_template(self, each_profile, profile_info):
"""
Extend get have for site, and template related validate information
for the given profile config from Cisco Catalyst Center

Parameters:
self (object): An instance of a class used for interacting with
Cisco Catalyst Center.
each_profile (dict) - Playbook details containing network profile
profile_info (dict) - Validate and add the site and template info
to the existing profile information.

Returns:
self - The current object with template, validate site id
information collection for profile update.
"""
onboarding_templates = each_profile.get("onboarding_templates")
if onboarding_templates and isinstance(onboarding_templates, list)\
and len(onboarding_templates) > 0:
profile_info["onboarding_templates"] = self.get_templates_details(
onboarding_templates)

day_n_templates = each_profile.get("day_n_templates")
if day_n_templates and isinstance(day_n_templates, list)\
and len(day_n_templates) > 0:
profile_info["day_n_templates"] = self.get_templates_details(
day_n_templates)

site_names = each_profile.get("site_names")
if site_names:
site_response = []
for site in site_names:
if site:
each_site_response = {}
each_site_response["site_exist"], each_site_response["site_id"] =\
self.get_site_id(site)
each_site_response["site_names"] = site
site_response.append(each_site_response)
if not each_site_response["site_exist"]:
self.msg = 'Given site {0} not exist in Catalyst Center'.format(site)
self.log(self.msg, "ERROR")
self.set_operation_result("failed", False, self.msg,
"ERROR").check_return_status()

if len(site_response) > 0:
profile_info["site_response"] = site_response

def get_templates_details(self, template_list):
"""
This Function used to get the list of templates from Cisco Catalyst Center
and validate the template_list exist in the Catalyst Center.

Parameters:
self (object): An instance of a class used for interacting with Cisco Catalyst Center.
template_list (list): list of string contains template name to validate.

Returns:
list: A list of dict contain the Template details of the given list from
template_list.

Description:
This function used to get the templates details from Cisco Catalyst Center and
compare with given template_list from play book and retrun with list of
template details.
"""
self.log("Get templates details for : {0}".format(template_list), "INFO")

try:
response = self.dnac._exec(
family="configuration_templates",
function="gets_the_templates_available_v1",
params={}
)
self.log("Response from gets_the_templates_available_v1 API: {0}".
format(self.pprint(response)), "DEBUG")

if response and isinstance(response, list):
template_info_list = []
if len(response) > 0:
for input_template in template_list:
template_info = {}
for each_template in response:
if each_template.get("name") == input_template:
template_info = {
"template_name": each_template.get("name"),
"template_exist": True,
"template_id": each_template.get("templateId"),
"template_info": each_template
}
template_info_list.append(template_info)

if not template_info:
self.msg = 'Given template {0} not exist in Catalyst Center'.format(
input_template)
self.log(self.msg, "ERROR")
self.set_operation_result("failed", False, self.msg,
"ERROR").check_return_status()

if len(template_info_list) > 0:
return template_info_list
else:
return None

except Exception as e:
self.msg = 'An error occurred during get templates details: {0}'.format(str(e))
self.log(self.msg, "ERROR")
self.set_operation_result("failed", False, self.msg, "ERROR")
return None

def get_network_profile(self, profile_type, offset, limit):
"""
Get network profile list from Cisco Catalyst Center based on the profile type
given in the playbook and response with network profile information.

Parameters:
self (object): An instance of a class used for interacting with Cisco Catalyst Center.
profile_type (str): A string containing Wireless, Switch or Assurance.
offset (int): Offset value start from 1
limit (int): Limit value start from 1 to 500

Returns:
list: A list of dict contains network profile information.

Description:
This function used to get the network profile based on input config.
"""

param = {"type": profile_type,
"offset": offset,
"limit": limit}
self.log("Getting all network profile", "INFO")
try:
response = self.dnac._exec(
family="site_design",
function="retrieves_the_list_of_network_profiles_for_sites_v1",
params=param
)
self.log("Response from retrieves_the_list_of_network_profiles_for_sites_v1 API: {0}".
format(self.pprint(response)), "DEBUG")
if response and isinstance(response, dict):
self.log("Received the network profile response: {0}".
format(self.pprint(response["response"])), "INFO")
return response.get("response")
else:
return None

except Exception as e:
self.msg = 'An error occurred during get network profile: {0}'.format(str(e))
self.log(self.msg, "ERROR")
self.set_operation_result("failed", False, self.msg, "ERROR")
return None

def get_templates_for_profile(self, profile_id):
"""
Get the CLI template for the specific profile id
Parameters:
self (object): An instance of a class used for interacting with Cisco Catalyst Center.
profile_id (str): A string containing profile id to fetch template assigned to
the profile.

Returns:
list: A list of dict contains network template id and name.

Description:
This function is used to get cli template for the specific profile id
"""
self.log("Profile id for the template: {0}".format(profile_id), "INFO")
param = {
"profile_id": profile_id
}

try:
response = self.dnac._exec(
family="network_settings",
function="retrieve_cli_templates_attached_to_a_network_profile_v1",
params=param
)
self.log("Response from retrieve_cli_templates_attached_to_a_network_profile_v1 " +\
"API: {0}".format(self.pprint(response)), "DEBUG")
if response and isinstance(response, dict):
return response.get("response")
else:
return None

except Exception as e:
self.msg = "An error occurred during retrieve cli templates " +\
"for profile: {0}".format(str(e))
self.log(self.msg, "ERROR")
self.fail_and_exit(self.msg)

def assign_site_to_network_profile(self, profile_id, site_id):
"""
Assign a site to a network profile.

Parameters:
self (object): An instance of a class used for interacting with Cisco Catalyst Center.
profile_id (str): A string containing profile id used to assign to site.
site_id (str): A string containing site id used to assign the profile to this site id.

Returns:
dict: A dict contains Task details of the profile assigned status.

Description:
This function is used to assign the Profile id to the Site.
"""
self.log("Assigning site {0} to profile {1}.".format(
profile_id, site_id), "INFO")
params = {
"profile_id": profile_id,
"id": site_id
}

return self.execute_process_task_data(
"site_design", "assign_a_network_profile_for_sites_to_the_given_site_v1",
params
)

def unassign_site_to_network_profile(self, profile_id, site_id):
"""
Un assign a site from the network profile.

Parameters:
self (object): An instance of a class used for interacting with Cisco Catalyst Center.
profile_id (str): A string containing profile id used to un assign from site.
site_id (str): A string containing site id used to un assign from the profile.

Returns:
dict: A dict contains Task details of the profile unassigned status.

Description:
This function is used to un assign the Profile id from the Site.
"""
param = {
"profile_id": profile_id,
"site_id": site_id
}
self.log("Unassign site to network profile for: {0}".format(str(param)), "INFO")

return self.execute_process_task_data(
"site_design", "unassigns_a_network_profile_for_sites_from_multiple_sites_v1",
param
)

def delete_network_profiles(self, profile_id):
"""
Delete network profiles from the Catalyst Center and response with
the task details.

Parameters:
self (object): An instance of a class used for interacting with Cisco Catalyst Center.
profile_id (str): Contains profile to be deleted.

Returns:
dict: A dict contains task details of the deleted status.

Description:
This function is used to delete network profiles from Catalyst Center.
"""

self.log("Delete network profiles for: {0}".format(profile_id), "INFO")
param = {
"id": profile_id,
}

return self.execute_process_task_data(
"site_design", "deletes_a_network_profile_for_sites_v1", param
)

def execute_process_task_data(self, profile_family, profile_function_name,
payload_data, task_id=None):
"""
This function used to execute the payload data based on the family and function
and get the task id, aslo pass the taskid and get details of the task as a output.
Parameters:
self (object): An instance of a class used for interacting with Cisco Catalyst Center.
profile_family (str): A string containing family name of the API.
profile_function_name (str): A string containing function name of the API.
payload_data (dict): Contains dict of payload for the API.
task_id (str): Optional param if task id is available profile_family,
profile_function_name, payload_data can be dummy data
Returns:
dict: A dict contains Task details as output.

Description:
This function is used to process the API call and show the task details
as the response.
"""
try:
if profile_family and profile_function_name and payload_data:
if not task_id:
task_id = self.get_taskid_post_api_call(profile_family,
profile_function_name,
payload_data)
resync_retry_count = int(self.payload.get("dnac_api_task_timeout"))
resync_retry_interval = int(self.payload.get("dnac_task_poll_interval"))
while resync_retry_count:
task_details_response = self.get_tasks_by_id(task_id)
self.log("Status of the task: {0} .".format(self.status), "INFO")

if task_details_response.get("endTime") is not None:
if task_details_response.get("status") == "SUCCESS":
self.result['changed'] = True
self.result['response'] = self.get_task_details_by_id(task_id)
return self.result['response']
if task_details_response.get("status") == "FAILURE":
self.result['changed'] = False
self.result['response'] = self.get_task_details_by_id(task_id)
return self.result['response']

time.sleep(resync_retry_interval)
resync_retry_count = resync_retry_count - 1
else:
return None

except Exception as e:
self.msg = 'An error occurred during get task details: {0}'.format(str(e))
self.log(self.msg, "ERROR")
self.fail_and_exit(self.msg)

def value_exists(self, data, target_key, target_value):
"""
This function used check specifice key, value pair exist in the data of dict or
list of dict and return the True or False as a response.

Parameters:
self (object): An instance of a class used for interacting with Cisco Catalyst Center.
data (dict): Contains dict or list of dict data when need to find
target_key (str): A string containing key of the dict in the data.
target_value (str): A string containing value to find in the data.

Returns:
bool: return True or False based the key, value matches.

Description:
This function is used to check the given key, value exist in the data
and return the true or false..
"""
if isinstance(data, dict):
for value in data.values():
if data.get(target_key) == target_value or\
self.value_exists(value, target_key, target_value):
return True
elif isinstance(data, list):
for item in data:
if self.value_exists(item, target_key, target_value):
return True
return False
Loading