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

adoII

Renowned Member
Jan 28, 2010
182
19
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 $@