mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-08-27 12:30:13 +03:00
feat: Jinja2 template support in device_command_run
This commit is contained in:
parent
06e1511773
commit
8aa7f2bde5
@ -1320,9 +1320,14 @@ async def device_command_run(
|
||||
device_configs: Annotated[list, Field(
|
||||
description="List of device commands. Each entry: {\"device_name\": \"R1\", \"show_commands\": [\"show ip int brief\", \"show running-config\"]}"
|
||||
)],
|
||||
template: Annotated[str | None, Field(description="Optional Jinja2 template. Use with vars per device. Example: \"show ip route {{ protocol }}\"")] = None,
|
||||
) -> list[dict[str, Any]]:
|
||||
"""Run read-only diagnostic (show) commands on network devices via console.
|
||||
|
||||
Two modes:
|
||||
1. Direct commands: each device has show_commands=[...]
|
||||
2. Jinja2 template: provide template + vars per device
|
||||
|
||||
Use this to inspect device status, view configurations, or verify changes.
|
||||
Devices must be started first.
|
||||
"""
|
||||
|
||||
@ -97,9 +97,15 @@ def device_command_run_handler(params: dict[str, Any], gns3_ctx: dict[str, Any])
|
||||
"""Run read-only diagnostic (show) commands on network devices."""
|
||||
project_id = params.get("project_id")
|
||||
device_configs = params.get("device_configs")
|
||||
template = params.get("template")
|
||||
if not project_id or not device_configs:
|
||||
return [{"error": "project_id and device_configs (list of {device_name, show_commands}) are required"}]
|
||||
|
||||
if template:
|
||||
device_configs = _render_template(template, device_configs)
|
||||
if len(device_configs) == 1 and "error" in device_configs[0]:
|
||||
return device_configs
|
||||
|
||||
from gns3server.agent.gns3_copilot.tools_v2.display_tools_nornir import ExecuteMultipleDeviceCommands
|
||||
|
||||
tool = ExecuteMultipleDeviceCommands()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user