-
Notifications
You must be signed in to change notification settings - Fork 1
Fabric device info feature #162
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
Fabric device info feature #162
Conversation
| self.log("Retrieving fabric device onboarding information for lifecycle management and troubleshooting", "INFO") | ||
| self.log("Processing port channel details for {0} fabric devices across fabric sites".format(len(filtered_fabric_devices)), "DEBUG") | ||
|
|
||
| device_identifier = self.want["fabric_devices"][0].get("device_identifier") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.log(
"Port channel retrieval configuration - device_identifier specified: {0}".format(
bool(device_identifier)
),
"DEBUG"
)
all_port_channel_info_list = []
# Statistics tracking for port channel operations
statistics = {
'devices_processed': 0,
'devices_with_port_channels': 0,
'devices_without_port_channels': 0,
'devices_with_errors': 0,
'total_port_channels_retrieved': 0,
'total_api_calls': 0
}
self.log(
"Beginning port channel data collection across {0} fabric devices".format(
len(filtered_fabric_devices)
),
"INFO"
)
| devices_without_port_channels_data = 0 | ||
| devices_with_errors = 0 | ||
|
|
||
| for index, (ip, fabric_id) in enumerate(filtered_fabric_devices.items()): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.log(
"Processing outer loop for device {0}/{1} - "
"IP: {2}, Fabric ID: {3}".format(
index, len(filtered_fabric_devices), device_ip, fabric_id
),
"DEBUG"
)
| devices_with_errors = 0 | ||
|
|
||
| for index, (ip, fabric_id) in enumerate(filtered_fabric_devices.items()): | ||
| ip_device_uuid_map = self.get_device_ids_from_device_ips([ip]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if not ip_device_uuid_map or device_ip not in ip_device_uuid_map:
self.log(
"Failed to retrieve device UUID for IP {0} - skipping port channel retrieval".format(
device_ip
),
"WARNING"
)
statistics['devices_with_errors'] += 1
all_port_channel_info_list.append({
"device_ip": device_ip,
"port_channel_details": "Error: Unable to retrieve device UUID"
})
continue
# Inner loop processing each device IP and UUID mapping
for ip, device_uuid in ip_device_uuid_map.items():
| for index, (ip, fabric_id) in enumerate(filtered_fabric_devices.items()): | ||
| ip_device_uuid_map = self.get_device_ids_from_device_ips([ip]) | ||
| for ip, device_uuid in ip_device_uuid_map.items(): | ||
| devices_processed += 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
statistics['devices_processed'] += 1
self.log(
"Processing inner loop for device {0} - UUID: {1}".format(
ip, device_uuid
),
"DEBUG"
)
self.log(
"Initiating port channel data retrieval for fabric device {0}".format(ip),
"DEBUG"
)
| self.log( | ||
| "Added 'network_device_id' parameter for device {0}: {1}".format(ip, device_uuid), | ||
| "DEBUG" | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
statistics['total_api_calls'] += 1
| family="sda", | ||
| function="get_port_channels", | ||
| params=params | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Validate API response structure
if not response or not isinstance(response, dict):
self.log(
"Invalid API response structure for device {0} - "
"expected dict, got: {1}".format(
ip, type(response).__name__
),
"WARNING"
)
statistics['devices_with_errors'] += 1
all_port_channel_info_list.append({
"device_ip": ip,
"port_channel_details": "Error: Invalid API response structure"
})
continue
port_channel_data = response.get("response", [])
if not isinstance(port_channel_data, list):
self.log(
"Unexpected response data type for device {0} - "
"expected list, got: {1}".format(
ip, type(port_channel_data).__name__
),
"WARNING"
)
statistics['devices_with_errors'] += 1
all_port_channel_info_list.append({
"device_ip": ip,
"port_channel_details": "Error: Unexpected response data format"
})
continue
| ), | ||
| "DEBUG" | ||
| ) | ||
| if onboarding_data: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if port_channel_data:
statistics['devices_with_port_channels'] += 1
statistics['total_port_channels_retrieved'] += len(port_channel_data)
self.log(
"Port channel configuration found for fabric device {0} - "
"retrieved {1} port channel records".format(
ip, len(port_channel_data)
),
"INFO"
)
all_port_channel_info_list.append({
"device_ip": ip,
"port_channel_details": port_channel_data
})
for idx, port_channel in enumerate(port_channel_data, start=1):
port_channel_id = port_channel.get("id", "Unknown")
interface_name = port_channel.get("interfaceName", "Unknown")
self.log(
"Port channel {0}/{1} details for device {2} - "
"ID: {3}, Interface: {4}".format(
idx, len(port_channel_data), ip,
port_channel_id, interface_name
),
"DEBUG"
)
else:
statistics['devices_without_port_channels'] += 1
self.log(
"No port channel configuration found for fabric device {0} - "
"device may not have configured port channels".format(ip),
"DEBUG"
)
all_port_channel_info_list.append({
"device_ip": ip,
"port_channel_details": []
})
| all_onboarding_info_list.append({ | ||
| "device_ip": ip, | ||
| "port_channel_details": "Error: {0}".format(api_err) | ||
| }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
continue
| "port_channel_details": "Error: {0}".format(api_err) | ||
| }) | ||
|
|
||
| result = [{"port_channel_info": all_onboarding_info_list}] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
result = [{"port_channel_info": all_port_channel_info_list}]
self.log(
"Port channel configuration retrieval completed - "
"devices processed: {0}, with port channels: {1}, "
"without port channels: {2}, with errors: {3}".format(
statistics['devices_processed'],
statistics['devices_with_port_channels'],
statistics['devices_without_port_channels'],
statistics['devices_with_errors']
),
"INFO"
)
self.log(
"Port channel retrieval statistics - "
"total API calls: {0}, total port channels retrieved: {1}".format(
statistics['total_api_calls'],
statistics['total_port_channels_retrieved']
),
"INFO"
)
if statistics['devices_with_port_channels'] > 0:
self.log(
"Fabric devices with port channel configurations indicating "
"successful interface aggregation: {0}".format(
statistics['devices_with_port_channels']
),
"INFO"
)
if statistics['devices_without_port_channels'] > 0:
self.log(
"Fabric devices without port channel configurations: {0}".format(
statistics['devices_without_port_channels']
),
"INFO"
)
if statistics['devices_with_errors'] > 0:
self.log(
"Warning: {0} devices encountered errors during port channel "
"configuration retrieval - check individual device logs for details".format(
statistics['devices_with_errors']
),
"WARNING"
)
successful_devices = [
entry["device_ip"] for entry in all_port_channel_info_list
if isinstance(entry["port_channel_details"], list) and entry["port_channel_details"]
]
if successful_devices:
self.log(
"Successfully retrieved port channel configurations for devices: {0}".format(
successful_devices
),
"DEBUG"
)
self.log(
"Port channel configuration retrieval operation completed for {0} "
"fabric devices with {1} total device entries processed".format(
len(filtered_fabric_devices), len(all_port_channel_info_list)
),
"INFO"
)
self.log(
"Final aggregated port channel information result: {0}".format(result),
"DEBUG"
)
return result
57ce499
into
cisco-en-programmability:main
Type of Change
Description
The update includes fixes for 2 identified bugs in the fabric_devices_info module.
Bug Fix:
Root Cause (if applicable):
Fix Implemented: [Describe the fix applied]
Enhancement: [Brief description of the improvement/enhancement made]
Enhancement Description: [Explain what was enhanced, why, and how]
Impact Area: [Mention which part of the system/codebase is affected]
Testing Done:
Test cases covered: [Mention test case IDs or brief points]
Checklist
Ansible Best Practices
ansible-vaultor environment variables)Documentation
Screenshots (if applicable)
Notes to Reviewers