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

Develop v6.10.1 #144

Merged
merged 87 commits into from
Jan 22, 2024
Merged
Changes from 4 commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
7a15f55
Making the previously kept template_pnp_intent playbook to underscore…
abimishr Dec 19, 2023
33b68c9
Changing the name of the variables from camel case to snake case
abimishr Dec 19, 2023
8816a62
Making the previously kept template_pnp_intent playbook to underscore…
abimishr Dec 19, 2023
cad8564
Validating the DNAC after applying the config
Dec 19, 2023
cb2ca45
Changed the description for config_verify
Dec 19, 2023
057f760
Adding the corrected playbook for template_pnp
abimishr Dec 20, 2023
3cdcef6
Adding the corrected playbook for template_pnp
abimishr Dec 20, 2023
de0129c
Merge pull request #78 from abimishr/PNP_Code_Abinash
madhansansel Dec 20, 2023
016bef2
Merge pull request #81 from cisco-en-programmability/main
madhansansel Dec 20, 2023
98b9cbb
Provision Wireless devices, add examples in documentation
Abhishek-121 Dec 20, 2023
ee106c8
Remove redundant task status call by making seperate API and add docs…
Abhishek-121 Dec 21, 2023
720464d
remove f string
Abhishek-121 Dec 21, 2023
4c04b04
Merge pull request #82 from Abhishek-121/main
madhansansel Dec 21, 2023
c8c1a21
Added the validation structure in dnac.py and addresses template id i…
Dec 22, 2023
3bc4d01
Resolved the sanity issues
Dec 22, 2023
305b92c
Addressed the PR comments
Dec 22, 2023
b429d11
Addressed the PR comments
Dec 22, 2023
3313af0
Addressed the PR comments
Dec 22, 2023
d072bd4
Addressed the PR comments
Dec 22, 2023
84d3737
Merge pull request #87 from MUTHU-RAKESH-27/main
madhansansel Dec 22, 2023
d8436d8
Resolved a bug on the variable mismatch on project_name and template_…
Dec 22, 2023
e174ec0
Merge pull request #88 from MUTHU-RAKESH-27/main
madhansansel Dec 22, 2023
f186cd9
Added the code for Validation of Site Creation/Updation/Deletion afte…
Abhishek-121 Dec 22, 2023
a349969
remove unused import dnac_compare_equality
Abhishek-121 Dec 22, 2023
4d49734
add new line
Abhishek-121 Dec 22, 2023
03e1c4b
PnP Reset and hostname added along with unprovision in provision inte…
abimishr Dec 22, 2023
a12cb90
Merge pull request #89 from Abhishek-121/main
madhansansel Dec 22, 2023
2a45e73
PnP Reset and hostname added along with unprovision in provision inte…
abimishr Dec 22, 2023
31a60bc
PnP Reset and hostname added along with unprovision in provision inte…
abimishr Dec 22, 2023
e851c38
PnP Reset and hostname added along with unprovision in provision inte…
abimishr Dec 22, 2023
7c8f212
PnP Reset and hostname added along with unprovision in provision inte…
abimishr Dec 22, 2023
1874627
PnP Reset and hostname added along with unprovision in provision inte…
abimishr Dec 22, 2023
a8696d0
Merge pull request #90 from abimishr/PNP_Code_Abinash
madhansansel Dec 22, 2023
54a9936
Changes in intent modules
madhansansel Dec 22, 2023
26dc6c3
Merge pull request #1 from madhansansel/main
rukapse Jan 4, 2024
9bfc6b3
added verification for device addition/deletion, updation of interfac…
Abhishek-121 Jan 11, 2024
7b9c0d0
Code and playbook for config verify of device addition of PnP only
abimishr Jan 12, 2024
dae5d26
Restored the automation hub signed status for further versions
Jan 12, 2024
342a078
optimised code, address issue of device role not getting updated, add…
Abhishek-121 Jan 12, 2024
878789a
Changed the Unicode quotes to the ASCII quotes
Jan 12, 2024
ddbe686
Merge pull request #93 from MUTHU-RAKESH-27/main
madhansansel Jan 12, 2024
83dc378
print invalid protocol
Abhishek-121 Jan 12, 2024
9ae50da
Validated the global device credentials after applying the playbook c…
Jan 12, 2024
1118745
Merge branch 'madhansansel:main' into main
MUTHU-RAKESH-27 Jan 12, 2024
e78b557
Merge pull request #91 from Abhishek-121/main
madhansansel Jan 12, 2024
3ad3980
Adding device_details.template in gitignore
madhansansel Jan 12, 2024
1865fb3
Chnging the docstring of config check methods in PnP
abimishr Jan 12, 2024
69b0e85
Chnging the docstring of config check methods in PnP
abimishr Jan 12, 2024
1763ee9
Changing the documentation in PnP
abimishr Jan 12, 2024
8050c3c
Addressed the review comments
Jan 16, 2024
995f74b
Merge branch 'madhansansel:main' into main
MUTHU-RAKESH-27 Jan 16, 2024
a275488
Addressed the review comments
Jan 16, 2024
3344459
Merge pull request #96 from MUTHU-RAKESH-27/main
madhansansel Jan 16, 2024
c0c84e6
Supported both the camel and snake cases
Jan 16, 2024
7c1ee6b
Added the log function in the dnac.py file for camel_to_snake_case
Jan 16, 2024
0c89a8e
Merge pull request #98 from MUTHU-RAKESH-27/main
madhansansel Jan 16, 2024
8814f50
Merge remote-tracking branch 'upstream/main'
rukapse Jan 16, 2024
097ee6e
Logging levels implemented in dnac.py
rukapse Jan 17, 2024
fd00e9c
Merge pull request #2 from rukapse/dev
rukapse Jan 17, 2024
80a6294
Changing the documentation in PnP
abimishr Jan 17, 2024
a6db407
Making the PnP code more efficient
abimishr Jan 17, 2024
68fde43
Making the PnP code more efficient
abimishr Jan 17, 2024
175d079
Discovery's CIDR code along wkth documentation change, with verify me…
abimishr Jan 17, 2024
38ac1fb
Discovery's CIDR code along wkth documentation change, with verify me…
abimishr Jan 17, 2024
58938b7
Discovery's CIDR code along wkth documentation change, with verify me…
abimishr Jan 17, 2024
f5e0492
Merge pull request #92 from abimishr/PNP_Code_Abinash
madhansansel Jan 17, 2024
3d0c9af
bug fix in def log under DnacBase
rukapse Jan 18, 2024
b149ac7
Making few changes in documentation of Discovery
abimishr Jan 18, 2024
f1a04d0
Address Jira ticket issue of SWIM, Inventory, Site module and update …
Abhishek-121 Jan 18, 2024
ce8ee03
address PR review comments
Abhishek-121 Jan 19, 2024
875efda
Merge pull request #100 from abimishr/PNP_Code_Abinash
madhansansel Jan 19, 2024
a9dcd0c
Merge pull request #101 from Abhishek-121/main
madhansansel Jan 19, 2024
100853c
sanity test fixes
rukapse Jan 19, 2024
ee980d7
Validated the DNAC after applying the configuration template config
Jan 19, 2024
c7553d0
Addressed the PR comments
Jan 19, 2024
7fe5e36
Update API paramters for Untagging Golden Image, fixed wired device p…
Abhishek-121 Jan 19, 2024
7cf9f3f
remove unused log
Abhishek-121 Jan 19, 2024
12c575f
Merge pull request #103 from MUTHU-RAKESH-27/main
madhansansel Jan 19, 2024
429d1ed
Added code for handling wired provision of dump IP
Abhishek-121 Jan 19, 2024
54f2c44
address review comments
Abhishek-121 Jan 19, 2024
64d0eff
Merge pull request #104 from Abhishek-121/main
madhansansel Jan 19, 2024
59b0c69
line 404 sanity fix
rukapse Jan 19, 2024
68fac25
removed space before new line in logging statement
rukapse Jan 19, 2024
45255fd
Merge pull request #99 from rukapse/main
madhansansel Jan 19, 2024
5454c73
Changes in intent modules
madhansansel Jan 19, 2024
142ca26
Merge pull request #143 from madhansansel/main
fmunozmiranda Jan 22, 2024
18598b0
Updating readme
fmunozmiranda Jan 22, 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
226 changes: 183 additions & 43 deletions plugins/modules/site_intent.py
Original file line number Diff line number Diff line change
@@ -25,6 +25,10 @@
Rishita Chowdhary (@rishitachowdhary)
Abhishek Maheshwari (@abhishekmaheshwari)
options:
config_verify:
description: Set to True to verify the Cisco DNA Center config after applying the playbook config.
type: bool
default: False
state:
description: The state of DNAC after module completion.
type: str
@@ -303,7 +307,6 @@
validate_list_of_dicts,
log,
get_dict_result,
dnac_compare_equality,
)

