Simplest way to destroy a VM from CLI in a cluster with HA ?

YAGA

Renowned Member
Feb 15, 2016
76
8
73
58
Hello,

In a cluster with HA, a VM that was created on a node may have changed nodes.

What is the simplest way to destroy a VM by its VMID from CLI when you do not know on which node it was automatically migrated by HA?

I haven't found anything simple with just one command line

Regards,
YAGA
 
You won't be able to do that with one command. There is no central endpoint with Proxmox VE. You will first have to pull the list of all VMs to see which node it is running on.
 
Thank you @sb-jw for your answer, I will look into this but maybe someone has already done this with one or more simple CLI commands.
Regards
 
Hi,

Sorry @sb-jw for not responding sooner and many thanks for your input.

Based on your suggestion I have written a one-line command to convert VMID number to host IP, but I don't like my code.

9999 is the VMID and the result is the host IP.

pvesh get /nodes/`pvesh get /cluster/resources --type=vm --noborder --noheader | grep "/9999" | awk -F ' ' '{print $14}'`/network --noborder --noheader | grep "vmbr0" | awk -F ' ' '{print $2}'

Does anyone have a better solution?

Regards,
 
You could just use json:
Code:
pvesh get /nodes/`pvesh get /cluster/resources --type=vm --output-format json|jq -r '.[]|select(.vmid == 3002)|.node'`/network --output-format json|jq -r '.[]|select(.iface == "vmbr0")|.address'
172.16.100.201

But I dont understand why you need the node IP? Once you know the node "owner" of the VM, you can just send the PVESH to that node from any other node.
Code:
echo pvesh get /nodes/`pvesh get /cluster/resources --type=vm --output-format json|jq -r '.[]|select(.vmid == 3002)|.node'`/qemu/3002
pvesh get /nodes/pve7demo1/qemu/3002



Blockbridge : Ultra low latency all-NVME shared storage for Proxmox - https://www.blockbridge.com/proxmox
 
Last edited:

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!