#!/bin/bash
# verify-cluster-quorum.sh
# Verifies cluster quorum configuration for 2-node cluster

set -euo pipefail

# Load environment variables
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
if [ -f "${SCRIPT_DIR}/../.env" ]; then
    set -a
    source <(grep -v '^#' "${SCRIPT_DIR}/../.env" | grep -v '^$' | sed 's/^/export /')
    set +a
fi

# Colors
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'

NODE1_IP="192.168.11.10"
NODE1_NAME="ML110-01"
NODE2_IP="192.168.11.11"
NODE2_NAME="R630-01"

log() {
    echo -e "${GREEN}[INFO]${NC} $1"
}

warn() {
    echo -e "${YELLOW}[WARN]${NC} $1"
}

info() {
    echo -e "${BLUE}[INFO]${NC} $1"
}

main() {
    echo ""
    echo "╔══════════════════════════════════════════════════════════════╗"
    echo "║          Cluster Quorum Verification                        ║"
    echo "╚══════════════════════════════════════════════════════════════╝"
    echo ""
    
    info "For a 2-node Proxmox cluster, quorum must be configured."
    echo ""
    info "To verify quorum configuration via SSH:"
    echo ""
    echo "On ML110-01:"
    echo "  ssh root@192.168.11.10"
    echo "  pvecm expected 2"
    echo "  pvecm status"
    echo ""
    echo "On R630-01:"
    echo "  ssh root@192.168.11.11"
    echo "  pvecm expected 2"
    echo "  pvecm status"
    echo ""
    warn "Note: Quorum configuration requires SSH access or Web UI"
    warn "API-based quorum configuration is not available"
    echo ""
    info "Expected output should show:"
    info "  Quorum information"
    info "  ------------------"
    info "  Date:             [current date]"
    info "  Quorum provider:  corosync_votequorum"
    info "  Nodes:            2"
    info "  Node ID:          1"
    info "  Ring ID:          [ring id]"
    info "  Quorate:          Yes"
    echo ""
}

main "$@"

