mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-04 22:41:12 +02:00
efactor(copilot): adopt Nornir best
practice for multi-vendor device support
Refactor Nornir configuration to use host-level connection_options
instead of dynamic groups, following Nornir's configuration priority
model (host > group > defaults).
**Problem:**
Previous implementation used first device's configuration for all
devices, causing Cisco devices to use Huawei driver and vice versa.
**Solution:**
- Each host now has device-specific connection_options at host level
- Single generic "network_devices" group for shared settings
- Host-level config automatically overrides group-level config
**Changes:**
- Remove: _get_nornir_groups_config() helper function
- Remove: _get_nornir_group() helper function
- Simplify: _initialize_nornir() to use single generic group
- Update: get_gns3_device_port.py() to return host-level config
- Reserve: platform field for future NAPALM/scrapli plugin support
**Benefits:**
- Cleaner code structure (no dynamic group creation)
- Follows Nornir best practice ("configuration proximity")
- Easy to extend with new device types
- Properly handles mixed-vendor topologies
This commit is contained in:
1 parent
44f802ae4f
commit
364ff93783
4 files changed
+320
-219
No files matched your search
@@ -49,9 +49,13 @@ def get_device_ports_from_topology(
|
||||
{
|
||||
"device_name": {
|
||||
"port": console_port,
|
||||
"groups": ["platform_telnet"], # Dynamically generated from platform/device_type
|
||||
"device_type": "huawei_telnet", # Extracted from tags
|
||||
"platform": "huawei" # Extracted from tags
|
||||
"platform": "huawei", # Extracted from tags
|
||||
"groups": ["network_devices"], # For inheriting shared settings
|
||||
"connection_options": {
|
||||
"netmiko": {
|
||||
"extras": {"device_type": "huawei_telnet"} # Extracted from tags
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Devices that don't exist or missing console_port will not be included
|
||||
@@ -128,18 +132,19 @@ def get_device_ports_from_topology(
|
||||
platform,
|
||||
)
|
||||
|
||||
# Add device to hosts_data
|
||||
# Dynamically generate group name based on platform and device_type
|
||||
if device_type and "_telnet" in device_type:
|
||||
group_name = f"{platform}_telnet"
|
||||
else:
|
||||
group_name = platform
|
||||
|
||||
# Add device to hosts_data with connection_options at host level
|
||||
# This is the Nornir best practice - each host has its own
|
||||
# connection configuration (device_type), while sharing common
|
||||
# settings (hostname, timeout) via group inheritance.
|
||||
hosts_data[device_name] = {
|
||||
"port": node_info["console_port"],
|
||||
"groups": [group_name],
|
||||
"device_type": device_type,
|
||||
"platform": platform,
|
||||
"groups": ["network_devices"], # For inheriting hostname, timeout, etc.
|
||||
"connection_options": {
|
||||
"netmiko": {
|
||||
"extras": {"device_type": device_type}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
logger.info("Returning %d device port mappings", len(hosts_data))
|
||||
|
||||
Reference in new issue
Block a user