Skip to content

Commit

Permalink
Merge pull request #42 from madhansansel/main
Browse files Browse the repository at this point in the history
latest changes 04/01/24
  • Loading branch information
rukapse authored Apr 1, 2024
2 parents d76952f + 5326e0a commit 9ad4bd0
Show file tree
Hide file tree
Showing 16 changed files with 147 additions and 45 deletions.
3 changes: 3 additions & 0 deletions changelogs/changelog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -849,3 +849,6 @@ releases:
- Added attributes 'dnac_api_task_timeout' and 'dnac_task_poll_interval' in intent and workflow_manager modules.
- inventory_workflow_manager - Added attributes 'add_user_defined_field', 'update_interface_details', 'export_device_list' and 'admin_status'
- inventory_workflow_manager - Removed attributes 'provision_wireless_device', 'reprovision_wired_device'
- Added the op_modifies=True when calling SDK APIs in the workflow manager modules.
- Added a method to validate IP addresses.
- Fixed a minor issue in the site workflow manager module.
4 changes: 2 additions & 2 deletions playbooks/PnP.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
template_name: "Ansible_PNP_Switch"
image_name: cat9k_iosxe_npe.17.03.07.SPA.bin
project_name: Onboarding Configuration
template_details:
template_params:
hostname: SJC-Switch-1
interface: TwoGigabitEthernet1/0/2
device_info:
Expand Down Expand Up @@ -108,4 +108,4 @@
- device_info:
- serial_number: QD2425L8M7 #Will get deleted
- serial_number: FTC2320E0HA #Doesn't exist in the inventory
- serial_number: FKC2310E0HB #Doesn't exist in the inventory
- serial_number: FKC2310E0HB #Doesn't exist in the inventory
2 changes: 1 addition & 1 deletion playbooks/PnP_Workflow_Manager_Playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
template_name: "Ansible_PNP_Switch"
image_name: cat9k_iosxe_npe.17.03.07.SPA.bin
project_name: Onboarding Configuration
template_details:
template_params:
hostname: SJC-Switch-1
interface: TwoGigabitEthernet1/0/2
device_info:
Expand Down
10 changes: 5 additions & 5 deletions playbooks/device_provision_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@
dnac_port: "{{ dnac_port }}"
dnac_version: "{{ dnac_version }}"
dnac_debug: "{{ dnac_debug }}"

tasks:
- name: Provision a wired device to a site
cisco.dnac.workflow_manager:
cisco.dnac.provision_workflow_manager:
<<: *dnac_login
dnac_log: True
state: merged
config_verify: True
config:
- site_name_hierarchy: Global/USA/San Francisco/BGL_18
management_ip_address: 204.1.1.1
management_ip_address: 204.1.2.2


- name: Unprovision a wired device from a site
cisco.dnac.workflow_manager:
cisco.dnac.provision_workflow_manager:
<<: *dnac_login
dnac_log: True
state: deleted
config:
- management_ip_address: 204.1.1.1
- management_ip_address: 204.1.2.2
13 changes: 10 additions & 3 deletions plugins/modules/discovery_intent.py
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,7 @@ def get_ccc_global_credentials_v2_info(self):
family="discovery",
function='get_all_global_credentials_v2',
params=self.validated_config[0].get('headers'),
op_modifies=True
)
response = response.get('response')
self.log("The Global credentials response from 'get all global credentials v2' API is {0}".format(str(response)), "DEBUG")
Expand Down Expand Up @@ -1325,6 +1326,7 @@ def get_task_status(self, task_id=None):
family="task",
function='get_task_by_id',
params=params,
op_modifies=True,
)
response = response.response
self.log("Task status for the task id {0} is {1}".format(str(task_id), str(response)), "INFO")
Expand Down Expand Up @@ -1373,7 +1375,8 @@ def lookup_discovery_by_range_via_name(self):
response_part = self.dnac_apply['exec'](
family="discovery",
function='get_discoveries_by_range',
params=params
params=params,
op_modifies=True,
)
response["response"].extend(response_part["response"])
else:
Expand All @@ -1386,7 +1389,8 @@ def lookup_discovery_by_range_via_name(self):
response = self.dnac_apply['exec'](
family="discovery",
function='get_discoveries_by_range',
params=params
params=params,
op_modifies=True,
)
self.log("Response of the get discoveries via range API is {0}".format(str(response)), "DEBUG")

