MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / sync_ethernet_interfaces

Method sync_ethernet_interfaces

multi_interface.py:113–160  ·  view source on GitHub ↗

Sync Ethernet interface metadata.

(self, interfaces: List[Dict])

Source from the content-addressed store, hash-verified

111 return discovered
112
113 def sync_ethernet_interfaces(self, interfaces: List[Dict]):
114 """Sync Ethernet interface metadata."""
115 timestamp = time.time()
116 ethernet_scan_enabled = self.shared_data.config.get('ethernet_scan_enabled', True)
117 default_eth = self.shared_data.config.get('ethernet_default_interface', 'eth0')
118
119 with self._lock:
120 new_state: Dict[str, Dict] = {}
121 for iface in interfaces:
122 name = iface.get('name')
123 if not name:
124 continue
125
126 has_carrier = iface.get('has_carrier', False)
127 is_connected = iface.get('connected', False)
128 ip_address = iface.get('ip_address')
129
130 # Check for link-local IP (169.254.x.x) - not a valid connection
131 has_link_local = is_link_local_ip(ip_address)
132 if has_link_local:
133 logger.debug(f"Ethernet interface {name} has link-local IP - treating as not connected")
134 ip_address = None
135 is_connected = False
136
137 # Determine if this interface can be used for scanning
138 # Requires: enabled, carrier, connected, valid (non-link-local) IP
139 can_scan = ethernet_scan_enabled and has_carrier and is_connected and ip_address and not has_link_local
140
141 entry = {
142 'name': name,
143 'type': 'ethernet',
144 'role': 'internal' if name == default_eth else 'external',
145 'state': iface.get('state', 'UNKNOWN'),
146 'connected': is_connected,
147 'has_carrier': has_carrier,
148 'ip_address': ip_address,
149 'cidr': iface.get('cidr'),
150 'network_cidr': iface.get('network_cidr'),
151 'mac_address': iface.get('mac_address'),
152 'scan_enabled': can_scan,
153 'last_refresh': timestamp,
154 'is_link_local': has_link_local,
155 'reason': None if can_scan else ('link_local' if has_link_local else 'disabled' if not ethernet_scan_enabled else 'no_connection'),
156 }
157 new_state[name] = entry
158
159 self.ethernet_interfaces = new_state
160 self.ethernet_last_refresh = timestamp
161
162 def get_ethernet_status(self) -> Dict:
163 """Get current Ethernet interface status."""

Callers 1

Calls 3

is_link_local_ipFunction · 0.90
debugMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected