added func for parsing and writing networkd config

This commit is contained in:
Pranav Jerry 2021-09-26 13:57:40 +05:30
parent 8f905ed970
commit ab3252683a
No known key found for this signature in database
GPG Key ID: F1DCDC4FED0A0C5B
2 changed files with 11 additions and 3 deletions

View File

@ -170,7 +170,6 @@ def parse_args() -> Namespace:
"-v", "--verbose", action="count", default=0, help="increase output verbosity" "-v", "--verbose", action="count", default=0, help="increase output verbosity"
) )
# logger.debug("Parsing arguments")
return parser.parse_args() return parser.parse_args()

View File

@ -25,6 +25,7 @@ TODO: Add more details
from pathlib import Path from pathlib import Path
from shutil import copy from shutil import copy
from dasbus.connection import SystemMessageBus from dasbus.connection import SystemMessageBus
from naxalnet.config import args
NETWORKD_BUS = "org.freedesktop.network1" NETWORKD_BUS = "org.freedesktop.network1"
NETWORKD_PATH = "/org/freedesktop/network1" NETWORKD_PATH = "/org/freedesktop/network1"
@ -43,10 +44,18 @@ class Networkd:
def __init__(self, bus=SystemMessageBus()): def __init__(self, bus=SystemMessageBus()):
self._bus = bus self._bus = bus
self.proxy_reload() self.proxy_reload()
self.files = []
self.variables = {"batdev": "bat0", "bridgedev": "bridge0"}
def proxy_reload(self): def proxy_reload(self) -> None:
"""reload the proxy""" """reload the proxy"""
self.proxy = self._bus.get_proxy(NETWORKD_BUS, NETWORKD_PATH) 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""" """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"
)