Compare commits

...

2 Commits

Author SHA1 Message Date
Ryuichi Leo Takashige
e9e417d8e7 use 169.254, a little hacky 2026-01-29 19:51:25 +00:00
Ryuichi Leo Takashige
82ba48a89f Prioritise thunderbolt ip for ring 2026-01-29 19:51:25 +00:00

View File

@@ -245,10 +245,13 @@ def _find_ip_prioritised(
other_node_id: NodeId,
cycle_digraph: Topology,
node_network: Mapping[NodeId, NodeNetworkInfo],
*,
prefer_thunderbolt: bool = False,
) -> str | None:
"""Find an IP address between nodes with prioritization.
Priority: ethernet > wifi > unknown > thunderbolt
Default priority: ethernet > wifi > unknown > maybe_ethernet > thunderbolt
With prefer_thunderbolt: thunderbolt/link-local > ethernet > wifi > unknown > maybe_ethernet
"""
ips = list(_find_connection_ip(node_id, other_node_id, cycle_digraph))
if not ips:
@@ -257,14 +260,33 @@ def _find_ip_prioritised(
ip_to_type = {
iface.ip_address: iface.interface_type for iface in other_network.interfaces
}
priority = {
"ethernet": 0,
"wifi": 1,
"unknown": 2,
"maybe_ethernet": 3,
"thunderbolt": 4,
}
return min(ips, key=lambda ip: priority.get(ip_to_type.get(ip, "unknown"), 2))
def get_priority(ip: str) -> int:
interface_type = ip_to_type.get(ip, "unknown")
if prefer_thunderbolt:
# Link-local IPs (169.254.x.x) on maybe_ethernet are likely Thunderbolt
# TODO: This is a hack - fix this.
if interface_type == "maybe_ethernet" and ip.startswith("169.254."):
return 0
priority = {
"thunderbolt": 0,
"ethernet": 1,
"wifi": 2,
"unknown": 3,
"maybe_ethernet": 4,
}
return priority.get(interface_type, 3)
else:
priority = {
"ethernet": 0,
"wifi": 1,
"unknown": 2,
"maybe_ethernet": 3,
"thunderbolt": 4,
}
return priority.get(interface_type, 2)
return min(ips, key=get_priority)
def get_mlx_ring_hosts_by_node(
@@ -303,7 +325,8 @@ def get_mlx_ring_hosts_by_node(
continue
connection_ip = _find_ip_prioritised(
node_id, other_node_id, cycle_digraph, node_network
node_id, other_node_id, cycle_digraph, node_network,
prefer_thunderbolt=True,
)
if connection_ip is None:
raise ValueError(