Last active
May 4, 2024 18:17
-
-
Save vladistan/217a2cf3e5ea07900203363c4976734f to your computer and use it in GitHub Desktop.
Start Proxmox VMs across the cluster using CLI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PATTERN="k8s" | |
VM_INFO=$(pvesh get /cluster/resources --type vm | grep $PATTERN | awk -F'│' '{for (i = 1; i <= NF; i++) {if ($i ~ /qemu\//) {gsub(/[^0-9]/, "", $i); vmid = $i;} if ($i ~ /pve[0-9]+/) {node = $i; gsub(/ /, "", node); print vmid, node; break;}}}') | |
# Convert VM_INFO into an array | |
VM_ARRAY=($VM_INFO) | |
# Process each VM ID and host pair | |
for (( i=0; i<${#VM_ARRAY[@]}; i+=2 )); do | |
VM_ID=${VM_ARRAY[i]} | |
HOST=${VM_ARRAY[i+1]} | |
ssh $HOST "qm stop $VM_ID" | |
echo "Stopping VM ID: $VM_ID on host: $HOST" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment