mirror of
https://git.disroot.org/pranav/pybatmesh.git
synced 2024-12-28 19:10:28 +05:30
added func for parsing and writing networkd config
This commit is contained in:
parent
8f905ed970
commit
ab3252683a
@ -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()
|
||||||
|
|
||||||
|
|
||||||
|
@ -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"
|
||||||
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user