pybatmesh/naxalnet

49 lines
1.1 KiB
Python
Executable File

#!/usr/bin/env python3
"""
Setup a working BATMAN Advanced network
with systemd-networkd and iwd
"""
# for linking resolv.conf
from pathlib import Path
from dasbus.connection import SystemMessageBus
SYSTEMD_RESOLVED_STUB_RESOLVE = "/run/systemd/resolve/stub-resolv.conf"
RESOLV_CONF = "/etc/resolv.conf"
def get_all_devices(proxy):
"""
Returns d-bus object path of all devices as a list of strings.
proxy: usually what is returned by bus.get_proxy('net.connman.iwd','/')
"""
# Gets all D-Bus objects in the proxy.
objects = proxy.GetManagedObjects()
# Now find out which of them are devices
devices = []
for name, obj in objects.items():
if "net.connman.iwd.Device" in obj:
# add all devices to the list
devices.append(name)
return devices
# Copy networkd configs
# syslink resolvd
try:
Path(RESOLV_CONF).symlink_to(SYSTEMD_RESOLVED_STUB_RESOLVE)
except FileExistsError:
print("Resolv.conf already exists")
# connect to the System bus
bus = SystemMessageBus()
# iwd proxy
proxy = bus.get_proxy("net.connman.iwd", "/")
print("Bye")