#!/bin/bash
# Test Proxmox connectivity for both instances
# TASK-001, TASK-002: Verify network connectivity

set -e

INSTANCE_1_URL="https://192.168.11.10:8006"
INSTANCE_2_URL="https://192.168.11.11:8006"

echo "=== Testing Proxmox Connectivity ==="
echo ""

# Test Instance 1
echo "Testing Instance 1 ($INSTANCE_1_URL)..."
if curl -k -s -f "${INSTANCE_1_URL}/api2/json/version" > /dev/null 2>&1; then
    VERSION=$(curl -k -s "${INSTANCE_1_URL}/api2/json/version" | grep -o '"data":"[^"]*"' | cut -d'"' -f4 || echo "unknown")
    echo "✓ Instance 1 is reachable (Version: $VERSION)"
else
    echo "✗ Instance 1 is NOT reachable"
    exit 1
fi

# Test Instance 2
echo ""
echo "Testing Instance 2 ($INSTANCE_2_URL)..."
if curl -k -s -f "${INSTANCE_2_URL}/api2/json/version" > /dev/null 2>&1; then
    VERSION=$(curl -k -s "${INSTANCE_2_URL}/api2/json/version" | grep -o '"data":"[^"]*"' | cut -d'"' -f4 || echo "unknown")
    echo "✓ Instance 2 is reachable (Version: $VERSION)"
else
    echo "✗ Instance 2 is NOT reachable"
    exit 1
fi

echo ""
echo "=== Connectivity Test Complete ==="
echo "Both instances are reachable and responding"
