fix: reject non-VPCS nodes in the VPCS config tool

VPCS syntax typed into another node's console is silently discarded
(IOS answers % Invalid input) while the tool still reports success.
get_device_ports_from_topology now carries the GNS3 node type through
to callers, and VPCSCommands fails device preparation with a per-device
error unless the node type is vpcs.
This commit is contained in:
YueGuobin committed 2026-08-26 00:36:47 +08:00
1 parent 8a8314ab29
commit 2951af6eab
4 files changed
+93

No files matched your search

@@ -461,6 +461,25 @@ class VPCSCommands(BaseTool):
port = device_ports[device_name]["port"]
node_type = device_ports[device_name].get("node_type")
if node_type != "vpcs":
# VPCS syntax typed into another node's CLI is silently
# discarded (e.g. IOS answers "% Invalid input"), so reject
# mismatched devices before a console session is opened
logger.error(
"Device '%s' is a %s node, not a VPCS node",
device_name,
node_type or "unknown-type",
)
hosts_data[device_name] = {
"error": (
f"Device '{device_name}' is a {node_type or 'unknown-type'} node, "
"not a VPCS node; use device_config_send / device_show_run "
"for network devices"
)
}
continue
# VPCS devices use gns3_vpcs_telnet device type
hosts_data[device_name] = {
"port": port,
@@ -59,6 +59,7 @@ def get_device_ports_from_topology(
"device_name": {
"port": console_port,
"platform": "huawei", # Extracted from tags
"node_type": "vpcs", # GNS3 node type from the topology
"groups": ["network_devices"], # For inheriting shared settings
"connection_options": {
"netmiko": {
@@ -160,9 +161,14 @@ def get_device_ports_from_topology(
# This is the Nornir best practice - each host has its own
# connection configuration (device_type), while sharing common
# settings (hostname, timeout) via group inheritance.
# node_type (the GNS3 node type, e.g. vpcs/iou/docker) lets callers
# reject mismatched devices before opening a console connection;
# DictInventory ignores keys it does not know, so carrying it here
# is safe for entries fed straight into Nornir.
host_entry = {
"port": node_info["console_port"],
"platform": platform,
"node_type": node_info.get("type"),
"groups": ["network_devices"], # For inheriting hostname, timeout, etc.
"connection_options": {
"netmiko": {
+3
View File
@@ -1517,6 +1517,9 @@ async def vpcs_config_set(
) -> list[dict[str, Any]]:
"""Configure VPCS devices (set IP addresses, gateway, etc.).
Only VPCS nodes are accepted: any other node type in device_configs fails
with a per-device error instead of typing VPCS syntax into its CLI.
VPCS-specific configuration commands:
- ip <address>/<mask> <gateway> Set IP and gateway
- save Save config to startup.vpc