Proxmox MCP medium: P5 live migration tool
This commit is contained in:
@@ -322,6 +322,41 @@ def register(mcp: FastMCP) -> None:
|
|||||||
except (GuardError, ProxmoxAPIError) as exc:
|
except (GuardError, ProxmoxAPIError) as exc:
|
||||||
return json.dumps({"status": "error", "message": str(exc)}, indent=2)
|
return json.dumps({"status": "error", "message": str(exc)}, indent=2)
|
||||||
|
|
||||||
|
|
||||||
|
# ── Migration tools ──────────────────────────────────────────
|
||||||
|
|
||||||
|
@mcp.tool()
|
||||||
|
def proxmox_migrate_vm(
|
||||||
|
node: str,
|
||||||
|
vmid: int,
|
||||||
|
target_node: str,
|
||||||
|
online: bool = True,
|
||||||
|
target: str = "",
|
||||||
|
) -> str:
|
||||||
|
"""Migrate a VM or LXC container to another node.
|
||||||
|
|
||||||
|
For QEMU VMs: set online=True for live migration.
|
||||||
|
For LXC containers: migration is always offline.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
require_writes()
|
||||||
|
client = get_client(target=target)
|
||||||
|
try:
|
||||||
|
# Try QEMU first — supports live migration
|
||||||
|
data: dict = {"target": target_node}
|
||||||
|
if online:
|
||||||
|
data["online"] = 1
|
||||||
|
result = client.post(f"nodes/{node}/qemu/{vmid}/migrate", data=data)
|
||||||
|
except ProxmoxAPIError:
|
||||||
|
# Fall back to LXC — containers cannot be live-migrated
|
||||||
|
result = client.post(
|
||||||
|
f"nodes/{node}/lxc/{vmid}/migrate",
|
||||||
|
data={"target": target_node},
|
||||||
|
)
|
||||||
|
return json.dumps(result, indent=2, default=str)
|
||||||
|
except (GuardError, ProxmoxAPIError) as exc:
|
||||||
|
return json.dumps({"status": "error", "message": str(exc)}, indent=2)
|
||||||
|
|
||||||
# ── Snapshot tools ───────────────────────────────────────────
|
# ── Snapshot tools ───────────────────────────────────────────
|
||||||
|
|
||||||
@mcp.tool()
|
@mcp.tool()
|
||||||
|
|||||||
Reference in New Issue
Block a user