#!/bin/bash
# Test Proxmox connection methods

PROXMOX_HOST="${PROXMOX_HOST:-192.168.11.10}"
PROXMOX_USER="${PROXMOX_USER:-root}"

echo "Testing Proxmox Connection Methods"
echo "==================================="
echo ""

echo "1. Testing Ping..."
if ping -c 2 -W 2 $PROXMOX_HOST > /dev/null 2>&1; then
    echo "   ✓ Ping successful"
else
    echo "   ✗ Ping failed (host unreachable)"
fi

echo ""
echo "2. Testing Port 8006..."
if timeout 3 bash -c "echo > /dev/tcp/$PROXMOX_HOST/8006" 2>/dev/null; then
    echo "   ✓ Port 8006 is accessible"
else
    echo "   ✗ Port 8006 is not accessible"
fi

echo ""
echo "3. Testing SSH..."
if timeout 5 ssh -o StrictHostKeyChecking=no -o ConnectTimeout=3 $PROXMOX_USER@$PROXMOX_HOST "echo 'SSH works'" 2>/dev/null; then
    echo "   ✓ SSH connection successful"
    echo ""
    echo "4. Testing pvesh via SSH..."
    if timeout 5 ssh -o StrictHostKeyChecking=no -o ConnectTimeout=3 $PROXMOX_USER@$PROXMOX_HOST "pvesh get /nodes --output-format json" 2>/dev/null | grep -q "node"; then
        echo "   ✓ pvesh works via SSH"
        echo ""
        echo "→ Recommendation: Use list_vms.sh (shell script)"
    else
        echo "   ✗ pvesh not available or failed"
    fi
else
    echo "   ✗ SSH connection failed"
fi

echo ""
echo "Current Network Info:"
echo "  Your IP: $(ip addr show | grep 'inet.*192.168' | awk '{print $2}' | head -1)"
echo "  Target Host: $PROXMOX_HOST"
