Proxmox VE
Use the local Proxmox CLI first. Prefer read-only inspection before any mutating action, and confirm before stopping guests, rolling back snapshots, or changing configuration.
Safe workflow
- 1. Verify the environment and auth context.
- Discover nodes and guests with read-only commands.
- Check current state before proposing an action.
- Perform the smallest requested mutation.
- Re-check status and report what changed.
Start with lightweight inspection:
CODEBLOCK0
If the user did not specify a node, discover it first instead of guessing.
Read-first inspection
List nodes:
CODEBLOCK1
List QEMU VMs on a node:
CODEBLOCK2
List LXC containers on a node:
CODEBLOCK3
Inspect a specific VM or container:
CODEBLOCK4
If the user only gives a VMID and not the guest type, identify it first instead of guessing:
CODEBLOCK5
Useful cluster and node checks:
CODEBLOCK6
Prefer JSON when the output will be parsed or compared:
CODEBLOCK7
Guest lifecycle actions
Check state first, then act.
Recommended sequence:
- 1. Identify the node and guest type.
- Check current guest status.
- Confirm the exact action if it is disruptive.
- Run the smallest matching command.
- Re-check status and report the result.
QEMU VM actions:
CODEBLOCK8
LXC container actions:
CODEBLOCK9
Guidance:
- - Prefer
shutdown/reboot for graceful operations. - Use
stop only when the user explicitly wants a forced stop or graceful shutdown is not working. - Mention whether the target is a QEMU VM (
qm) or LXC container (pct) before running the command.
Snapshot workflow
Inspect snapshots before creating, deleting, or rolling back.
QEMU snapshots:
CODEBLOCK10
LXC snapshots:
CODEBLOCK11
Rules:
- - Confirm before
rollback or delsnapshot. - Use clear, generic snapshot names in examples such as
pre-update or before-maintenance. - Report post-action status after snapshot operations.
API-style access with pvesh
Use pvesh when the user asks for API-like inspection or when you need structured output without hand-building HTTP requests.
Examples:
CODEBLOCK12
Use pvesh usage <path> to discover parameters for less common endpoints:
CODEBLOCK13
Read references/commands-and-auth.md when the task needs API token guidance, remote API examples, or a broader command map.
Bundled scripts
Use the bundled Python helpers when the user wants reusable code or a minimal scriptable PVE API client.
Scripts:
- -
scripts/pve_api.py — generic GET/POST helper for API paths - INLINECODE14 — list nodes
- INLINECODE15 — list guests on a node
- INLINECODE16 — fetch current status
Expected environment variables:
CODEBLOCK14
Example usage:
CODEBLOCK15
Auth and environment guidance
On a Proxmox host, local CLI access is often enough:
CODEBLOCK16
For remote API usage, prefer environment variables over hardcoding secrets:
CODEBLOCK17
Do not print or paste real secrets back into chat. If credentials are missing, ask for them or ask the user to authenticate locally.
Guardrails
- - Do not assume VMID ownership or guest purpose from the numeric ID alone.
- Do not reboot, stop, reset, roll back, or delete without explicit user intent.
- Prefer node and guest discovery commands before suggesting actions.
- After any mutation, run a status check and summarize the result.
- If the task expands into storage, networking, clustering changes, or backup jobs, inspect first and ask before editing.
Proxmox VE
优先使用本地 Proxmox CLI。在执行任何修改操作前,优先进行只读检查,并在停止虚拟机、回滚快照或更改配置前进行确认。
安全工作流程
- 1. 验证环境和认证上下文。
- 使用只读命令发现节点和虚拟机。
- 在提出操作前检查当前状态。
- 执行最小请求的修改操作。
- 重新检查状态并报告变更内容。
从轻量级检查开始:
bash
pveversion
hostname
pvesh get /version
pvesh get /nodes
pvesh get /cluster/status
如果用户未指定节点,先发现节点而非猜测。
只读优先检查
列出节点:
bash
pvesh get /nodes
列出节点上的 QEMU 虚拟机:
bash
pvesh get /nodes//qemu
qm list
列出节点上的 LXC 容器:
bash
pvesh get /nodes//lxc
pct list
检查特定虚拟机或容器:
bash
qm status
qm config
pct status
pct config
如果用户仅提供 VMID 而未指定虚拟机类型,先识别而非猜测:
bash
qm list
pct list
pvesh get /cluster/resources --type vm
有用的集群和节点检查:
bash
pvesh get /cluster/resources
pvesh get /nodes//status
pvesh get /nodes//tasks --limit 10
当输出需要解析或比较时,优先使用 JSON 格式:
bash
pvesh get /nodes --output-format json
pvesh get /nodes//qemu --output-format json
虚拟机生命周期操作
先检查状态,再执行操作。
推荐顺序:
- 1. 识别节点和虚拟机类型。
- 检查当前虚拟机状态。
- 如果操作具有破坏性,确认具体操作。
- 运行最小的匹配命令。
- 重新检查状态并报告结果。
QEMU 虚拟机操作:
bash
qm start
qm stop
qm shutdown
qm reboot
qm reset
LXC 容器操作:
bash
pct start
pct stop
pct shutdown
pct reboot
指导原则:
- - 优先使用 shutdown/reboot 进行优雅操作。
- 仅在用户明确要求强制停止或优雅关机无效时使用 stop。
- 在运行命令前说明目标是 QEMU 虚拟机(qm)还是 LXC 容器(pct)。
快照工作流程
在创建、删除或回滚快照前进行检查。
QEMU 快照:
bash
qm listsnapshot
qm snapshot
qm delsnapshot
qm rollback
LXC 快照:
bash
pct listsnapshot
pct snapshot
pct delsnapshot
pct rollback
规则:
- - 在 rollback 或 delsnapshot 前进行确认。
- 在示例中使用清晰、通用的快照名称,如 pre-update 或 before-maintenance。
- 快照操作后报告操作后状态。
使用 pvesh 的 API 风格访问
当用户要求进行 API 风格的检查,或需要结构化输出而不手动构建 HTTP 请求时,使用 pvesh。
示例:
bash
pvesh get /cluster/resources
pvesh get /nodes//qemu//status/current
pvesh get /nodes//lxc//status/current
使用 pvesh usage 发现不常用端点的参数:
bash
pvesh usage /nodes//qemu//status/current -v
当任务需要 API 令牌指南、远程 API 示例或更广泛的命令映射时,阅读 references/commands-and-auth.md。
捆绑脚本
当用户需要可重用代码或最小化的可脚本化 PVE API 客户端时,使用捆绑的 Python 辅助工具。
脚本:
- - scripts/pveapi.py — 用于 API 路径的通用 GET/POST 辅助工具
- scripts/listnodes.py — 列出节点
- scripts/listguests.py [--kind qemu|lxc|all] — 列出节点上的虚拟机
- scripts/gueststatus.py — 获取当前状态
预期的环境变量:
bash
export PVE_HOST=proxmox.example.com
export PVE_USER=automation@pam
export PVETOKENID=automation
export PVETOKENSECRET=replace-me
使用示例:
bash
python3 {baseDir}/scripts/list_nodes.py
python3 {baseDir}/scripts/list_guests.py pve-node-1 --kind all
python3 {baseDir}/scripts/guest_status.py pve-node-1 qemu 100
python3 {baseDir}/scripts/pve_api.py /cluster/resources
认证和环境指南
在 Proxmox 主机上,本地 CLI 访问通常足够:
bash
whoami
pveversion
pvesh get /version
对于远程 API 使用,优先使用环境变量而非硬编码密钥:
bash
export PVE_HOST=proxmox.example.com
export PVE_USER=automation@pam
export PVE_REALM=pam
export PVETOKENID=automation
export PVETOKENSECRET=replace-me
不要在聊天中打印或粘贴真实密钥。如果缺少凭据,请询问用户或要求用户在本地进行身份验证。
安全护栏
- - 不要仅凭数字 ID 假设 VMID 所有权或虚拟机用途。
- 未经用户明确意图,不要重启、停止、重置、回滚或删除。
- 在建议操作前,优先进行节点和虚拟机发现命令。
- 在任何修改操作后,运行状态检查并总结结果。
- 如果任务涉及存储、网络、集群更改或备份作业,先检查并在编辑前询问。