Handle edge case when two sparks have both cables plugged and assigned IPs

This commit is contained in:
Eugene Rakhmatulin
2026-03-31 11:59:03 -07:00
parent 41c0ce2c9a
commit 7f0be29fcc

View File

@@ -332,16 +332,28 @@ detect_copy_hosts() {
_scan_subnet_for_gb10 "$cidr" "$local_iface_ip" "$temp_file" _scan_subnet_for_gb10 "$cidr" "$local_iface_ip" "$temp_file"
done done
# Deduplicate and collect results # Deduplicate and collect results.
# On two-cable setups two IB IPs may belong to the same host; deduplicate by
# querying each host's ETH_IF IP as a canonical identity.
COPY_PEER_NODES=() COPY_PEER_NODES=()
declare -A _SEEN_COPY declare -A _SEEN_COPY # keyed by IB IP
declare -A _SEEN_HOST # keyed by ETH_IF IP → first IB IP seen for that host
if [[ -f "$temp_file" ]]; then if [[ -f "$temp_file" ]]; then
while read -r ip; do while read -r ip; do
if [[ -z "${_SEEN_COPY[$ip]}" ]]; then [[ -n "${_SEEN_COPY[$ip]}" ]] && continue
_SEEN_COPY["$ip"]=1 _SEEN_COPY["$ip"]=1
# Resolve canonical host identity via ETH_IF IP
local host_ip
host_ip=$(ssh -o ConnectTimeout=3 -o StrictHostKeyChecking=no -o BatchMode=yes "$ip" \
"ip -o -f inet addr show $ETH_IF 2>/dev/null | awk '{print \$4}' | head -n1 | cut -d/ -f1" \
2>/dev/null)
if [[ -n "$host_ip" && -n "${_SEEN_HOST[$host_ip]}" ]]; then
echo " Skipping $ip (same host as ${_SEEN_HOST[$host_ip]}, ETH_IF: $host_ip)"
continue
fi
[[ -n "$host_ip" ]] && _SEEN_HOST["$host_ip"]="$ip"
COPY_PEER_NODES+=("$ip") COPY_PEER_NODES+=("$ip")
echo " Found GB10 copy host: $ip" echo " Found GB10 copy host: $ip"
fi
done < <(sort "$temp_file") done < <(sort "$temp_file")
rm -f "$temp_file" rm -f "$temp_file"
fi fi