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

Fix the issue of deleting template and also creating fabric sites and zone in single task #45

Merged
merged 23 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b50fde8
Fix the issue of verifying the deletion of template or project
Abhishek-121 Nov 20, 2024
f2ef9b7
Merge branch 'main' into main
Abhishek-121 Nov 20, 2024
f4bb5d7
address review comments
Abhishek-121 Nov 21, 2024
3d6b5fe
Merge branch 'main' of https://github.com/cisco-en-programmability/ca…
Abhishek-121 Nov 21, 2024
eff443c
changes
Abhishek-121 Nov 21, 2024
7d85653
revert the version in galaxy.yml
Abhishek-121 Nov 21, 2024
becc284
revert the import statements after documentation
Abhishek-121 Nov 21, 2024
9287475
moved import to the top of the module
Abhishek-121 Nov 25, 2024
b54365c
add new line after import statements
Abhishek-121 Nov 25, 2024
54d4ee5
Merge branch 'main' of https://github.com/cisco-en-programmability/ca…
Abhishek-121 Nov 25, 2024
af9895f
add quotes to the variable
Abhishek-121 Nov 25, 2024
24d5b76
Revert "add new line after import statements"
Abhishek-121 Nov 25, 2024
358c7c6
revert 2 commits before
Abhishek-121 Nov 25, 2024
52d6207
Fix the issue of creating fabric sites/zones in single go
Abhishek-121 Nov 27, 2024
4694777
Merge branch 'main' of https://github.com/cisco-en-programmability/ca…
Abhishek-121 Nov 28, 2024
b638630
Add space after - to fix sanity errors
Abhishek-121 Nov 28, 2024
e7be6d2
Merge branch 'main' of https://github.com/cisco-en-programmability/ca…
Abhishek-121 Nov 28, 2024
a93967c
revert the space after -
Abhishek-121 Nov 28, 2024
933beff
fix sanity errors
Abhishek-121 Nov 28, 2024
c207857
fix sanity for fabric site module
Abhishek-121 Nov 28, 2024
ffa7799
fix sanity
Abhishek-121 Nov 28, 2024
885d772
revert readme changes
Abhishek-121 Nov 28, 2024
af546a3
Update the log messages
Abhishek-121 Nov 28, 2024
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
59 changes: 40 additions & 19 deletions plugins/modules/sda_fabric_sites_zones_workflow_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Copyright (c) 2022, 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

Check warning on line 7 in plugins/modules/sda_fabric_sites_zones_workflow_manager.py

View workflow job for this annotation

GitHub Actions / Sanity (Ⓐdevel)

7:1 [document-start] missing document start "---"

__metaclass__ = type
__author__ = ("Abhishek Maheshwari, Madhan Sankaranarayanan")
Expand All @@ -14,13 +14,13 @@
module: sda_fabric_sites_zones_workflow_manager
short_description: Manage fabric site(s)/zone(s) and update the authentication profile template in Cisco Catalyst Center.
description:
- Creating fabric site(s) for the SDA operation in Cisco Catalyst Center.
- Updating fabric site(s) for the SDA operation in Cisco Catalyst Center.
- Creating fabric zone(s) for the SDA operation in Cisco Catalyst Center.
- Updating fabric zone(s) for the SDA operation in Cisco Catalyst Center.
- Deletes fabric site(s) from Cisco Catalyst Center.
- Deletes fabric zone(s) from Cisco Catalyst Center.
- Configure the authentication profile template for fabric site/zone in Cisco Catalyst Center.
- Creating fabric site(s) for the SDA operation in Cisco Catalyst Center.
- Updating fabric site(s) for the SDA operation in Cisco Catalyst Center.
- Creating fabric zone(s) for the SDA operation in Cisco Catalyst Center.
- Updating fabric zone(s) for the SDA operation in Cisco Catalyst Center.
- Deletes fabric site(s) from Cisco Catalyst Center.
- Deletes fabric zone(s) from Cisco Catalyst Center.
- Configure the authentication profile template for fabric site/zone in Cisco Catalyst Center.
version_added: '6.17.0'
extends_documentation_fragment:
- cisco.dnac.workflow_manager_params
Expand All @@ -30,11 +30,11 @@
config_verify:
description: Set to True to verify the Cisco Catalyst Center configuration after applying the playbook configuration.
type: bool
default: False
default: false
state:
description: The desired state of Cisco Catalyst Center after the module execution.
type: str
choices: [ merged, deleted ]
choices: [merged, deleted]
default: merged
config:
description: A list containing detailed configurations for creating, updating, or deleting fabric sites or zones
Expand All @@ -44,7 +44,7 @@
to authentication profiles.
type: list
elements: dict
required: True
required: true
suboptions:
fabric_sites:
description: A dictionary containing detailed configurations for managing REST Endpoints that will receive Audit log
Expand All @@ -57,13 +57,13 @@
sites or zones, as well as for updating the authentication profile template. This parameter is mandatory for
any fabric site/zone management operation.
type: str
required: True
required: true
fabric_type:
description: Specifies the type of site to be managed within the SDA environment. The acceptable values are 'fabric_site'
and 'fabric_zone'. The default value is 'fabric_site', indicating the configuration of a broader network area, whereas
'fabric_zone' typically refers to a more specific segment within the site.
type: str
required: True
required: true
authentication_profile:
description: The authentication profile applied to the specified fabric. This profile determines the security posture and
controls for network access within the site. Possible values include 'Closed Authentication', 'Low Impact',
Expand Down Expand Up @@ -107,8 +107,8 @@


