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

swim bug fixed - image activation for all the child sites devices - V2.3.7.6 #67

Merged
Changes from 1 commit
Commits
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
88 changes: 43 additions & 45 deletions plugins/modules/swim_workflow_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.log("Fetched site names: {0}".format(str(get_site_names)), "DEBUG")

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed the code

site_info = {}

for item in get_site_names['response']:
if 'nameHierarchy' in item and 'id' in item:
site_info[item['nameHierarchy']] = item['id']

madhansansel marked this conversation as resolved.
Show resolved Hide resolved
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,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True or False?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed the code

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have removed the op_modifies as it is not required for get

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')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead:

        devices = response.get('response')
        if not devices:
            self.log("No devices found for site - '{0}'.".format(site_name), "WARNING")
            continue

Copy link
Collaborator Author

@syed-khadeerahmed syed-khadeerahmed Dec 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed the code


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:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    for device in devices:
        device_id_list.append(device.get("deviceId"))

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed the code

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")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    self.log("Received API response from 'get_device_list': {0}".format(str(device_list_response)), "DEBUG")

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed the code


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:
Expand Down Expand Up @@ -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

Expand Down
Loading