MCPcopy Create free account
hub / github.com/apache/cloudstack / find_device_for_gateway

Function find_device_for_gateway

systemvm/debian/opt/cloud/bin/cs/CsHelper.py:279–302  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

277
278
279def 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

Callers

nothing calls this directly

Calls 7

get_interfacesMethod · 0.80
addressMethod · 0.80
is_addedMethod · 0.80
ip_in_subnetMethod · 0.80
get_deviceMethod · 0.80
debugMethod · 0.80
errorMethod · 0.45

Tested by

no test coverage detected