Expand Down Expand Up @@ -1462,6 +1466,7 @@ def get_discovery_device_info(self, discovery_id=None, task_id=None):
family="discovery",
function='get_discovered_network_devices_by_discovery_id',
params=params,
op_modifies=True,
)
devices = response.response

Expand Down Expand Up @@ -1532,6 +1537,7 @@ def delete_exist_discovery(self, params):
family="discovery",
function="delete_discovery_by_id",
params=params,
op_modifies=True,
)

self.log("Response collected from API 'delete_discovery_by_id': {0}".format(str(response)), "DEBUG")
Expand Down Expand Up @@ -1649,7 +1655,8 @@ def verify_diff_merged(self, config):
response = self.dnac_apply['exec'](
family="discovery",
function='get_discovery_by_id',
params=params
params=params,
op_modifies=True,
)
discovery_name = config.get('discovery_name')
if response:
Expand Down
13 changes: 10 additions & 3 deletions plugins/modules/discovery_workflow_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,7 @@ def get_ccc_global_credentials_v2_info(self):
family="discovery",
function='get_all_global_credentials_v2',
params=self.validated_config[0].get('headers'),
op_modifies=True
)
response = response.get('response')
self.log("The Global credentials response from 'get all global credentials v2' API is {0}".format(str(response)), "DEBUG")
Expand Down Expand Up @@ -1325,6 +1326,7 @@ def get_task_status(self, task_id=None):
family="task",
function='get_task_by_id',
params=params,
op_modifies=True,
)
response = response.response
self.log("Task status for the task id {0} is {1}".format(str(task_id), str(response)), "INFO")
Expand Down Expand Up @@ -1373,7 +1375,8 @@ def lookup_discovery_by_range_via_name(self):
response_part = self.dnac_apply['exec'](
family="discovery",
function='get_discoveries_by_range',
params=params
params=params,
op_modifies=True,
)
response["response"].extend(response_part["response"])
else:
Expand All @@ -1386,7 +1389,8 @@ def lookup_discovery_by_range_via_name(self):
response = self.dnac_apply['exec'](
family="discovery",
function='get_discoveries_by_range',
params=params
params=params,
op_modifies=True,
)
self.log("Response of the get discoveries via range API is {0}".format(str(response)), "DEBUG")

Expand Down Expand Up @@ -1462,6 +1466,7 @@ def get_discovery_device_info(self, discovery_id=None, task_id=None):
family="discovery",
function='get_discovered_network_devices_by_discovery_id',
params=params,
op_modifies=True,
)
devices = response.response

Expand Down Expand Up @@ -1532,6 +1537,7 @@ def delete_exist_discovery(self, params):
family="discovery",
function="delete_discovery_by_id",
params=params,
op_modifies=True,
)

self.log("Response collected from API 'delete_discovery_by_id': {0}".format(str(response)), "DEBUG")
Expand Down Expand Up @@ -1649,7 +1655,8 @@ def verify_diff_merged(self, config):
response = self.dnac_apply['exec'](
family="discovery",
function='get_discovery_by_id',
params=params
params=params,
op_modifies=True,
)
discovery_name = config.get('discovery_name')
if response:
Expand Down
20 changes: 20 additions & 0 deletions plugins/modules/inventory_intent.py
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,7 @@ def is_udf_exist(self, field_name):
response = self.dnac._exec(
family="devices",
function='get_all_user_defined_fields',
op_modifies=True,
params={"name": field_name},
)

Expand Down Expand Up @@ -943,6 +944,7 @@ def create_user_defined_field(self, udf):
response = self.dnac._exec(
family="devices",
function='create_user_defined_field',
op_modifies=True,
params=udf,
)
self.log("Received API response from 'create_user_defined_field': {0}".format(str(response)), "DEBUG")
Expand Down Expand Up @@ -986,6 +988,7 @@ def add_field_to_devices(self, device_ids, udf):
response = self.dnac._exec(
family="devices",
function='add_user_defined_field_to_device',
op_modifies=True,
params=udf_param_dict,
)
self.log("Received API response from 'add_user_defined_field_to_device': {0}".format(str(response)), "DEBUG")
Expand Down Expand Up @@ -1226,6 +1229,7 @@ def get_ap_devices(self, device_ips):
response = self.dnac._exec(
family="devices",
function='get_device_list',
op_modifies=True,
params={"managementIpAddress": device_ip}
)
response = response.get('response', [])
Expand Down Expand Up @@ -1360,6 +1364,7 @@ def reboot_access_points(self):
response = self.dnac._exec(
family="devices",
function='get_device_list',
op_modifies=True,
params={"managementIpAddress": device_ip}
)
response = response.get('response')
Expand Down Expand Up @@ -1905,6 +1910,7 @@ def get_udf_id(self, field_name):
response = self.dnac._exec(
family="devices",
function='get_all_user_defined_fields',
op_modifies=True,
params={"name": field_name},
)
self.log("Received API response from 'get_all_user_defined_fields': {0}".format(str(response)), "DEBUG")
Expand Down Expand Up @@ -2091,6 +2097,7 @@ def get_device_ids(self, device_ips):
response = self.dnac._exec(
family="devices",
function='get_device_list',
op_modifies=True,
params={"managementIpAddress": device_ip}
)

