From 25a5bdee303e5cd26128f445173d5d3def4c74d8 Mon Sep 17 00:00:00 2001 From: Pranav Jerry Date: Sat, 25 Sep 2021 15:04:29 +0530 Subject: [PATCH] added network.py and some other changes This will be used to control systemd-networkd via d-bus and runtime configs and make things easier in implementing B.A.T.M.A.N. gateway support --- naxalnet/config.py | 7 +++++++ naxalnet/default.py | 1 + naxalnet/network.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ naxalnet/scripts.py | 2 +- 4 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 naxalnet/network.py diff --git a/naxalnet/config.py b/naxalnet/config.py index ecbab00..e061678 100644 --- a/naxalnet/config.py +++ b/naxalnet/config.py @@ -170,6 +170,13 @@ def parse_args() -> Namespace: "-v", "--verbose", action="count", default=0, help="increase output verbosity" ) + parser.add_argument( + "--glob-mesh-configs", + type=str, + default=config["globs"]["meshconfigs"], + help="glob matching filenames for mesh configuration", + ) + # logger.debug("Parsing arguments") return parser.parse_args() diff --git a/naxalnet/default.py b/naxalnet/default.py index ecf3570..f28bc76 100644 --- a/naxalnet/default.py +++ b/naxalnet/default.py @@ -31,6 +31,7 @@ CONFIG = { "confdir": "/usr/share/naxalnet/networkd", "runtimedir": "/run/systemd/network", }, + "globs": {"meshconfigs": "mesh.*", "checkconfigs": "check.*"}, "adhoc": {"name": "NxMesh"}, "ap": {"ssid": "MeshWiFi", "passwd": "naxalnet256"}, } diff --git a/naxalnet/network.py b/naxalnet/network.py new file mode 100644 index 0000000..13574aa --- /dev/null +++ b/naxalnet/network.py @@ -0,0 +1,45 @@ +# This file is part of naxalnet. +# Copyright (C) 2021 The naxalnet Authors + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +""" +network.py +---------- + +This submodule manages the systemd-networkd configuration. +TODO: Add more details +""" + +from pathlib import Path +from shutil import copy +from dasbus.connection import SystemMessageBus + +NETWORKD_BUS = "org.freedesktop.network1" +NETWORKD_PATH = "/org/freedesktop/network1" + + +def copy_glob(directory: str, glob: str, destination: str) -> None: + """copy files in directory matching the glob to destination""" + match = Path(directory).glob(glob) + for i in match: + copy(i, destination) + + +class Networkd: + """control systemd-networkd""" + + def __init__(self, bus=SystemMessageBus()): + self._bus = bus + self.proxy = self._bus.get_proxy(NETWORKD_BUS, NETWORKD_PATH) diff --git a/naxalnet/scripts.py b/naxalnet/scripts.py index e201ca1..b448ac5 100644 --- a/naxalnet/scripts.py +++ b/naxalnet/scripts.py @@ -138,7 +138,7 @@ def setup_devices(): logger.error(REPORT_BUG_INFO) sys.exit(4) except: - logger.exception("An unknow error occured while setting up the mesh") + logger.exception("An unknown error occured while setting up the mesh") logger.error(REPORT_BUG_INFO) sys.exit(4)