Script to start a vm in a cluster, don't know on which cluster member the vm is

adoII

Renowned Member
Jan 28, 2010
174
17
83
Hi,

I want to write a script that stops and starts a vm in a proxmox cluster
When I use qm start I have to know on which of the cluster the vm xx is defined and running

Is there a kind of cluster "qm" command that lets me stop and start a vm when i do not know on which cluster menber it is running ?

Thanks
 
This probably isn't the most efficient way to do this, but the following script works for simple qm commands (we call it qmc - "qm cluster"):

Code:
#!/bin/bash
#Author: Jeff Moskow - Ready-to-Run Software, Inc.

#Desc: Runs a "qm" command on the appropriate cluster node
#      NOTE: This assume that the vmid is the last argument so optional arguments don't work.
#      Please test and use at own risk.

# vm id
vm=$BASH_ARGV

# find the node with this VM
for node in `pvecm nodes | sed '1,1d;s/^.* //'` ; do ssh $node qm list | egrep "^ *$vm " >/dev/null && break ; done

ssh $node qm $@
 
This version is faster, but I'm not sure that it will be guaranteed to work as well with future releases:

Code:
#!/bin/bash#Author: Jeff Moskow - Ready-to-Run Software, Inc.


#Desc: Runs a "qm: command on the approproate cluster node
#      NOTE: This assume that the vmid is the last argument so optional arguments don't work.
#      Please test and use at own risk.


# vm id
vm=$BASH_ARGV


# find the node with this VM
node=$(ls /etc/pve/nodes/*/qemu-server/$vm.conf | cut -d / -f5)


ssh $node qm $@
 

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!