Skip to content

Commit

Permalink
Merge pull request #444 from MUTHU-RAKESH-27/main
Browse files Browse the repository at this point in the history
Ordered the device_config details before removing the devices from the fabric
  • Loading branch information
madhansansel authored Oct 24, 2024
2 parents ab052ef + 63c23d0 commit e5b3214
Showing 1 changed file with 65 additions and 1 deletion.
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 = []
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")
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
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:
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

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)
)

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

0 comments on commit e5b3214

Please sign in to comment.