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

Ordered the device_config details before removing the devices from the fabric #444

Merged
merged 2 commits into from
Oct 24, 2024
Merged
Changes from all commits
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
66 changes: 65 additions & 1 deletion plugins/modules/sda_fabric_devices_workflow_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -4022,6 +4022,69 @@ def get_diff_merged(self, config):

return self

def prioritize_device_deletion(self, device_config):
"""
Prioritize the device config so that the device with the role 'CONTROL_PLANE_NODE'
is deleted last, and devices that don't exist are handled first.

Parameters:
device_config (list): Devices config details provided by the user in the playbook.
Returns:
updated_device_config (list): Reordered device config details.
Description:
For each device in the config, check whether it exists in the Cisco Catalyst Center.
If the device doesn't exist, prepend it to the list. If it has a role 'CONTROL_PLANE_NODE',
append it to ensure it is processed last. Update self.have['fabric_details'] with the new
order and return the updated config.
"""

fabric_device_index = -1
updated_device_config = []
update_have = []
MUTHU-RAKESH-27 marked this conversation as resolved.
Show resolved Hide resolved
self.log("Starting to reorder devices based on their existence and role.", "DEBUG")
self.log("Input device_config: {device_config}".format(device_config=device_config), "DEBUG")
for item in device_config:
fabric_device_index += 1
device_ip = item.get("device_ip")
MUTHU-RAKESH-27 marked this conversation as resolved.
Show resolved Hide resolved
self.log("Processing device with IP: {ip}".format(ip=device_ip))
have_device_details = self.have.get("fabric_devices")[fabric_device_index]
exists = have_device_details.get("exists")
if not exists:
self.log(
"The device with IP address '{ip}' is not available in the Cisco Catalyst Center."
.format(ip=device_ip)
)
updated_device_config = [item] + updated_device_config
MUTHU-RAKESH-27 marked this conversation as resolved.
Show resolved Hide resolved
update_have = [have_device_details] + update_have
continue

device_roles = have_device_details.get("device_details").get("deviceRoles")
if "CONTROL_PLANE_NODE" in device_roles:
MUTHU-RAKESH-27 marked this conversation as resolved.
Show resolved Hide resolved
self.log(
"Device with IP '{ip}' has role 'CONTROL_PLANE_NODE', appending to the end."
.format(ip=device_ip)
)
updated_device_config.append(item)
update_have.append(have_device_details)
continue

MUTHU-RAKESH-27 marked this conversation as resolved.
Show resolved Hide resolved
self.log(
"Device with IP '{ip}' role '{device_roles}', prepending."
.format(ip=device_ip, device_roles=device_roles)
)
updated_device_config.insert(0, item)
update_have.insert(0, have_device_details)

self.have.update({
"fabric_devices": update_have
})
self.log(
"Updated device_config for deletion: {updated_config}"
.format(updated_config=updated_device_config)
)

MUTHU-RAKESH-27 marked this conversation as resolved.
Show resolved Hide resolved
return updated_device_config

def delete_l2_handoff(self, have_l2_handoff, device_ip,
result_fabric_device_response,
result_fabric_device_msg):
Expand Down Expand Up @@ -4316,7 +4379,8 @@ def delete_fabric_devices(self, fabric_devices):
"Starting deletion of fabric devices under fabric '{fabric_name}'"
.format(fabric_name=fabric_name), "DEBUG"
)
for item in device_config:
updated_device_config = self.prioritize_device_deletion(device_config)
for item in updated_device_config:
fabric_device_index += 1
device_ip = item.get("device_ip")
self.response[0].get("response").get(fabric_name).update({
Expand Down
Loading