fix: Add image field to template_create, document type-specific params in description

This commit is contained in:
YueGuobin 2026-06-11 01:34:34 +08:00
parent 828a770489
commit c2aae9529b
No known key found for this signature in database
2 changed files with 17 additions and 4 deletions

View File

@ -569,11 +569,20 @@ async def template_create(
name: Annotated[str, Field(description="Template name")],
template_type: Annotated[str, Field(description="Template type (e.g. qemu, docker, dynamips)")],
compute_id: Annotated[str, Field(description="Compute ID (default: local)")] = "local",
image: Annotated[str | None, Field(description="Docker image name or Dynamips IOS image path (required for docker/dynamips)")] = None,
) -> list[dict[str, Any]]:
"""Create a new template."""
return await asyncio.to_thread(_run_handler_sync, create_template_handler, {
"name": name, "template_type": template_type, "compute_id": compute_id,
})
"""Create a new template.
Template-type-specific required parameters:
docker: image is required (e.g. "ubuntu:latest")
dynamips: image is required (path to .image file)
iou: needs 'path' (IOL image path) set via template_update after creation
qemu: needs 'hda_disk_image' or 'qemu_path' set via template_update after creation
"""
params = {"name": name, "template_type": template_type, "compute_id": compute_id}
if image:
params["image"] = image
return await asyncio.to_thread(_run_handler_sync, create_template_handler, params)
@mcp.tool()

View File

@ -83,6 +83,10 @@ def create_template_handler(params: dict[str, Any], gns3_ctx: dict[str, Any]) ->
"template_type": template_type,
"compute_id": params.get("compute_id", "local"),
}
# Pass through optional template-type-specific fields (image, qemu_path, etc.)
for key in ("image",):
if key in params:
data[key] = params[key]
return conn.http_call("post", f"{conn.base_url}/templates", json_data=data).json()