qm list 2>/dev/null | awk '/\d+/ {print "vm:", $1, "\n"}' >> /etc/pve/ha/resources.cfg
GUESTS=$(pvesh get /cluster/resources --type vm --output-format yaml | awk '/vmid:/ {print $2}')
for id in $GUESTS; do ha-manager add "$id"; done
What happens, if a host fails and the VM's has no HA enabled?
Can we start them manually on another host or are they blocked on the failed host?
/etc/pve/nodes/<deadnode>/qemu-server/<VMID>.conf
to another node (same sub directory).It seems that we may want to adapt ha-manager add to accept lists of VMIDs in the future, not often required but when it's really nice to have.
Hi,
there isn't a built in command for mass adding all VMs but it's pretty easy to script, for VMs on current node for example:
qm list 2>/dev/null | awk '/\d+/ {print "vm:", $1, "\n"}' >> /etc/pve/ha/resources.cfg
qm list 2>/dev/null | awk '/\[0-9]+/ {print "vm:", $1, "\n"}' >> /etc/pve/ha/resources.cfg
root@proxmox07:~# cat /usr/local/bin/pve-ha-enable.sh
#!/bin/bash
# Running VMs
VMIDS_R=$(qm list | grep running | awk '{print $1}' | tail -n +1)
# Stopped VMs
VMIDS_S=$(qm list | grep stopped | awk '{print $1}' | tail -n +1)
HOSTNAME=$(hostname)
for VMID in ${VMIDS_R}
do
if [[ $(qm config ${VMID} | grep "nvme-zfs-mirror" | wc -c) -ne 0 ]]
then
# Do not migrate VMs on local storage
GROUP="${HOSTNAME}-do_not_migrate"
else
# Migrate VMs on shared storage
GROUP=${HOSTNAME}
fi
CMD="ha-manager add vm:${VMID} --group ${GROUP}"
echo "${CMD}"
${CMD}
done
for VMID in ${VMIDS_S}
do
CMD="ha-manager add vm:${VMID} --group ${HOSTNAME} --state stopped"
echo "${CMD}"
${CMD}
done
root@proxmox07:~#
We use essential cookies to make this site work, and optional cookies to enhance your experience.