#!/bin/bash

# Investigate VMID 6000 Network Issue
# IP: 192.168.11.113 (recently reassigned)

set -euo pipefail

echo "=== Investigating VMID 6000 Network Issue ==="
echo ""

# Check container config
echo "=== Container Config ==="
ssh -o StrictHostKeyChecking=accept-new -o ConnectTimeout=5 root@192.168.11.10 \
  "ssh -o StrictHostKeyChecking=accept-new -o ConnectTimeout=5 root@r630-01 'pct config 6000 | grep -E \"net|ip\" | head -10'"

echo ""
echo "=== Container Network Status ==="
ssh -o StrictHostKeyChecking=accept-new -o ConnectTimeout=5 root@192.168.11.10 \
  "ssh -o StrictHostKeyChecking=accept-new -o ConnectTimeout=5 root@r630-01 'pct exec 6000 -- ip addr show 2>&1 | head -20'"

echo ""
echo "=== Routing Table ==="
ssh -o StrictHostKeyChecking=accept-new -o ConnectTimeout=5 root@192.168.11.10 \
  "ssh -o StrictHostKeyChecking=accept-new -o ConnectTimeout=5 root@r630-01 'pct exec 6000 -- ip route show 2>&1'"

echo ""
echo "=== Gateway Reachability ==="
ssh -o StrictHostKeyChecking=accept-new -o ConnectTimeout=5 root@192.168.11.10 \
  "ssh -o StrictHostKeyChecking=accept-new -o ConnectTimeout=5 root@r630-01 'pct exec 6000 -- ping -c 2 -W 1 192.168.11.1 2>&1 || echo \"Gateway unreachable\"'"

echo ""
echo "=== DNS Test ==="
ssh -o StrictHostKeyChecking=accept-new -o ConnectTimeout=5 root@192.168.11.10 \
  "ssh -o StrictHostKeyChecking=accept-new -o ConnectTimeout=5 root@r630-01 'pct exec 6000 -- ping -c 2 -W 1 8.8.8.8 2>&1 || echo \"DNS server unreachable\"'"

echo ""
echo "=== Container Status ==="
ssh -o StrictHostKeyChecking=accept-new -o ConnectTimeout=5 root@192.168.11.10 \
  "ssh -o StrictHostKeyChecking=accept-new -o ConnectTimeout=5 root@r630-01 'pct status 6000 2>&1'"
