janus: fallback for no-gw configuration

This commit is contained in:
Maxim Devaev 2022-11-20 05:52:33 +03:00
parent 59ed36a6af
commit 26a831d2ed

View File

@ -98,19 +98,19 @@ class JanusRunner: # pylint: disable=too-many-instance-attributes
def __get_default_ip(self) -> str: def __get_default_ip(self) -> str:
try: try:
gws = netifaces.gateways() gws = netifaces.gateways()
if "default" not in gws: if "default" in gws:
raise RuntimeError(f"No default gateway: {gws}") for proto in [socket.AF_INET, socket.AF_INET6]:
if proto in gws["default"]:
iface = gws["default"][proto][1]
addrs = netifaces.ifaddresses(iface)
return addrs[proto][0]["addr"]
iface = "" for iface in netifaces.interfaces():
for proto in [socket.AF_INET, socket.AF_INET6]: if not iface.startswith(("lo", "docker")):
if proto in gws["default"]: addrs = netifaces.ifaddresses(iface)
iface = gws["default"][proto][1] for proto in [socket.AF_INET, socket.AF_INET6]:
break if proto in addrs:
else: return addrs[proto][0]["addr"]
raise RuntimeError(f"No iface for the gateway {gws['default']}")
for addr in netifaces.ifaddresses(iface).get(proto, []):
return addr["addr"]
except Exception as err: except Exception as err:
get_logger().error("Can't get default IP: %s", tools.efmt(err)) get_logger().error("Can't get default IP: %s", tools.efmt(err))
return "" return ""