#!/bin/bash set -euo pipefail if ! which jq >> /dev/null; then echo "jq not found" exit 1 fi includingNomigrate=0 if [[ "$#" -gt 0 ]]; then includingNomigrate="$1" fi host="$(hostname)" if [[ "$#" -gt 1 ]]; then host="$2" fi function running_ids { if [[ "$includingNomigrate" == 1 ]]; then pvesh get "/nodes/${host}/qemu" --output-format json |\ jq -r 'map(select( .status == "running" ) | .vmid) | sort | @csv' else pvesh get "/nodes/${host}/qemu" --output-format json |\ jq -r 'map(select( .status == "running" and (.tags | split(";") | all(.!="nomigrate")) ) | .vmid) | sort | @csv' fi } running_ids="$(running_ids)" if [[ "$running_ids" != "" ]]; then echo "ERROR: VMs running on $host: $running_ids" exit 1 fi