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 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
52 changes: 51 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,55 @@ def get_diff_merged(self, config):

return self

def arrange_config_for_deletion(self, device_config):
MUTHU-RAKESH-27 marked this conversation as resolved.
Show resolved Hide resolved
"""
Arrange the device config in such a way that the device with the role 'CONTROL_PLANE_NODE'
MUTHU-RAKESH-27 marked this conversation as resolved.
Show resolved Hide resolved
will be deleted at last.

Parameters:
device_config (list): Devices config details provided by the user in the playbook.
Returns:
updated_device_config (list): Updated device config details.
MUTHU-RAKESH-27 marked this conversation as resolved.
Show resolved Hide resolved
Description:
Loop in the device config information. If the device doesnot exists, prepend the
MUTHU-RAKESH-27 marked this conversation as resolved.
Show resolved Hide resolved
config details and the information collected from the Cisco Catalyst Center to the
new list or if the device has a role of 'CONTROL_PLANE_NODE', append the config details
and the information collected from the Cisco Catalyst Center to the new list.
Update the self.have.get("fabric_details") and return the new device_config list.
"""

fabric_device_index = -1
updated_device_config = []
update_have = []
MUTHU-RAKESH-27 marked this conversation as resolved.
Show resolved Hide resolved
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
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
updated_device_config.append(item)
update_have.append(have_device_details)
continue

MUTHU-RAKESH-27 marked this conversation as resolved.
Show resolved Hide resolved
updated_device_config = [item] + updated_device_config
update_have = [have_device_details] + update_have

self.have.update({
"fabric_devices": update_have
})

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 +4365,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.arrange_config_for_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