requirements:
- dnacentersdk >= 2.9.2
- python >= 3.9
- dnacentersdk >= 2.9.2
- python >= 3.9

notes:
- To ensure the module operates correctly for scaled sets, which involve creating or updating fabric sites/zones and handling
Expand All @@ -133,7 +133,7 @@

"""

EXAMPLES = r"""

Check failure on line 136 in plugins/modules/sda_fabric_sites_zones_workflow_manager.py

View workflow job for this annotation

GitHub Actions / Sanity (Ⓐdevel)

136:14 syntax error: could not find expected ':' (syntax)
- name: Create a fabric site for SDA with the specified name.
cisco.dnac.sda_fabric_sites_zones_workflow_manager:
dnac_host: "{{dnac_host}}"
Expand Down Expand Up @@ -1339,10 +1339,18 @@

# Create/Update Fabric sites/zones in Cisco Catalyst Center
raw_fabric_sites = self.want.get('fabric_sites')
# Convert each dictionary to a sorted tuple of key-value pairs
unique_fabric_sites = {tuple(sorted(d.items())) for d in raw_fabric_sites}
# Convert each unique tuple back into a dictionary
fabric_sites = [dict(t) for t in unique_fabric_sites]
# Preserve the order of input while deduplicating
Abhishek-121 marked this conversation as resolved.
Show resolved Hide resolved
self.log("Starting deduplication of raw_fabric_sites.", "DEBUG")
unique_fabric_site_set = set()
fabric_sites = []
for fabric_site_dict in raw_fabric_sites:
# Convert dictionary to a frozenset - immutable set
site_zone = frozenset(fabric_site_dict.items())
if site_zone not in unique_fabric_site_set:
Abhishek-121 marked this conversation as resolved.
Show resolved Hide resolved
self.log("New unique site found: '{0}'".format(site_zone), "DEBUG")
unique_fabric_site_set.add(site_zone)
fabric_sites.append(fabric_site_dict)
self.log("Deduplication complete. Total unique sites: {0}".format(len(fabric_sites)), "DEBUG")

Abhishek-121 marked this conversation as resolved.
Show resolved Hide resolved
for site in fabric_sites:
site_name = site.get("site_name_hierarchy")
Expand Down Expand Up @@ -1497,7 +1505,20 @@
self.set_operation_result("failed", False, self.msg, "ERROR")
return self

fabric_sites = self.want.get('fabric_sites')
raw_fabric_sites = self.want.get('fabric_sites')
# Preserve the order of input while deduplicating
self.log("Starting deduplication of raw_fabric_sites.", "DEBUG")
unique_fabric_site_set = set()
fabric_sites = []
for fabric_site_dict in raw_fabric_sites:
# Convert dictionary to a frozenset - immutable set
site_zone = frozenset(fabric_site_dict.items())
if site_zone not in unique_fabric_site_set:
self.log("New unique site found: '{0}'".format(site_zone), "DEBUG")
unique_fabric_site_set.add(site_zone)
fabric_sites.append(fabric_site_dict)

