QM and PCT commands globally?

flames

Renowned Member
Feb 8, 2018
136
26
68
CH
Hello,
there are many useful command linde tools, that we would like to use for automation in custom scripts, but all "qm" or "pct" commands for VMs and CTs are node dependent in a cluster and deliver a return only when the subject VM/CT is on the node, where the command is executed...
Are there some global commands, that would i.e. return the vm name or ct hostname from any node, even not the one, the command actually executed from?
Thanks in Advance
 
You can get all that via the API. Use the API Viewer to see all possible commands. Use pvesh to easily access the API.
You can get a list of VMs for a node called "pveA" using the following command
Code:
root@pveA:~# pvesh get nodes/pveA/qemu
With pvesh it is possible to replace "pveA" with the name of any other node (for example, pveB) in your cluster.
Code:
root@pveA:~# pvesh get nodes/pveB/qemu
It is often useful to use jq. For example, to get all the VM names that you wanted
Code:
root@pveA:~# apt install jq
root@pveA:~# pvesh get nodes/pveC/qemu --output-format=json | jq '.[].name'
"Copy-of-VM-pve6"
"Copy-of-VM-Copy-of-VM-pve6"
"pve"
To get container names
Code:
root@pveA:~# pvesh get nodes/pveA/lxc
and to get nodes in your cluster
Code:
root@pveA:~# pvesh get nodes
 
  • Like
Reactions: flames

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!