This script helps to start/stop/shutdown vms/lxc containers on multiple nodes without accessing the nodes.
This script was created with the help of ChatGPT, and even this README.md was written by ChatGPT. I'm not a Python expert, but the script should be helpful for anyone who wants a quick way to manage VMs or containers on a Proxmox environment.
- Start, stop, or shut down Proxmox VMs and containers by ID.
- Fetch the status of VMs/containers.
- Supports both synchronous and asynchronous execution.
- A Proxmox environment with
pveshcommand-line tool. - Python 3.x installed.
-
Download the script to your Proxmox machine:
curl -O https://raw.githubusercontent.com/aizatto/pmx/main/pmx.py cd proxmox-manager -
Make the script executable:
chmod +x pmx.py
The script takes a followed by one or more VM/Container IDs.
Example:
./pmx.py status 100Available commands:
statusstartshutdownstoprebootsuspenddestroysnapshotdelsnapshotlistsnapshotreplicationsreplication-schedule-nowvzdumphaha-setha-set-started-allha-set-ignored-all
./pmy.py./pmx.py status 101 102lxc/101 running 1h 23m
qemu/102 stopped./pmx.py start 101 102 103Starting VM 101...
Starting VM 102...
VM 103 is already running. Only 'stop' or 'shutdown' are allowed.
./pmx.py stop 101 102Stopping VM 101...
VM 102 is already stopped. Only 'start' is allowed.
./pmx.py shutdown 101./pmx.py destroy 101You will be asked to confirm if you want to destroy vm. You can skip confirmation by passing --skip-confirm.
By default, jobs will be purged, and unreferenced disks destroyed. You can use the arguments:
--do-not-purge-jobsto not purge from job configurations--do-not-destroy-unreferenced-disksto not destroy unreferenced disks
./pmx.py snapshot --name snapshot-test --description "testing snapshots" 101Arguments:
--nameRequired. snapshot name--descriptionOptional
./pmx.py delsnapshot --name snapshot-test 101Arguments:
--nameRequired. snapshot name
./pmx.py delsnapshot --name snapshot-test 101Arguments:
--nameRequired. snapshot name
./pmx.py replications
./pmx.py replications 101 102
./pmx.py --node replications node1./pmx.py replication-schedule-now 101./pmx.py ha
./pmx.py ha 100 101
./pmx.py --node ha node1State can be one of:
started: The CRM tries to start the resource. Service state is set tostartedafter successful start. On node failures, or when start fails, it tries to recover the resource. If everything fails, service state it set toerror.stopped: The CRM tries to keep the resource instoppedstate, but it still tries to relocate the resources on node failures.disabled: The CRM tries to put the resource instoppedstate, but does not try to relocate the resources on node failures. The main purpose of this state is error recovery, because it is the only way to move a resource out of theerrorstate.ignored: The resource gets removed from the manager status and so the CRM and the LRM do not touch the resource anymore. All {pve} API calls affecting this resource will be executed, directly bypassing the HA stack. CRM commands will be thrown away while there source is in this state. The resource will not get relocated on node failures.
./pmx.py --ha-state started ha-set 100 101
./pmx.py --ha-state ignored ha-set node1./pmx.py ha-delete 100Useful when turning off all your proxmox nodes.
./pmx.py ha-set-started-all
./pmx.py ha-set-ignored-all./pmx.py ha-delete 100By default, commands are executed asynchronously. To run them synchronously, pass the --sync argument:
./pmx.py --sync start 101 You can pass a --node argument if you want the selector to select pods based on a node.
For example, assuming the environment looks like:
- node1
- lxc/100
- lxc/101
- node2
- lxc/103
You can return the status of all vms on the Node via
./pmx.py --node status node1This works with start, shutdown, stop, and destroy.
- If a VM/container is
stopped, only thestartcommand will be allowed. - If a VM/container is
running, only thestoporshutdowncommands will be allowed. - The script retrieves the node and type (
qemuorlxc) automatically from the Proxmox cluster.
The script supports graceful handling of Ctrl+C, so you can stop execution safely.
Feel free to contribute! Fork the repository and submit a pull request if you'd like to improve or fix anything.
This project is licensed under the MIT License.