From cf6104553d4eb032e109876151f54be9f7e30330 Mon Sep 17 00:00:00 2001 From: Syed-khadeerahmed Date: Mon, 16 Dec 2024 11:28:54 +0530 Subject: [PATCH 1/2] swim bug fixed --- plugins/modules/swim_workflow_manager.py | 88 ++++++++++++------------ 1 file changed, 43 insertions(+), 45 deletions(-) diff --git a/plugins/modules/swim_workflow_manager.py b/plugins/modules/swim_workflow_manager.py index 1b85b8039..44ce6905a 100644 --- a/plugins/modules/swim_workflow_manager.py +++ b/plugins/modules/swim_workflow_manager.py @@ -937,62 +937,60 @@ def get_device_uuids(self, site_name, device_family, device_role, device_series_ for item_dict in item['response']: site_response_list.append(item_dict) else: - try: - response = self.dnac._exec( - family="site_design", - function='get_site_assigned_network_devices', - op_modifies=True, - params={"site_id": site_id}, - ) - self.log("Received API response from 'get_site_assigned_network_devices': {0}".format(str(response)), "DEBUG") - response = response.get('response') + site_names = site_name + ".*" + get_site_names = self.get_site(site_names) + self.log(get_site_names) + site_info = {} + + for item in get_site_names['response']: + if 'nameHierarchy' in item and 'id' in item: + site_info[item['nameHierarchy']] = item['id'] + + for site_name, site_id in site_info.items(): + try: + response = self.dnac._exec( + family="site_design", + function='get_site_assigned_network_devices', + op_modifies=True, + params={"site_id": site_id}, + ) + self.log("Received API response from 'get_site_assigned_network_devices': {0}".format(str(response)), "DEBUG") + response = response.get('response') - if not response: - self.log("No devices found for site '{0}'.". format(site_name), "WARNING") + if not response: + self.log("No devices found for site - '{0}'.". format(site_name), "WARNING") - except Exception as e: - self.log("Unable to fetch the device(s) associated to the site '{0}' due to '{1}'".format(site_name, str(e)), "WARNING") - return device_uuid_list + for device_id in response: + device_id_list.append(device_id.get("deviceId")) - for device_id in response: - device_id_list.append(device_id.get("deviceId")) + except Exception as e: + self.log("Unable to fetch the device(s) associated to the site '{0}' due to '{1}'".format(site_name, str(e)), "WARNING") + return device_uuid_list - try: - device_params = {} - offset = 0 - limit = self.get_device_details_limit() - initial_exec = False + for device_id in device_id_list: + self.log("Processing device_id: {0}".format(device_id)) + try: + device_list_response = self.dnac._exec( + family="devices", + function="get_device_list", + params={"id": device_id}, + ) - while True: - if initial_exec: - device_params["limit"] = limit - device_params["offset"] = offset * limit - device_list_response = self.dnac._exec( - family="devices", - function='get_device_list', - params=device_params - ) - else: - initial_exec = True - device_list_response = self.dnac._exec( - family="devices", - function='get_device_list', - op_modifies=True - ) - offset = offset + 1 - self.log("Received API response from 'device_list_response': {0}".format(str(device_list_response)), "DEBUG") - device_response = device_list_response.get('response') + self.log("Received API response: {0}".format(str(device_list_response)), "DEBUG") + + device_response = device_list_response.get("response") if not device_response: - break + self.log("No device data found for device_id: {0}".format(device_id), "INFO") + continue for device in device_response: if device.get("instanceUuid") in device_id_list: if device_family is None or device.get("family") == device_family: site_response_list.append(device) - except Exception as e: - self.log("Unable to fetch the device(s) associated to the site '{0}' due to '{1}'".format(site_name, str(e)), "WARNING") - return device_uuid_list + except Exception as e: + self.log("Unable to fetch devices for site '{0}' due to: {1}".format(site_name, str(e)), "WARNING") + return device_uuid_list self.device_ips = [] for item in site_response_list: @@ -1034,7 +1032,7 @@ def get_device_uuids(self, site_name, device_family, device_role, device_series_ offset = offset + 1 device_response = device_list_response.get('response') - if not response or not device_response: + if not device_response: self.log("Failed to retrieve devices associated with the site '{0}' due to empty API response.".format(site_name), "INFO") break From d33c515c9d9a150e12148d2ec840a2c9bb04c38d Mon Sep 17 00:00:00 2001 From: Syed-khadeerahmed Date: Tue, 17 Dec 2024 12:36:09 +0530 Subject: [PATCH 2/2] review comments fixed --- plugins/modules/swim_workflow_manager.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/plugins/modules/swim_workflow_manager.py b/plugins/modules/swim_workflow_manager.py index 44ce6905a..df7ddc067 100644 --- a/plugins/modules/swim_workflow_manager.py +++ b/plugins/modules/swim_workflow_manager.py @@ -939,7 +939,8 @@ def get_device_uuids(self, site_name, device_family, device_role, device_series_ else: site_names = site_name + ".*" get_site_names = self.get_site(site_names) - self.log(get_site_names) + self.log("Fetched site names: {0}".format(str(get_site_names)), "DEBUG") + site_info = {} for item in get_site_names['response']: @@ -951,16 +952,15 @@ def get_device_uuids(self, site_name, device_family, device_role, device_series_ response = self.dnac._exec( family="site_design", function='get_site_assigned_network_devices', - op_modifies=True, params={"site_id": site_id}, ) self.log("Received API response from 'get_site_assigned_network_devices': {0}".format(str(response)), "DEBUG") - response = response.get('response') - - if not response: + devices = response.get('response') + if not devices: self.log("No devices found for site - '{0}'.". format(site_name), "WARNING") + continue - for device_id in response: + for device_id in devices: device_id_list.append(device_id.get("deviceId")) except Exception as e: @@ -976,7 +976,7 @@ def get_device_uuids(self, site_name, device_family, device_role, device_series_ params={"id": device_id}, ) - self.log("Received API response: {0}".format(str(device_list_response)), "DEBUG") + self.log("Received API response from 'get_device_list': {0}".format(str(device_list_response)), "DEBUG") device_response = device_list_response.get("response") if not device_response: