Files
proxmox/scripts/reassign-vlan200-to-vlan11.sh
defiQUG b3a8fe4496
Some checks failed
Deploy to Phoenix / deploy (push) Has been cancelled
chore: sync all changes to Gitea
- Config, docs, scripts, and backup manifests
- Submodule refs unchanged (m = modified content in submodules)

Made-with: Cursor
2026-03-02 11:37:34 -08:00

172 lines
6.8 KiB
Bash
Executable File

#!/usr/bin/env bash
# Reassign all VLAN 200 containers to VLAN 11 IPs
# Since VLAN 11 cannot reach VLAN 200, we need to move all containers to VLAN 11
set -uo pipefail
NODE_IP="${PROXMOX_HOST_R630_01}"
# VLAN 200 containers that need reassignment
declare -A vlan200_containers=(
["10000"]="order-postgres-primary"
["10001"]="order-postgres-replica"
["10020"]="order-redis"
["10030"]="order-identity"
["10040"]="order-intake"
["10050"]="order-finance"
["10060"]="order-dataroom"
["10070"]="order-legal"
["10080"]="order-eresidency"
["10090"]="order-portal-public"
["10091"]="order-portal-internal"
["10092"]="order-mcp-legal"
["10200"]="order-prometheus"
["10201"]="order-grafana"
["10202"]="order-opensearch"
["10210"]="order-haproxy"
["10230"]="order-vault"
["10232"]="CT10232"
)
# Available IPs in VLAN 11 (${NETWORK_192_168_11_0:-192.168.11.0}/24)
# Reserved: 10-25 (physical servers), avoiding conflicts with existing assignments
available_ips=(
"${IP_SERVICE_35:-${IP_SERVICE_35:-${IP_SERVICE_35:-${IP_SERVICE_35:-${IP_SERVICE_35:-${IP_SERVICE_35:-192.168.11.35}}}}}}"
"${IP_SERVICE_36:-${IP_SERVICE_36:-${IP_SERVICE_36:-${IP_SERVICE_36:-${IP_SERVICE_36:-${IP_SERVICE_36:-192.168.11.36}}}}}}"
"${IP_MIM_WEB:-192.168.11.37}"
"${ORDER_REDIS_IP:-192.168.11.38}"
"${IP_ORDER_HAPROXY:-${IP_ORDER_HAPROXY:-192.168.11.39}}"
"${IP_SERVICE_40:-${IP_SERVICE_40:-${IP_SERVICE_40:-192.168.11.40}}}"
"${IP_SERVICE_41:-${IP_SERVICE_41:-${IP_SERVICE_41:-192.168.11.41}}}"
"${IP_SERVICE_42:-${IP_SERVICE_42:-${IP_SERVICE_42:-192.168.11.42}}}"
"${IP_SERVICE_43:-${IP_SERVICE_43:-${IP_SERVICE_43:-192.168.11.43}}}"
"${ORDER_POSTGRES_PRIMARY:-${ORDER_POSTGRES_PRIMARY:-192.168.11.44}}"
"${ORDER_POSTGRES_REPLICA:-${ORDER_POSTGRES_REPLICA:-192.168.11.45}}"
"${ORDER_REDIS_REPLICA:-${ORDER_REDIS_REPLICA:-${ORDER_REDIS_REPLICA:-192.168.11.46}}}"
"${IP_SERVICE_47:-${IP_SERVICE_47:-${IP_SERVICE_47:-192.168.11.47}}}"
"${IP_ORDER_OPENSEARCH:-${IP_ORDER_OPENSEARCH:-${IP_ORDER_OPENSEARCH:-192.168.11.48}}}"
"${IP_SERVICE_49:-${IP_SERVICE_49:-${IP_SERVICE_49:-192.168.11.49}}}"
"${IP_SERVICE_50:-${IP_SERVICE_50:-${IP_SERVICE_50:-${IP_SERVICE_50:-${IP_SERVICE_50:-${IP_SERVICE_50:-192.168.11.50}}}}}}"
"${IP_SERVICE_51:-${IP_SERVICE_51:-${IP_SERVICE_51:-${IP_SERVICE_51:-${IP_SERVICE_51:-${IP_SERVICE_51:-192.168.11.51}}}}}}"
"${IP_SERVICE_52:-${IP_SERVICE_52:-192.168.11.52}}"
"${DB_HOST:-192.168.11.53}"
"${IP_SERVICE_54:-${IP_SERVICE_54:-192.168.11.54}}"
"${IP_SERVICE_55:-${IP_SERVICE_55:-192.168.11.55}}"
"${IP_SERVICE_56:-${IP_SERVICE_56:-192.168.11.56}}"
"${IP_SERVICE_57:-${IP_SERVICE_57:-192.168.11.57}}"
"${IP_SERVICE_58:-${IP_SERVICE_58:-192.168.11.58}}"
)
# Check if we have enough IPs
if [ ${#available_ips[@]} -lt ${#vlan200_containers[@]} ]; then
echo "ERROR: Not enough available IPs. Need ${#vlan200_containers[@]}, have ${#available_ips[@]}"
exit 1
fi
echo "═══════════════════════════════════════════════════════════"
echo "Reassigning VLAN 200 Containers to VLAN 11"
echo "═══════════════════════════════════════════════════════════"
echo ""
echo "Containers to reassign: ${#vlan200_containers[@]}"
echo "Available IPs: ${#available_ips[@]}"
echo ""
# Create mapping
declare -a vmid_list=()
declare -a ip_list=()
index=0
for vmid in "${!vlan200_containers[@]}"; do
vmid_list+=("$vmid")
ip_list+=("${available_ips[$index]}")
((index++))
done
# Display mapping
echo "IP Reassignment Plan:"
echo "───────────────────────────────────────────────────────────"
for i in "${!vmid_list[@]}"; do
vmid="${vmid_list[$i]}"
new_ip="${ip_list[$i]}"
hostname="${vlan200_containers[$vmid]}"
old_ip=$(ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no root@${NODE_IP} \
"pct config $vmid 2>/dev/null | grep '^net0:' | grep -oP 'ip=\\K[^,]+' | cut -d'/' -f1" || echo "N/A")
printf " CT %-6s %-30s %-15s → %-15s\n" "$vmid" "$hostname" "$old_ip" "$new_ip"
done
echo ""
# Auto-proceed (non-interactive)
echo "Proceeding with reassignment automatically..."
echo ""
echo "Starting reassignment..."
echo ""
SUCCESS=0
FAILED=0
# Reassign each container
for i in "${!vmid_list[@]}"; do
vmid="${vmid_list[$i]}"
new_ip="${ip_list[$i]}"
hostname="${vlan200_containers[$vmid]}"
echo "Processing CT $vmid ($hostname)..."
# Stop container first
echo " Stopping container..."
ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no root@${NODE_IP} \
"pct stop $vmid 2>/dev/null" || true
sleep 2
# Get current network config
current_net=$(ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no root@${NODE_IP} \
"pct config $vmid 2>/dev/null | grep '^net0:'" || echo "")
if [ -z "$current_net" ]; then
echo " ⚠️ No network config found, creating new..."
# Create new network config
ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no root@${NODE_IP} \
"pct set $vmid --net0 name=eth0,bridge=vmbr0,ip=${new_ip}/24,gw=${NETWORK_GATEWAY:-192.168.11.1}" 2>&1
else
# Extract bridge name (default to vmbr0 if not found)
bridge=$(echo "$current_net" | grep -oP 'bridge=\\K[^,]+' || echo "vmbr0")
# Update IP address
echo " Updating IP to $new_ip..."
ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no root@${NODE_IP} \
"pct set $vmid --net0 name=eth0,bridge=${bridge},ip=${new_ip}/24,gw=${NETWORK_GATEWAY:-192.168.11.1}" 2>&1
fi
if [ $? -eq 0 ]; then
echo " ✅ IP updated to $new_ip"
# Start container
echo " Starting container..."
ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no root@${NODE_IP} \
"pct start $vmid" 2>&1
if [ $? -eq 0 ]; then
echo " ✅ Container started"
((SUCCESS++))
else
echo " ⚠️ IP updated but container failed to start"
((FAILED++))
fi
else
echo " ❌ Failed to update IP"
((FAILED++))
fi
echo ""
sleep 1
done
echo "═══════════════════════════════════════════════════════════"
echo "Reassignment Complete"
echo "═══════════════════════════════════════════════════════════"
echo " Success: $SUCCESS"
echo " Failed: $FAILED"
echo " Total: ${#vlan200_containers[@]}"
echo "═══════════════════════════════════════════════════════════"