Skip to content

Commit

Permalink
Fix: Operators had to specify network interface
Browse files Browse the repository at this point in the history
The network interfaces defaulted to `eth0`, which not the default on all supported systems.

This uses the default network interface instead, and should require less configuration from node operators and developers.

Fixes #253
  • Loading branch information
hoh committed Sep 19, 2023
1 parent 2b39b16 commit d35b544
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
3 changes: 2 additions & 1 deletion doc/INSTALL-Debian-12.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ ALEPH_VM_DOMAIN_NAME=vm.example.org

#### Network configuration

On some systems, the default network interface is not `eth0` and you will want to configure the default interface
The default network interface is detected automatically from the IP routes.
On some systems, this is not the desired configuration and you will want to configure the default interface
by adding:
```
ALEPH_VM_NETWORK_INTERFACE=enp0s1
Expand Down
3 changes: 2 additions & 1 deletion doc/INSTALL-Ubuntu-22.04.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ ALEPH_VM_DNS_RESOLUTION=resolvectl

> 💡 You can instead specify the DNS resolvers used by the VMs using `ALEPH_VM_DNS_NAMESERVERS=["1.2.3.4", "5.6.7.8"]`.
On some systems, the default network interface is not `eth0` and you will want to configure the default interface
The default network interface is detected automatically from the IP routes.
On some systems, this is not the desired configuration and you will want to configure the default interface
by adding:
```
ALEPH_VM_NETWORK_INTERFACE=enp0s1
Expand Down
16 changes: 15 additions & 1 deletion vm_supervisor/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ def resolvectl_dns_servers_ipv4(interface: str) -> Iterable[str]:
yield server


def get_default_interface() -> Optional[str]:
"""Returns the default network interface"""
with open("/proc/net/route", "r") as f:
for line in f.readlines():
parts = line.strip().split()
if parts[1] == "00000000": # Indicates default route
return parts[0]
return None


class Settings(BaseSettings):
SUPERVISOR_HOST = "127.0.0.1"
SUPERVISOR_PORT: int = 4020
Expand All @@ -93,7 +103,7 @@ class Settings(BaseSettings):

# Networking does not work inside Docker/Podman
ALLOW_VM_NETWORKING = True
NETWORK_INTERFACE = "eth0"
NETWORK_INTERFACE: Optional[str] = None
IPV4_ADDRESS_POOL = Field(
default="172.16.0.0/12",
description="IPv4 address range used to provide networks to VMs.",
Expand Down Expand Up @@ -236,6 +246,7 @@ def check(self):
assert isfile(self.FIRECRACKER_PATH), f"File not found {self.FIRECRACKER_PATH}"
assert isfile(self.JAILER_PATH), f"File not found {self.JAILER_PATH}"
assert isfile(self.LINUX_PATH), f"File not found {self.LINUX_PATH}"
assert self.NETWORK_INTERFACE, f"Network interface is not specified"
assert self.CONNECTOR_URL.startswith(
"http://"
) or self.CONNECTOR_URL.startswith("https://")
Expand Down Expand Up @@ -271,6 +282,9 @@ def setup(self):
os.makedirs(self.EXECUTION_LOG_DIRECTORY, exist_ok=True)
os.makedirs(self.PERSISTENT_VOLUMES_DIR, exist_ok=True)

if not self.NETWORK_INTERFACE:
self.NETWORK_INTERFACE = get_default_interface()

if self.DNS_NAMESERVERS is None and self.DNS_RESOLUTION:
if self.DNS_RESOLUTION == DnsResolver.resolv_conf:
self.DNS_NAMESERVERS = list(etc_resolv_conf_dns_servers())
Expand Down

0 comments on commit d35b544

Please sign in to comment.