floor_plan = {
@@ -406,6 +409,7 @@ def get_current_site(self, site):
address=location.get("attributes").get("address"),
latitude=location.get("attributes").get("latitude"),
longitude=location.get("attributes").get("longitude"),
country=location.get("attributes").get("country"),
)
)

@@ -541,9 +545,8 @@ def get_site_params(self, params):
def get_site_name(self, site):
"""
Get and Return the site name.
Parameters:
self (object): An instance of a class used for interacting with Cisco DNA Center.
- self (object): An instance of a class used for interacting with Cisco DNA Center.
- site (dict): A dictionary containing information about the site.
Returns:
- str: The constructed site name.
@@ -561,10 +564,97 @@ def get_site_name(self, site):

return site_name

def compare_float_values(self, ele1, ele2, precision=2):
"""
Compare two floating-point values with a specified precision.
Args:
- self (object): An instance of a class used for interacting with Cisco DNA Center.
- ele1 (float): The first floating-point value to be compared.
- ele2 (float): The second floating-point value to be compared.
- precision (int, optional): The number of decimal places to consider in the comparison, Defaults to 2.
Return:
bool: True if the rounded values are equal within the specified precision, False otherwise.
Description:
This method compares two floating-point values, ele1 and ele2, by rounding them
to the specified precision and checking if the rounded values are equal. It returns
True if the rounded values are equal within the specified precision, and False otherwise.
"""

return round(float(ele1), precision) == round(float(ele2), precision)

def is_area_updated(self, updated_site, requested_site):
"""
Check if the area site details have been updated.
Args:
- self (object): An instance of a class used for interacting with Cisco DNA Center.
- updated_site (dict): The site details after the update.
- requested_site (dict): The site details as requested for the update.
Return:
bool: True if the area details (name and parentName) have been updated, False otherwise.
Description:
This method compares the area details (name and parentName) of the updated site
with the requested site and returns True if they are equal, indicating that the area
details have been updated. Returns False if there is a mismatch in the area site details.
"""

return (
updated_site['name'] == requested_site['name'] and
updated_site['parentName'] == requested_site['parentName']
)

def is_building_updated(self, updated_site, requested_site):
"""
Check if the building details in a site have been updated.
Args:
- self (object): An instance of a class used for interacting with Cisco DNA Center.
- updated_site (dict): The site details after the update.
- requested_site (dict): The site details as requested for the update.
Return:
bool: True if the building details have been updated, False otherwise.
Description:
This method compares the building details of the updated site with the requested site.
It checks if the name, parentName, latitude, longitude, and address (if provided) are
equal, indicating that the building details have been updated. Returns True if the
details match, and False otherwise.
"""

return (
updated_site['name'] == requested_site['name'] and
updated_site['parentName'] == requested_site['parentName'] and
self.compare_float_values(updated_site['latitude'], requested_site['latitude']) and
self.compare_float_values(updated_site['longitude'], requested_site['longitude']) and
(requested_site['address'] is None or updated_site['address'] == requested_site['address'])
)

def is_floor_updated(self, updated_site, requested_site):
"""
Check if the floor details in a site have been updated.
Args:
- self (object): An instance of a class used for interacting with Cisco DNA Center.
- updated_site (dict): The site details after the update.
- requested_site (dict): The site details as requested for the update.
Return:
bool: True if the floor details have been updated, False otherwise.
Description:
This method compares the floor details of the updated site with the requested site.
It checks if the name, rf_model, length, width, and height are equal, indicating
that the floor details have been updated. Returns True if the details match, and False otherwise.
"""

keys_to_compare = ['length', 'width', 'height']
if updated_site['name'] != requested_site['name'] or updated_site['rf_model'] != requested_site['rfModel']:
return False

for key in keys_to_compare:
if not self.compare_float_values(updated_site[key], requested_site[key]):
return False

return True

def site_requires_update(self):
"""
Check if the site requires updates.
Parameters:
self (object): An instance of a class used for interacting with Cisco DNA Center.
Returns:
@@ -576,29 +666,19 @@ def site_requires_update(self):
specified parameters, such as the site type and site details.
"""

requested_site = self.want.get("site_params")
current_site = self.have.get("current_site")

self.log("Current Site: " + str(current_site))
type = self.have['current_site']['type']
updated_site = self.have['current_site']['site'][type]
requested_site = self.want['site_params']['site'][type]
self.log("Current Site: " + str(updated_site))
self.log("Requested Site: " + str(requested_site))

if requested_site.get('type') == "building":
requested_address = requested_site['site']['building']['address']
current_address = current_site['site']['building']['address']

if requested_address is None or requested_address == current_address:
return False

return True
if type == "building":
return not self.is_building_updated(updated_site, requested_site)

obj_params = [
("type", "type"),
("site", "site")
]
elif type == "floor":
return not self.is_floor_updated(updated_site, requested_site)

return any(not dnac_compare_equality(current_site.get(dnac_param),
requested_site.get(ansible_param))
for (dnac_param, ansible_param) in obj_params)
return not self.is_area_updated(updated_site, requested_site)

def get_have(self, config):
"""
@@ -610,9 +690,9 @@ def get_have(self, config):
- self (object): An instance of a class used for interacting with Cisco DNA Center.
Description:
This method queries Cisco DNA Center to check if a specified site
exists. If the site exists, it retrieves details about the current
site, including the site ID and other relevant information. The
results are stored in the 'have' attribute for later reference.
exists. If the site exists, it retrieves details about the current
site, including the site ID and other relevant information. The
results are stored in the 'have' attribute for later reference.
"""

site_exists = False
@@ -635,9 +715,7 @@ def get_have(self, config):

def get_want(self, config):
"""
Get all site-related information from the playbook needed for
creation in Cisco DNA Center.
Get all site-related information from the playbook needed for creation/updation/deletion of site in Cisco DNA Center.
Parameters:
self (object): An instance of a class used for interacting with Cisco DNA Center.
config (dict): A dictionary containing configuration information.
@@ -664,11 +742,9 @@ def get_diff_merged(self, config):
"""
Update/Create site information in Cisco DNA Center with fields
provided in the playbook.
Parameters:
self (object): An instance of a class used for interacting with Cisco DNA Center.
config (dict): A dictionary containing configuration information.
Returns:
self (object): An instance of a class used for interacting with Cisco DNA Center.
Description:
@@ -700,8 +776,10 @@ def get_diff_merged(self, config):
else:
# Site does not neet update
self.result['response'] = self.have.get("current_site")
self.result['msg'] = "Site - {0} does not need update".format(self.have.get("current_site"))
self.module.exit_json(**self.result)
self.msg = "Site - {0} does not need any update".format(self.have.get("current_site"))
self.log(self.msg)
self.result['msg'] = self.msg
return self

else:
# Creating New Site
@@ -799,26 +877,19 @@ def delete_single_site(self, site_id, site_name):
def get_diff_deleted(self, config):
"""
Call Cisco DNA Center API to delete sites with provided inputs.
Parameters:
- self (object): An instance of a class used for interacting with Cisco DNA Center.
- config (dict): Dictionary containing information for site deletion.
Returns:
If the deletion is successful, 'changed' is set to True, and the
'response' includes execution details and the deleted site ID. If
an error occurs during the deletion, the method uses 'fail_json' to
raise an exception with the error message. If the site does not
exist, the method raises an exception with a message indicating that
the site was not found.
- self: The result dictionary includes the following keys:
- 'changed' (bool): Indicates whether changes were made
during the deletion process.
- 'response' (dict): Contains details about the execution
and the deleted site ID.
- 'msg' (str): A message indicating the status of the deletion operation.
Description:
This method initiates the deletion of a site by calling the
'delete_site' function in the 'sites' family of the Cisco DNA
Center API. It uses the site ID obtained from the 'have' attribute.
This method initiates the deletion of a site by calling the 'delete_site' function in the 'sites' family
of the Cisco DNA Center API. It uses the site ID obtained from the 'have' attribute.
"""

site_exists = self.have.get("site_exists")
@@ -860,6 +931,71 @@ def get_diff_deleted(self, config):

return self

def verify_diff_merged(self, config):
"""
Verify the merged status(Creation/Updation) of site configuration in Cisco DNA Center.
Args:
- self (object): An instance of a class used for interacting with Cisco DNA Center.
- config (dict): The configuration details to be verified.
Return:
- self (object): An instance of a class used for interacting with Cisco DNA Center.
Description:
This method checks the merged status of a configuration in Cisco DNA Center by retrieving the current state
(have) and desired state (want) of the configuration, logs the states, and validates whether the specified
site exists in the DNA Center configuration.
"""

self.get_have(config)
self.log(str(self.have))
self.log(str(self.want))
# Code to validate dnac config for merged state
site_exist = self.have.get("site_exists")

if site_exist:
self.status = "success"
msg = "Requested Site - {0} present in Cisco DNA Center and creation verified.".format(self.want.get("site_name"))
self.log(msg)

require_update = self.site_requires_update()

if not require_update:
self.log("Site - {0} Updation Verified Successfully.".format(self.want.get("site_name")))
self. status = "success"
return self

self.log("Playbook paramater doesnot match with the Cisco DNA Center means Merged task not executed successfully.")

return self

def verify_diff_deleted(self, config):
"""
Verify the deletion status of site configuration in Cisco DNA Center.
Args:
- self (object): An instance of a class used for interacting with Cisco DNA Center.
- config (dict): The configuration details to be verified.
Return:
- self (object): An instance of a class used for interacting with Cisco DNA Center.
Description:
This method checks the deletion status of a configuration in Cisco DNA Center.
It validates whether the specified site exists in the DNA Center configuration.
"""

self.get_have(config)
self.log(str(self.have))
self.log(str(self.want))
# Code to validate dnac config for delete state
site_exist = self.have.get("site_exists")

if not site_exist:
self.status = "success"
msg = "Requested Site - {0} already deleted from Cisco DNA Center and verified successfully.".format(self.want.get("site_name"))
self.log(msg)
return self

self.log("Playbook paramater doesnot match with the Cisco DNA Center means Deletion not executed successfully.")

return self


def main():
""" main entry point for module execution
@@ -874,6 +1010,7 @@ def main():
'dnac_debug': {'type': 'bool', 'default': False},
'dnac_log': {'type': 'bool', 'default': False},
'validate_response_schema': {'type': 'bool', 'default': True},
"config_verify": {"type": 'bool', "default": False},
'config': {'required': True, 'type': 'list', 'elements': 'dict'},
'state': {'default': 'merged', 'choices': ['merged', 'deleted']}
}
@@ -890,12 +1027,15 @@ def main():
dnac_site.check_return_status()

dnac_site.validate_input().check_return_status()
config_verify = dnac_site.params.get("config_verify")

for config in dnac_site.validated_config:
dnac_site.reset_values()
dnac_site.get_want(config).check_return_status()
dnac_site.get_have(config).check_return_status()
dnac_site.get_diff_state_apply[state](config).check_return_status()
if config_verify:
dnac_site.verify_diff_state_apply[state](config).check_return_status()

module.exit_json(**dnac_site.result)