Find which ethernet device the gateway IP belongs to by checking if the gateway is in any of the configured interface subnets. Args: config: CsConfig instance containing network configuration gateway_ip: IP address of the gateway to locate Returns: Device n
(config: 'CsConfig', gateway_ip: str)
| 277 | |
| 278 | |
| 279 | def find_device_for_gateway(config: 'CsConfig', gateway_ip: str) -> Optional[str]: |
| 280 | """ |
| 281 | Find which ethernet device the gateway IP belongs to by checking |
| 282 | if the gateway is in any of the configured interface subnets. |
| 283 | |
| 284 | Args: |
| 285 | config: CsConfig instance containing network configuration |
| 286 | gateway_ip: IP address of the gateway to locate |
| 287 | |
| 288 | Returns: |
| 289 | Device name (e.g., 'eth2') or None if not found |
| 290 | """ |
| 291 | try: |
| 292 | interfaces = config.address().get_interfaces() |
| 293 | for interface in interfaces: |
| 294 | if not interface.is_added(): |
| 295 | continue |
| 296 | if interface.ip_in_subnet(gateway_ip): |
| 297 | return interface.get_device() |
| 298 | logging.debug("No matching device found for gateway %s" % gateway_ip) |
| 299 | return None |
| 300 | except Exception as e: |
| 301 | logging.error("Error finding device for gateway %s: %s" % (gateway_ip, e)) |
| 302 | return None |
nothing calls this directly
no test coverage detected