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
pvesh
command-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 100
Available commands:
status
start
shutdown
stop
reboot
suspend
destroy
snapshot
delsnapshot
listsnapshot
replications
replication-schedule-now
vzdump
ha
ha-set
ha-set-started-all
ha-set-ignored-all
./pmy.py
./pmx.py status 101 102
lxc/101 running 1h 23m
qemu/102 stopped
./pmx.py start 101 102 103
Starting VM 101...
Starting VM 102...
VM 103 is already running. Only 'stop' or 'shutdown' are allowed.
./pmx.py stop 101 102
Stopping VM 101...
VM 102 is already stopped. Only 'start' is allowed.
./pmx.py shutdown 101
./pmx.py destroy 101
You 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-jobs
to not purge from job configurations--do-not-destroy-unreferenced-disks
to not destroy unreferenced disks
./pmx.py snapshot --name snapshot-test --description "testing snapshots" 101
Arguments:
--name
Required. snapshot name--description
Optional
./pmx.py delsnapshot --name snapshot-test 101
Arguments:
--name
Required. snapshot name
./pmx.py delsnapshot --name snapshot-test 101
Arguments:
--name
Required. 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 node1
State can be one of:
started
: The CRM tries to start the resource. Service state is set tostarted
after 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 instopped
state, but it still tries to relocate the resources on node failures.disabled
: The CRM tries to put the resource instopped
state, 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 theerror
state.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 100
Useful when turning off all your proxmox nodes.
./pmx.py ha-set-started-all
./pmx.py ha-set-ignored-all
./pmx.py ha-delete 100
By 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 node1
This works with start
, shutdown
, stop
, and destroy
.
- If a VM/container is
stopped
, only thestart
command will be allowed. - If a VM/container is
running
, only thestop
orshutdown
commands will be allowed. - The script retrieves the node and type (
qemu
orlxc
) 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.