#!/bin/bash
# Helper script to provide commands for running verification on Proxmox node
# This script outputs the commands to copy to Proxmox SSH session

VMID=100

echo "=========================================="
echo "Copy and paste these commands into your"
echo "Proxmox SSH session (root@ml110-01):"
echo "=========================================="
echo ""
echo "--- START COPY ---"
echo ""
echo "VMID=100"
echo ""
echo "# Step 1: Check VM status"
echo "qm status \$VMID"
echo ""
echo "# Step 2: Verify boot order"
echo "BOOT=\$(qm config \$VMID | grep '^boot:' || echo '')"
echo "if [ -z \"\$BOOT\" ]; then"
echo "  echo 'Fixing boot order...'"
echo "  qm set \$VMID --boot order=scsi0"
echo "else"
echo "  echo \"Boot order: \$BOOT\""
echo "fi"
echo ""
echo "# Step 3: Verify disk"
echo "SCSI0=\$(qm config \$VMID | grep '^scsi0:' || echo '')"
echo "if [ -z \"\$SCSI0\" ]; then"
echo "  echo 'ERROR: Disk not configured!'"
echo "  exit 1"
echo "else"
echo "  echo \"Disk: \$SCSI0\""
echo "fi"
echo "lvs | grep vm-\$VMID-disk"
echo ""
echo "# Step 4: Verify cloud-init"
echo "IDE2=\$(qm config \$VMID | grep '^ide2:' || echo '')"
echo "if [ -z \"\$IDE2\" ]; then"
echo "  echo 'Fixing cloud-init...'"
echo "  qm set \$VMID --ide2 local-lvm:cloudinit"
echo "  qm set \$VMID --ciuser admin"
echo "  qm set \$VMID --ipconfig0 ip=dhcp"
echo "else"
echo "  echo \"Cloud-init: \$IDE2\""
echo "fi"
echo ""
echo "# Step 5: Verify network"
echo "NET0=\$(qm config \$VMID | grep '^net0:' || echo '')"
echo "if [ -z \"\$NET0\" ]; then"
echo "  echo 'Fixing network...'"
echo "  qm set \$VMID --net0 virtio,bridge=vmbr0"
echo "else"
echo "  echo \"Network: \$NET0\""
echo "fi"
echo ""
echo "# Step 6: Verify guest agent (already fixed)"
echo "qm config \$VMID | grep '^agent:'"
echo ""
echo "# Step 7: Final config summary"
echo "echo '=== Final Configuration ==='"
echo "qm config \$VMID | grep -E '^agent:|^boot:|^scsi0:|^ide2:|^net0:|^ciuser:'"
echo ""
echo "# Step 8: Start VM"
echo "STATUS=\$(qm status \$VMID | awk '{print \$2}')"
echo "if [ \"\$STATUS\" != \"running\" ]; then"
echo "  echo 'Starting VM...'"
echo "  qm start \$VMID"
echo "  sleep 5"
echo "  qm status \$VMID"
echo "else"
echo "  echo 'VM is already running'"
echo "fi"
echo ""
echo "--- END COPY ---"
echo ""
echo "After running, monitor from Kubernetes:"
echo "  kubectl get proxmoxvm basic-vm-001 -w"

