#!/bin/bash
set -euo pipefail

# Add Cloud-Init to All VMs
# This script adds cloud-init drives to all SMOM-DBIS-138 VMs

echo "=========================================="
echo "Adding Cloud-Init to All VMs"
echo "=========================================="
echo ""

# Site 1 VMs
echo "=== Site 1 (ml110-01) ==="
echo "Connecting to root@192.168.11.10..."
ssh root@192.168.11.10 << 'EOF'
for vmid in 136 139 141 142 145 146 150 151; do
  echo "Adding cloud-init to VMID $vmid..."
  qm set $vmid --ide2 local-lvm:cloudinit --ciuser admin --ipconfig0 ip=dhcp
  echo "✅ VMID $vmid done"
done
EOF

echo ""
echo "=== Site 2 (r630-01) ==="
echo "Connecting to root@192.168.11.11..."
ssh root@192.168.11.11 << 'EOF'
for vmid in 137 138 144 148 101 102 103 104; do
  echo "Adding cloud-init to VMID $vmid..."
  qm set $vmid --ide2 local-lvm:cloudinit --ciuser admin --ipconfig0 ip=dhcp
  echo "✅ VMID $vmid done"
done
EOF

echo ""
echo "=========================================="
echo "✅ Cloud-init drives added to all VMs"
echo "=========================================="
echo ""
echo "Next step: Write userData to VMs via Proxmox Web UI"
echo "  - Use all-vm-userdata.txt for the userData content"
echo "  - Or use: ./scripts/get-all-userdata.sh"