Expand Down Expand Up @@ -2127,6 +2134,7 @@ def get_device_ips_from_hostname(self, hostname_list):
response = self.dnac._exec(
family="devices",
function='get_device_list',
op_modifies=True,
params={"hostname": hostname}
)
if response:
Expand Down Expand Up @@ -2161,6 +2169,7 @@ def get_device_ips_from_serial_number(self, serial_number_list):
response = self.dnac._exec(
family="devices",
function='get_device_list',
op_modifies=True,
params={"serialNumber": serial_number}
)
if response:
Expand Down Expand Up @@ -2195,6 +2204,7 @@ def get_device_ips_from_mac_address(self, mac_address_list):
response = self.dnac._exec(
family="devices",
function='get_device_list',
op_modifies=True,
params={"macAddress": mac_address}
)
if response:
Expand Down Expand Up @@ -2233,6 +2243,7 @@ def get_interface_from_id_and_name(self, device_id, interface_name):
response = self.dnac._exec(
family="devices",
function='get_interface_details',
op_modifies=True,
params=interface_detail_params
)
self.log("Received API response from 'get_interface_details': {0}".format(str(response)), "DEBUG")
Expand Down Expand Up @@ -2270,6 +2281,7 @@ def get_interface_from_ip(self, device_ip):
response = self.dnac._exec(
family="devices",
function='get_interface_by_ip',
op_modifies=True,
params={"ip_address": device_ip}
)
self.log("Received API response from 'get_interface_by_ip': {0}".format(str(response)), "DEBUG")
Expand Down Expand Up @@ -2302,6 +2314,7 @@ def get_device_response(self, device_ip):
response = self.dnac._exec(
family="devices",
function='get_device_list',
op_modifies=True,
params={"managementIpAddress": device_ip}
)
response = response.get('response')[0]
Expand Down Expand Up @@ -2360,6 +2373,7 @@ def check_interface_details(self, device_ip, interface_name):
response = self.dnac._exec(
family="devices",
function='get_interface_details',
op_modifies=True,
params=interface_detail_params
)
self.log("Received API response from 'get_interface_details': {0}".format(str(response)), "DEBUG")
Expand Down Expand Up @@ -2737,6 +2751,7 @@ def is_device_exist_in_ccc(self, device_ip):
response = self.dnac._exec(
family="devices",
function='get_device_list',
op_modifies=True,
params={"managementIpAddress": device_ip}
)
response = response.get('response')
Expand Down Expand Up @@ -2982,6 +2997,7 @@ def get_diff_merged(self, config):
response = self.dnac._exec(
family="devices",
function='get_device_list',
op_modifies=True,
params={"managementIpAddress": device_ip}
)
response = response.get('response')[0]
Expand Down Expand Up @@ -3306,6 +3322,7 @@ def get_diff_deleted(self, config):
response = self.dnac._exec(
family="devices",
function='delete_user_defined_field',
op_modifies=True,
params={"id": udf_id},
)
if response and isinstance(response, dict):
Expand Down Expand Up @@ -3356,13 +3373,15 @@ def get_diff_deleted(self, config):
prov_respone = self.dnac._exec(
family="sda",
function='get_provisioned_wired_device',
op_modifies=True,
params=provision_params,
)

if prov_respone.get("status") == "success":
response = self.dnac._exec(
family="sda",
function='delete_provisioned_wired_device',
op_modifies=True,
params=provision_params,
)
executionid = response.get("executionId")
Expand All @@ -3389,6 +3408,7 @@ def get_diff_deleted(self, config):
response = self.dnac._exec(
family="devices",
function='delete_device_by_id',
op_modifies=True,
params=delete_params,
)

Expand Down
Loading

0 comments on commit 9ad4bd0

Please sign in to comment.