From ab3252683ad0abd8d3330dd32e17f81db80a8cfc Mon Sep 17 00:00:00 2001 From: Pranav Jerry Date: Sun, 26 Sep 2021 13:57:40 +0530 Subject: [PATCH] added func for parsing and writing networkd config --- naxalnet/config.py | 1 - naxalnet/network.py | 13 +++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/naxalnet/config.py b/naxalnet/config.py index ecbab00..7a77b60 100644 --- a/naxalnet/config.py +++ b/naxalnet/config.py @@ -170,7 +170,6 @@ def parse_args() -> Namespace: "-v", "--verbose", action="count", default=0, help="increase output verbosity" ) - # logger.debug("Parsing arguments") return parser.parse_args() diff --git a/naxalnet/network.py b/naxalnet/network.py index dee26e0..16bd6c0 100644 --- a/naxalnet/network.py +++ b/naxalnet/network.py @@ -25,6 +25,7 @@ TODO: Add more details from pathlib import Path from shutil import copy from dasbus.connection import SystemMessageBus +from naxalnet.config import args NETWORKD_BUS = "org.freedesktop.network1" NETWORKD_PATH = "/org/freedesktop/network1" @@ -43,10 +44,18 @@ class Networkd: def __init__(self, bus=SystemMessageBus()): self._bus = bus self.proxy_reload() + self.files = [] + self.variables = {"batdev": "bat0", "bridgedev": "bridge0"} - def proxy_reload(self): + def proxy_reload(self) -> None: """reload the proxy""" self.proxy = self._bus.get_proxy(NETWORKD_BUS, NETWORKD_PATH) - def add_config(self, path: str): + def add_config(self, name: str) -> None: """add config file to runtime directory and reload networkd""" + text = Path(name).read_text(encoding="utf-8") + contents = text.format(**self.variables) + self.files.append(name) + Path(args.networkd_runtime_dir + "/" + name).write_text( + contents, encoding="utf-8" + )