self.log("Deduplication complete. Total unique sites: {0}".format(len(fabric_sites)), "DEBUG")
fabric_site_dict = {}

for site in fabric_sites:
Expand Down
85 changes: 40 additions & 45 deletions plugins/modules/template_workflow_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -*- 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)
"""Ansible module to perform operations on project and templates in Cisco Catalyst Center."""

Check warning on line 5 in plugins/modules/template_workflow_manager.py

View workflow job for this annotation

GitHub Actions / Sanity (Ⓐdevel)

5:1 [document-start] missing document start "---"

Check failure on line 5 in plugins/modules/template_workflow_manager.py

View workflow job for this annotation

GitHub Actions / Sanity (Ⓐdevel)

5:3 syntax error: expected '<document start>', but found '<scalar>' (syntax)

from __future__ import absolute_import, division, print_function

Expand All @@ -14,14 +14,14 @@
module: template_workflow_manager
short_description: Resource module for Template functions
description:
- Manage operations create, update and delete of the resource Configuration Template.
- API to create a template by project name and template name.
- API to update a template by template name and project name.
- API to delete a template by template name and project name.
- API to export the projects for given projectNames.
- API to export the templates for given templateIds.
- API to manage operation create of the resource Configuration Template Import Project.
- API to manage operation create of the resource Configuration Template Import Template.
- Manage operations create, update and delete of the resource Configuration Template.
- API to create a template by project name and template name.
- API to update a template by template name and project name.
- API to delete a template by template name and project name.
- API to export the projects for given projectNames.
- API to export the templates for given templateIds.
- API to manage operation create of the resource Configuration Template Import Project.
- API to manage operation create of the resource Configuration Template Import Template.
version_added: '6.6.0'
extends_documentation_fragment:
- cisco.dnac.workflow_manager_params
Expand All @@ -34,15 +34,15 @@
config_verify:
description: Set to True to verify the Cisco Catalyst Center after applying the playbook config.
type: bool
default: False
default: false
state:
description: The state of Cisco Catalyst Center after module completion.
type: str
choices: [ merged, deleted ]
choices: [merged, deleted]
default: merged
config:
description:
- List of details of templates being managed.
- List of details of templates being managed.
type: list
elements: dict
required: true
Expand All @@ -59,9 +59,9 @@
type: bool
containing_templates:
description:
- Refer to a set of templates within the main template to define more complex or modular configurations.
- This is particularly useful in systems that support hierarchical or nested templates.
- Here parent templates may contain child templates to form a complete configuration.
- Refer to a set of templates within the main template to define more complex or modular configurations.
- This is particularly useful in systems that support hierarchical or nested templates.
- Here parent templates may contain child templates to form a complete configuration.
suboptions:
composite:
description: Specifies if the template is composite.
Expand Down Expand Up @@ -252,8 +252,8 @@
type: str
failure_policy:
description:
- Define failure policy if template provisioning fails.
- failure_policy will be enabled only when the composite is set to True.
- Define failure policy if template provisioning fails.
- failure_policy will be enabled only when the composite is set to True.
choices:
- ABORT_TARGET_ON_ERROR
type: str
Expand Down Expand Up @@ -424,21 +424,21 @@
suboptions:
do_version:
description:
- Determines whether to create a new version of the project with the imported contents.
- If set to true and the project already exists, a new version will be created.
- If false, the operation will fail with a 'Project already exists' error if the project already exists.
- Determines whether to create a new version of the project with the imported contents.
- If set to true and the project already exists, a new version will be created.
- If false, the operation will fail with a 'Project already exists' error if the project already exists.
type: bool
project_file:
description:
- Specifies the path to a JSON file that contains the import project configuration.
- If both 'project_file' and 'payload' are provided, the 'project_file' will be given priority.
- Specifies the path to a JSON file that contains the import project configuration.
- If both 'project_file' and 'payload' are provided, the 'project_file' will be given priority.
type: str
version_added: 6.17.0
payload:
description:
- Directly imports configuration data into the system using the provided payload.
- Offers an alternative to 'project_file' for importing configurations without referencing an external file.
- Ignored if 'project_file' is also provided.
- Directly imports configuration data into the system using the provided payload.
- Offers an alternative to 'project_file' for importing configurations without referencing an external file.
- Ignored if 'project_file' is also provided.
type: list
elements: dict
suboptions:
Expand All @@ -457,14 +457,14 @@
type: bool
template_file:
description:
- Specifies the path to a JSON file that contains an import template.
- If both 'template_file' and 'payload' are provided, the 'template_file' will be given priority.
- Specifies the path to a JSON file that contains an import template.
- If both 'template_file' and 'payload' are provided, the 'template_file' will be given priority.
type: str
payload:
description:
- The payload parameter is used to directly import configuration data into the system.
- The payload provides an alternative way to import configurations without the need to reference an external file.
- If both 'template_file' and 'payload' are provided, the 'template_file' will be given priority.
- The payload parameter is used to directly import configuration data into the system.
- The payload provides an alternative way to import configurations without the need to reference an external file.
- If both 'template_file' and 'payload' are provided, the 'template_file' will be given priority.
type: list
elements: dict
suboptions:
Expand All @@ -476,9 +476,9 @@
type: bool
containing_templates:
description:
- Refer to a set of templates within the main template to define more complex or modular configurations.
- This is particularly useful in systems that support hierarchical or nested templates.
- Here parent templates may contain child templates to form a complete configuration.
- Refer to a set of templates within the main template to define more complex or modular configurations.
- This is particularly useful in systems that support hierarchical or nested templates.
- Here parent templates may contain child templates to form a complete configuration.
suboptions:
composite:
description: Specifies if the template is composite.
Expand Down Expand Up @@ -666,8 +666,8 @@
type: str
failure_policy:
description:
- Define failure policy if template provisioning fails.
- failure_policy will be enabled only when the composite is set to True.
- Define failure policy if template provisioning fails.
- failure_policy will be enabled only when the composite is set to True.
choices:
- ABORT_TARGET_ON_ERROR
type: str
Expand Down Expand Up @@ -885,8 +885,8 @@


