diff --git a/docs/gns3-copilot/implemented/node-control-tools.md b/docs/gns3-copilot/implemented/node-control-tools.md index 4937d4d2a..f1f411601 100644 --- a/docs/gns3-copilot/implemented/node-control-tools.md +++ b/docs/gns3-copilot/implemented/node-control-tools.md @@ -76,7 +76,7 @@ The following built-in utility templates are excluded as they are not actual net ### GNS3CreateNodeTool 🆕 -**Tool Name:** `create_gns3_node` +**Tool Name:** `node_create` **Description:** Creates multiple nodes in a GNS3 project using specified templates and coordinates. @@ -94,7 +94,8 @@ The following built-in utility templates are excluded as they are not actual net { "template_id": "uuid-of-template2", "x": -200, - "y": 300 + "y": 300, + "compute_id": "uuid-of-remote-compute" } ] } @@ -127,6 +128,7 @@ The following built-in utility templates are excluded as they are not actual net - Uses templates for consistent node configuration - X/Y coordinate positioning for topology layout - Optional `name` field to set node name directly (if omitted, GNS3 assigns default name) +- Optional `compute_id` field to place the node on a remote compute (if omitted, `local`) - **Important**: Ensure distance between any two nodes is greater than 250px for clear interface labels **Use Cases:** @@ -141,7 +143,7 @@ The following built-in utility templates are excluded as they are not actual net ### GNS3LinkTool 🆕 -**Tool Name:** `create_gns3_link` +**Tool Name:** `link_create` **Description:** Creates one or more links between nodes in a GNS3 project by connecting their network ports. @@ -155,6 +157,13 @@ The following built-in utility templates are excluded as they are not actual net "port1": "Ethernet0/0", "node_id2": "uuid-of-node2", "port2": "Ethernet0/0" + }, + { + "node_id1": "uuid-of-node2", + "port1": "Serial0/0/0", + "node_id2": "uuid-of-node3", + "port2": "Serial0/0/0", + "link_type": "serial" } ] } @@ -176,6 +185,7 @@ The following built-in utility templates are excluded as they are not actual net **Features:** - Batch create multiple links - Automatic port discovery by name +- Optional `link_type` field per link (`ethernet` default, or `serial`) - Error handling for individual link failures - Port names must match topology data diff --git a/gns3server/agent/gns3_copilot/tools_v2/gns3_create_drawing.py b/gns3server/agent/gns3_copilot/tools_v2/gns3_create_drawing.py index 7f3f688fe..f541bdc14 100644 --- a/gns3server/agent/gns3_copilot/tools_v2/gns3_create_drawing.py +++ b/gns3server/agent/gns3_copilot/tools_v2/gns3_create_drawing.py @@ -95,7 +95,7 @@ class GNS3CreateTextDrawingTool(_GNS3CreateDrawingToolBase): computed width/height/line_height, or an "error" key on failure. """ - name: str = "create_gns3_text_drawing" + name: str = "drawing_create_text" description: str = """ Adds a text label to the GNS3 project canvas. Input: JSON with project_id, x, y (top-left corner), text and optional @@ -123,7 +123,7 @@ class GNS3CreateRectangleDrawingTool(_GNS3CreateDrawingToolBase): A dictionary with the created drawing, or an "error" key on failure. """ - name: str = "create_gns3_rectangle_drawing" + name: str = "drawing_create_rectangle" description: str = """ Adds a rectangle to the GNS3 project canvas. Input: JSON with project_id, x, y, width, height and optional fill, @@ -150,7 +150,7 @@ class GNS3CreateEllipseDrawingTool(_GNS3CreateDrawingToolBase): A dictionary with the created drawing, or an "error" key on failure. """ - name: str = "create_gns3_ellipse_drawing" + name: str = "drawing_create_ellipse" description: str = """ Adds an ellipse or circle to the GNS3 project canvas. Input: JSON with project_id, x, y, width, height (bounding box) and diff --git a/gns3server/agent/gns3_copilot/tools_v2/gns3_create_link.py b/gns3server/agent/gns3_copilot/tools_v2/gns3_create_link.py index c70c559ba..640cb0860 100644 --- a/gns3server/agent/gns3_copilot/tools_v2/gns3_create_link.py +++ b/gns3server/agent/gns3_copilot/tools_v2/gns3_create_link.py @@ -57,7 +57,7 @@ class GNS3LinkTool(BaseTool): with error handling for individual link failures. """ - name: str = "create_gns3_link" + name: str = "link_create" description: str = """ Creates one or more links between nodes in a GNS3 project. @@ -68,6 +68,7 @@ class GNS3LinkTool(BaseTool): - `port1` (str): Port name of the first node (e.g., 'Ethernet0/0'). - `node_id2` (str): UUID of the second node. - `port2` (str): Port name of the second node (e.g., 'Ethernet0/0'). + - `link_type` (str, optional): Link type - "ethernet" (default) or "serial". Note: Port names must match those from `gns3_topology_reader` tool. Example Input: @@ -79,6 +80,13 @@ class GNS3LinkTool(BaseTool): "port1": "Ethernet0/0", "node_id2": "uuid-of-node2", "port2": "Ethernet0/0" + }, + { + "node_id1": "uuid-of-node2", + "port1": "Serial0/0/0", + "node_id2": "uuid-of-node3", + "port2": "Serial0/0/0", + "link_type": "serial" } ] } @@ -160,6 +168,7 @@ class GNS3LinkTool(BaseTool): port1 = link_data.get("port1") node_id2 = link_data.get("node_id2") port2 = link_data.get("port2") + link_type = link_data.get("link_type") # Validate link parameters if not all([node_id1, port1, node_id2, port2]): @@ -200,28 +209,29 @@ class GNS3LinkTool(BaseTool): created_links.append({"error": error_msg}) continue - # Create the link via the shared REST handler - link_resp = create_link_handler( - { - "project_id": project_id, - "nodes": [ - { - "node_id": node_id1, - "adapter_number": port1_info.get("adapter_number", 0), - "port_number": port1_info.get("port_number", 0), - "label": {"text": port1_info.get("short_name") or port1}, - }, - { - "node_id": node_id2, - "adapter_number": port2_info.get("adapter_number", 0), - "port_number": port2_info.get("port_number", 0), - "label": {"text": port2_info.get("short_name") or port2}, - }, - ], - "fields": ["link_id"], - }, - gns3_ctx, - ) + # Create the link via the shared REST handler. link_type + # is passed only when set — the server defaults to ethernet. + link_params: dict[str, Any] = { + "project_id": project_id, + "nodes": [ + { + "node_id": node_id1, + "adapter_number": port1_info.get("adapter_number", 0), + "port_number": port1_info.get("port_number", 0), + "label": {"text": port1_info.get("short_name") or port1}, + }, + { + "node_id": node_id2, + "adapter_number": port2_info.get("adapter_number", 0), + "port_number": port2_info.get("port_number", 0), + "label": {"text": port2_info.get("short_name") or port2}, + }, + ], + "fields": ["link_id"], + } + if link_type: + link_params["link_type"] = link_type + link_resp = create_link_handler(link_params, gns3_ctx) if isinstance(link_resp, list): raise RuntimeError("Unexpected batch response when creating a single link") if "error" in link_resp: diff --git a/gns3server/agent/gns3_copilot/tools_v2/gns3_create_node.py b/gns3server/agent/gns3_copilot/tools_v2/gns3_create_node.py index 60b2b0801..bd6081201 100644 --- a/gns3server/agent/gns3_copilot/tools_v2/gns3_create_node.py +++ b/gns3server/agent/gns3_copilot/tools_v2/gns3_create_node.py @@ -99,11 +99,12 @@ class GNS3CreateNodeTool(BaseTool): If error occurs during validation, returns dict with error message. """ - name: str = "create_gns3_node" + name: str = "node_create" description: str = """ Creates multiple nodes in a GNS3 project using templates and coordinates. Input is a JSON object with project_id and array of nodes. - Each node requires: template_id, x, y. Optional: name (to set node name directly). + Each node requires: template_id, x, y. Optional: name (to set node name directly), + compute_id (compute to place the node on, default "local"). Example input: { "project_id": "uuid-of-project", @@ -118,7 +119,8 @@ class GNS3CreateNodeTool(BaseTool): "template_id": "uuid-of-template2", "x": -200, "y": 300, - "name": "R2" + "name": "R2", + "compute_id": "uuid-of-remote-compute" } ] } @@ -176,6 +178,7 @@ class GNS3CreateNodeTool(BaseTool): x = node_data.get("x") y = node_data.get("y") name = node_data.get("name") + compute_id = node_data.get("compute_id") if not all( [ @@ -208,6 +211,7 @@ class GNS3CreateNodeTool(BaseTool): x = node_data.get("x") y = node_data.get("y") name = node_data.get("name") + compute_id = node_data.get("compute_id") logger.info( "Creating node %d/%d with template %s at (%s, %s), name=%s...", @@ -219,17 +223,19 @@ class GNS3CreateNodeTool(BaseTool): name, ) - # Create node via the shared REST handler - created = create_node_handler( - { - "project_id": project_id, - "template_id": template_id, - "x": x, - "y": y, - "name": name, - }, - gns3_ctx, - ) + # Create node via the shared REST handler. compute_id is + # passed only when set — the handler defaults to "local". + node_params: dict[str, Any] = { + "project_id": project_id, + "template_id": template_id, + "x": x, + "y": y, + } + if name: + node_params["name"] = name + if compute_id: + node_params["compute_id"] = compute_id + created = create_node_handler(node_params, gns3_ctx) if isinstance(created, list): raise RuntimeError("Unexpected batch response when creating a single node") if "error" in created: