diff options
author | Maxim Devaev <[email protected]> | 2022-11-20 05:52:33 +0300 |
---|---|---|
committer | Maxim Devaev <[email protected]> | 2022-11-20 05:52:33 +0300 |
commit | 26a831d2ed1550a6ab8536a3e0dbd621151ee7ed (patch) | |
tree | 06175e32bebe7ea373c71a69a7a80ac7fc7ae8ba /kvmd/apps | |
parent | 59ed36a6af79d9defbdeade9927ec61871295249 (diff) |
janus: fallback for no-gw configuration
Diffstat (limited to 'kvmd/apps')
-rw-r--r-- | kvmd/apps/janus/runner.py | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/kvmd/apps/janus/runner.py b/kvmd/apps/janus/runner.py index 140a7b62..e08fade0 100644 --- a/kvmd/apps/janus/runner.py +++ b/kvmd/apps/janus/runner.py @@ -98,19 +98,19 @@ class JanusRunner: # pylint: disable=too-many-instance-attributes def __get_default_ip(self) -> str: try: gws = netifaces.gateways() - if "default" not in gws: - raise RuntimeError(f"No default gateway: {gws}") - - iface = "" - for proto in [socket.AF_INET, socket.AF_INET6]: - if proto in gws["default"]: - iface = gws["default"][proto][1] - break - else: - raise RuntimeError(f"No iface for the gateway {gws['default']}") - - for addr in netifaces.ifaddresses(iface).get(proto, []): - return addr["addr"] + if "default" in 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"] + + for iface in netifaces.interfaces(): + if not iface.startswith(("lo", "docker")): + addrs = netifaces.ifaddresses(iface) + for proto in [socket.AF_INET, socket.AF_INET6]: + if proto in addrs: + return addrs[proto][0]["addr"] except Exception as err: get_logger().error("Can't get default IP: %s", tools.efmt(err)) return "" |