requirements:
- dnacentersdk >= 2.7.2
- python >= 3.9
- dnacentersdk >= 2.7.2
- python >= 3.9
notes:
- SDK Method used are
configuration_templates.ConfigurationTemplates.create_template,
Expand Down Expand Up @@ -3371,7 +3371,7 @@
template_params = self.want.get("template_params")
params_key = {"template_id": self.have_template.get("id")}
deletion_value = "deletes_the_template"
name = "templateName: {0}".format(template_params.get('templateName'))
name = "templateName: {0}".format(template_params.get('name'))

response = self.dnac_apply['exec'](
family="configuration_templates",
Expand Down Expand Up @@ -3464,6 +3464,7 @@
self.msg = "Project is not deletable"
self.status = "failed"
return self
self.log("Successfully completed the delete operation for the template {0}".format(templateName), "DEBUG")

deploy_temp_details = config.get("deploy_template")
if deploy_temp_details:
Expand All @@ -3474,8 +3475,6 @@
).format(template_name)
self.set_operation_result("failed", False, self.msg, "ERROR").check_return_status()

self.msg = "Successfully completed delete state execution"
self.status = "success"
return self

def verify_diff_merged(self, config):
Expand Down Expand Up @@ -3570,15 +3569,11 @@
"name",
templateName)
if template_info:
self.msg = "Configuration Template config is not applied to the Cisco Catalyst Center."
self.status = "failed"
self.log("Configuration Template config is not applied to the Cisco Catalyst Center.", "WARNING")
return self

self.log("Successfully validated absence of template in the Catalyst Center.", "INFO")
self.result['response'][0].get("configurationTemplate").get("response").update({"Validation": "Success"})
self.log("Successfully validated the absence of Template {0} in the Cisco Catalyst Center.".format(templateName), "INFO")

self.msg = "Successfully validated the absence of Template in the Cisco Catalyst Center."
self.status = "success"
return self

def reset_values(self):
Expand Down
Loading