名称: proxmox-full
描述: 完整的 Proxmox VE 管理功能 - 创建/克隆/启动/停止虚拟机和 LXC 容器,管理快照、备份、存储和模板。当用户需要管理 Proxmox 基础设施、虚拟机或容器时使用。
元数据: {"clawdbot":{"emoji":"🖥️","homepage":"https://www.proxmox.com/","requires":{"bins":["curl","jq"],"env":["PVE_TOKEN"]},"primaryEnv":"PVE_TOKEN"}}
通过 REST API 实现对 Proxmox VE 虚拟化平台的全面控制。
export PVE_URL="https://192.168.1.10:8006"
export PVE_TOKEN="user@pam!tokenid=secret-uuid"
创建 API 令牌: 数据中心 → 权限 → API 令牌 → 添加(取消勾选“权限分离”)
AUTH="Authorization: PVEAPIToken=$PVE_TOKEN"
# 查看集群状态
curl -sk -H "$AUTH" "$PVE_URL/api2/json/cluster/status" | jq
# 列出所有节点
curl -sk -H "$AUTH" "$PVE_URL/api2/json/nodes" | jq '.data[] | {node, status, cpu: (.cpu*100|round), mem_pct: (.mem/.maxmem*100|round)}'
# 查看节点详情
curl -sk -H "$AUTH" "$PVE_URL/api2/json/nodes/{node}/status" | jq
# 列出节点上所有虚拟机
curl -sk -H "$AUTH" "$PVE_URL/api2/json/nodes/{node}/qemu" | jq '.data[] | {vmid, name, status}'
# 列出节点上所有 LXC 容器
curl -sk -H "$AUTH" "$PVE_URL/api2/json/nodes/{node}/lxc" | jq '.data[] | {vmid, name, status}'
# 集群范围查看(所有虚拟机 + LXC 容器)
curl -sk -H "$AUTH" "$PVE_URL/api2/json/cluster/resources?type=vm" | jq '.data[] | {node, type, vmid, name, status}'
# 启动
curl -sk -X POST -H "$AUTH" "$PVE_URL/api2/json/nodes/{node}/qemu/{vmid}/status/start"
# 停止(立即)
curl -sk -X POST -H "$AUTH" "$PVE_URL/api2/json/nodes/{node}/qemu/{vmid}/status/stop"
# 关机(优雅)
curl -sk -X POST -H "$AUTH" "$PVE_URL/api2/json/nodes/{node}/qemu/{vmid}/status/shutdown"
# 重启
curl -sk -X POST -H "$AUTH" "$PVE_URL/api2/json/nodes/{node}/qemu/{vmid}/status/reboot"
# 对于 LXC 容器:将 /qemu/ 替换为 /lxc/
# 获取下一个可用 VMID
NEWID=$(curl -sk -H "$AUTH" "$PVE_URL/api2/json/cluster/nextid" | jq -r '.data')
# 创建容器
curl -sk -X POST -H "$AUTH" "$PVE_URL/api2/json/nodes/{node}/lxc" \
-d "vmid=$NEWID" \
-d "hostname=my-container" \
-d "ostemplate=local:vztmpl/debian-12-standard_12.2-1_amd64.tar.zst" \
-d "storage=local-lvm" \
-d "rootfs=local-lvm:8" \
-d "memory=1024" \
-d "swap=512" \
-d "cores=2" \
-d "net0=name=eth0,bridge=vmbr0,ip=dhcp" \
-d "password=changeme123" \
-d "start=1"
LXC 参数说明:
| 参数 | 示例 | 描述 |
|-------|---------|-------------|
| vmid | 200 | 容器 ID |
| hostname | myct | 容器主机名 |
| ostemplate | local:vztmpl/debian-12-... | 模板路径 |
| storage | local-lvm | 根文件系统存储位置 |
| rootfs | local-lvm:8 | 根磁盘(8GB) |
| memory | 1024 | 内存(MB) |
| swap | 512 | 交换空间(MB) |
| cores | 2 | CPU 核心数 |
| net0 | name=eth0,bridge=vmbr0,ip=dhcp | 网络配置 |
| password | secret | root 密码 |
| ssh-public-keys | ssh-rsa ... | SSH 公钥(URL 编码) |
| unprivileged | 1 | 非特权容器 |
| start | 1 | 创建后立即启动 |
# 获取下一个 VMID
NEWID=$(curl -sk -H "$AUTH" "$PVE_URL/api2/json/cluster/nextid" | jq -r '.data')
# 创建虚拟机
curl -sk -X POST -H "$AUTH" "$PVE_URL/api2/json/nodes/{node}/qemu" \
-d "vmid=$NEWID" \
-d "name=my-vm" \
-d "memory=2048" \
-d "cores=2" \
-d "sockets=1" \
-d "cpu=host" \
-d "net0=virtio,bridge=vmbr0" \
-d "scsi0=local-lvm:32" \
-d "scsihw=virtio-scsi-pci" \
-d "ide2=local:iso/ubuntu-22.04.iso,media=cdrom" \
-d "boot=order=scsi0;ide2;net0" \
-d "ostype=l26"
虚拟机参数说明:
| 参数 | 示例 | 描述 |
|-------|---------|-------------|
| vmid | 100 | 虚拟机 ID |
| name | myvm | 虚拟机名称 |
| memory | 2048 | 内存(MB) |
| cores | 2 | 每个插槽的 CPU 核心数 |
| sockets | 1 | CPU 插槽数 |
| cpu | host | CPU 类型 |
| net0 | virtio,bridge=vmbr0 | 网络配置 |
| scsi0 | local-lvm:32 | 磁盘(32GB) |
| ide2 | local:iso/file.iso,media=cdrom | ISO 镜像 |
| ostype | l26(Linux), win11 | 操作系统类型 |
| boot | order=scsi0;ide2 | 启动顺序 |
# 克隆虚拟机
curl -sk -X POST -H "$AUTH" "$PVE_URL/api2/json/nodes/{node}/qemu/{vmid}/clone" \
-d "newid=201" \
-d "name=cloned-vm" \
-d "full=1" \
-d "storage=local-lvm"
# 克隆 LXC 容器
curl -sk -X POST -H "$AUTH" "$PVE_URL/api2/json/nodes/{node}/lxc/{vmid}/clone" \
-d "newid=202" \
-d "hostname=cloned-ct" \
-d "full=1" \
-d "storage=local-lvm"
克隆参数说明:
| 参数 | 描述 |
|-------|-------------|
| newid | 新 VMID |
| name/hostname | 新名称 |
| full | 1=完整克隆,0=链接克隆 |
| storage | 目标存储 |
| target | 目标节点(用于迁移) |
# 将虚拟机转换为模板
curl -sk -X POST -H "$AUTH" "$PVE_URL/api2/json/nodes/{node}/qemu/{vmid}/template"
# 将 LXC 容器转换为模板
curl -sk -X POST -H "$AUTH" "$PVE_URL/api2/json/nodes/{node}/lxc/{vmid}/template"
# 列出快照
curl -sk -H "$AUTH" "$PVE_URL/api2/json/nodes/{node}/qemu/{vmid}/snapshot" | jq '.data[] | {name, description}'
# 创建快照
curl -sk -X POST -H "$AUTH" "$PVE_URL/api2/json/nodes/{node}/qemu/{vmid}/snapshot" \
-d "snapname=before-update" \
-d "description=系统更新前快照"
# 回滚快照
curl -sk -X POST -H "$AUTH" "$PVE_URL/api2/json/nodes/{node}/qemu/{vmid}/snapshot/{snapname}/rollback"
# 删除快照
curl -sk -X DELETE -H "$AUTH" "$PVE_URL/api2/json/nodes/{node}/qemu/{vmid}/snapshot/{snapname}"
# 开始备份
curl -sk -X POST -H "$AUTH" "$PVE_URL/api2/json/nodes/{node}/vzdump" \
-d "vmid={vmid}" \
-d "storage=local" \
-d "mode=snapshot" \
-d "compress=zstd"
# 列出备份
curl -sk -H "$AUTH" "$PVE_URL/api2/json/nodes/{node}/storage/{storage}/content?content=backup" | jq
# 恢复备份
curl -sk -X POST -H "$AUTH" "$PVE_URL/api2/json/nodes/{node}/qemu" \
-d "vmid=300" \
-d "archive=local:backup/vzdump-qemu-100-2024_01_01-12_00_00.vma.zst" \
-d "storage=local-lvm"
# 列出存储
curl -sk -H "$AUTH" "$PVE_URL/api2/json/nodes/{node}/storage" | jq '.data[] | {storage, type, avail, used}'
# 列出可用模板
curl -sk -H "$AUTH" "$PVE_URL/api2/json/nodes/{node}/storage/local/content?content=vztmpl" | jq '.data[] | .volid'
# 列出 ISO 镜像
curl -sk -H "$AUTH" "$PVE_URL/api2/json/nodes/{node}/storage/local/content?content=iso" | jq '.data[] | .volid'
# 下载模板
curl -sk -X POST -H "$AUTH" "$PVE_URL/api2/json/nodes/{node}/aplinfo" \
-d "storage=local" \
-d "template=debian-12-standard_12.2-1_amd64.tar.zst"
# 最近任务
curl -sk -H "$AUTH" "$PVE_URL/api2/json/nodes/{node}/tasks?limit=10" | jq '.data[] | {upid, type, status}'
# 任务状态
curl -sk -H "$AUTH" "$PVE_URL/api2/json/nodes/{node}/tasks/{upid}/status" | jq
# 任务日志
curl -sk -H "$AUTH" "$PVE_URL/api2/json/nodes/{node}/tasks/{upid}/log" | jq -r '.data[].t'
# 删除虚拟机(必须先停止)
curl -sk -X DELETE -H "$AUTH" "$PVE_URL/api2/json/nodes/{node}/qemu/{vmid}"
# 删除 LXC 容器
curl -sk -X DELETE -H "$AUTH" "$PVE_URL/api2/json/nodes/{node}/lxc/{vmid}"
# 强制删除(清理)
curl -sk -X DELETE -H "$AUTH" "$PVE_URL/api2/json/nodes/{node}/qemu/{vmid}?purge=1&destroy-unreferenced-disks=1"
| 操作 | 端点 | 方法 |
|---|---|---|
| 列出节点 | /nodes | GET |
| 列出虚拟机 | /nodes/{node}/qemu | GET |
| 列出 LXC | /nodes/{node}/lxc | GET |
| 创建虚拟机 | /nodes/{node}/qemu | POST |
| 创建 LXC | /nodes/{node}/lxc | POST |
| 克隆 | /nodes/{node}/qemu/{vmid}/clone | POST |
| 启动 | /nodes/{node}/qemu/{vmid}/status/start | POST |
| 停止 | /nodes/{node}/qemu/{vmid}/status/stop | POST |
| 创建快照 | /nodes/{node}/qemu/{vmid}/snapshot | POST |
| 删除 | /nodes/{node}/qemu/{vmid} | DELETE |
| 获取下一个 ID | /cluster/nextid | GET |
-k 参数跳过自签名证书验证{node} 替换为节点名称(例如 pve){vmid} 替换为虚拟机/容器 IDqemu,容器使用 lxc