2026-03-02 11:37:34 -08:00
#!/usr/bin/env bash
2026-02-12 15:46:57 -08:00
# IP Conflict Resolution Script
# Resolves 3 verified IP conflicts on r630-01
# Date: 2026-01-20
set -euo pipefail
# Load IP configuration
SCRIPT_DIR = " $( cd " $( dirname " ${ BASH_SOURCE [0] } " ) " && pwd ) "
PROJECT_ROOT = " $( cd " $SCRIPT_DIR /.. " && pwd ) "
source " ${ PROJECT_ROOT } /config/ip-addresses.conf " 2>/dev/null || true
PROXMOX_HOST = " ${ PROXMOX_HOST_R630_01 } "
LOG_FILE = " /tmp/ip-conflict-resolution- $( date +%Y%m%d-%H%M%S) .log "
log( ) {
echo " [ $( date +'%Y-%m-%d %H:%M:%S' ) ] $1 " | tee -a " $LOG_FILE "
}
log_error( ) {
echo " [ $( date +'%Y-%m-%d %H:%M:%S' ) ] ERROR: $1 " | tee -a " $LOG_FILE "
}
verify_ip_available( ) {
local ip = $1
log " Verifying IP $ip is available... "
if ping -c 1 -W 1 " $ip " > /dev/null 2>& 1; then
log_error " IP $ip is already in use! "
return 1
fi
log " IP $ip is available ✓ "
return 0
}
resolve_conflict( ) {
local vmid = $1
local old_ip = $2
local new_ip = $3
local name = $4
log " === Resolving conflict for VMID $vmid ( $name ) === "
log " Current IP: $old_ip "
log " New IP: $new_ip "
# Verify new IP is available
if ! verify_ip_available " $new_ip " ; then
log_error " Cannot proceed - IP $new_ip is in use "
return 1
fi
# Stop container
log " Stopping container $vmid ... "
ssh root@$PROXMOX_HOST " pct stop $vmid " || {
log_error " Failed to stop container $vmid "
return 1
}
# Wait for stop
sleep 2
# Get current network configuration
log "Getting current network configuration..."
local current_net = $( ssh root@$PROXMOX_HOST " pct config $vmid | grep '^net0:' | cut -d' ' -f2- " )
# Extract network parameters
local bridge = $( echo " $current_net " | grep -oP 'bridge=\K[^,]+' || echo "vmbr0" )
local gw = $( echo " $current_net " | grep -oP 'gw=\K[^,]+' || echo " ${ PROXMOX_HOST_R630_01 :- 192 .168.11.11 } " )
local hwaddr = $( echo " $current_net " | grep -oP 'hwaddr=\K[^,]+' || echo "" )
local type = $( echo " $current_net " | grep -oP 'type=\K[^,]+' || echo "veth" )
# Build new network configuration
local new_net = " name=eth0,bridge= $bridge ,gw= $gw ,ip= $new_ip /24,type= $type "
if [ -n " $hwaddr " ] ; then
new_net = " $new_net ,hwaddr= $hwaddr "
fi
# Update network configuration
log "Updating network configuration..."
ssh root@$PROXMOX_HOST " pct set $vmid --net0 ' $new_net ' " || {
log_error "Failed to update network configuration"
log "Attempting to start container with old configuration..."
ssh root@$PROXMOX_HOST " pct start $vmid " || true
return 1
}
# Start container
log " Starting container $vmid ... "
ssh root@$PROXMOX_HOST " pct start $vmid " || {
log_error " Failed to start container $vmid "
return 1
}
# Wait for startup
sleep 3
# Verify new IP
log "Verifying new IP assignment..."
local actual_ip = $( ssh root@$PROXMOX_HOST " pct exec $vmid -- hostname -I 2>/dev/null | awk '{print \$1}' " || echo "" )
if [ " $actual_ip " = " $new_ip " ] ; then
log "✓ IP conflict resolved successfully!"
log " VMID $vmid ( $name ): $old_ip → $new_ip "
return 0
else
log_error " IP verification failed. Actual IP: $actual_ip , Expected: $new_ip "
return 1
fi
}
main( ) {
log "=== IP Conflict Resolution Script ==="
log " Host: $PROXMOX_HOST "
log " Log file: $LOG_FILE "
log ""
# Check if running in dry-run mode
if [ " ${ DRY_RUN :- false } " = "true" ] ; then
log "DRY RUN MODE - No changes will be made"
log ""
fi
# Verify SSH access
log "Verifying SSH access..."
if ! ssh -o ConnectTimeout = 5 root@$PROXMOX_HOST "echo 'SSH OK'" > /dev/null 2>& 1; then
log_error " Cannot connect to $PROXMOX_HOST "
exit 1
fi
log "SSH access verified ✓"
log ""
# Verify IP availability
log "=== Step 1: Verifying IP Availability ==="
for ip in ${ 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 } } ; do
if ! verify_ip_available " $ip " ; then
log_error " Required IP $ip is not available. Cannot proceed. "
exit 1
fi
done
log ""
if [ " ${ DRY_RUN :- false } " = "true" ] ; then
log "DRY RUN - Would resolve conflicts:"
log " VMID 10070 (order-legal): ${ IP_SERVICE_50 :- ${ IP_SERVICE_50 :- ${ IP_SERVICE_50 :- ${ IP_SERVICE_50 :- ${ IP_SERVICE_50 :- ${ IP_SERVICE_50 :- 192 .168.11.50 } } } } } } → ${ IP_SERVICE_54 :- ${ IP_SERVICE_54 :- 192 .168.11.54 } } "
log " VMID 10230 (order-vault): ${ IP_SERVICE_51 :- ${ IP_SERVICE_51 :- ${ IP_SERVICE_51 :- ${ IP_SERVICE_51 :- ${ IP_SERVICE_51 :- ${ IP_SERVICE_51 :- 192 .168.11.51 } } } } } } → ${ IP_SERVICE_55 :- ${ IP_SERVICE_55 :- 192 .168.11.55 } } "
log " VMID 10232 (CT10232): ${ IP_SERVICE_52 :- ${ IP_SERVICE_52 :- 192 .168.11.52 } } → ${ IP_SERVICE_56 :- ${ IP_SERVICE_56 :- 192 .168.11.56 } } "
exit 0
fi
# Resolve conflicts
log "=== Step 2: Resolving IP Conflicts ==="
log ""
# Conflict 1: VMID 10070 (order-legal)
resolve_conflict 10070 " ${ IP_SERVICE_50 :- ${ IP_SERVICE_50 :- ${ IP_SERVICE_50 :- ${ IP_SERVICE_50 :- ${ IP_SERVICE_50 :- ${ IP_SERVICE_50 :- 192 .168.11.50 } } } } } } " " ${ IP_SERVICE_54 :- ${ IP_SERVICE_54 :- 192 .168.11.54 } } " "order-legal"
local result1 = $?
log ""
# Conflict 2: VMID 10230 (order-vault)
resolve_conflict 10230 " ${ IP_SERVICE_51 :- ${ IP_SERVICE_51 :- ${ IP_SERVICE_51 :- ${ IP_SERVICE_51 :- ${ IP_SERVICE_51 :- ${ IP_SERVICE_51 :- 192 .168.11.51 } } } } } } " " ${ IP_SERVICE_55 :- ${ IP_SERVICE_55 :- 192 .168.11.55 } } " "order-vault"
local result2 = $?
log ""
# Conflict 3: VMID 10232 (CT10232)
resolve_conflict 10232 " ${ IP_SERVICE_52 :- ${ IP_SERVICE_52 :- 192 .168.11.52 } } " " ${ IP_SERVICE_56 :- ${ IP_SERVICE_56 :- 192 .168.11.56 } } " "CT10232"
local result3 = $?
log ""
# Summary
log "=== Resolution Summary ==="
if [ $result1 -eq 0 ] && [ $result2 -eq 0 ] && [ $result3 -eq 0 ] ; then
log "✓ All IP conflicts resolved successfully!"
log ""
log "Verification:"
log " ${ IP_SERVICE_50 :- ${ IP_SERVICE_50 :- ${ IP_SERVICE_50 :- ${ IP_SERVICE_50 :- ${ IP_SERVICE_50 :- ${ IP_SERVICE_50 :- 192 .168.11.50 } } } } } } → VMID 7800 (sankofa-api-1) only "
log " ${ IP_SERVICE_51 :- ${ IP_SERVICE_51 :- ${ IP_SERVICE_51 :- ${ IP_SERVICE_51 :- ${ IP_SERVICE_51 :- ${ IP_SERVICE_51 :- 192 .168.11.51 } } } } } } → VMID 7801 (sankofa-portal-1) only "
log " ${ IP_SERVICE_52 :- ${ IP_SERVICE_52 :- 192 .168.11.52 } } → VMID 7802 (sankofa-keycloak-1) only "
log " ${ IP_SERVICE_54 :- ${ IP_SERVICE_54 :- 192 .168.11.54 } } → VMID 10070 (order-legal) "
log " ${ IP_SERVICE_55 :- ${ IP_SERVICE_55 :- 192 .168.11.55 } } → VMID 10230 (order-vault) "
log " ${ IP_SERVICE_56 :- ${ IP_SERVICE_56 :- 192 .168.11.56 } } → VMID 10232 (CT10232) "
exit 0
else
log_error " Some conflicts could not be resolved. Check log file: $LOG_FILE "
exit 1
fi
}
main " $@ "