implemented NetworkLoop call in scripts.py

See any_interface_is_routable()
This commit is contained in:
Pranav Jerry 2021-11-14 19:46:04 +05:30
parent cd44357496
commit caeb042612
No known key found for this signature in database
GPG Key ID: F1DCDC4FED0A0C5B
2 changed files with 5 additions and 8 deletions

View File

@ -42,4 +42,4 @@ given below.
# #
# In case you forgot to change the version, skip the number # In case you forgot to change the version, skip the number
# and put the next number in the next commit. # and put the next number in the next commit.
__version__ = "0.5.1a0.dev2" __version__ = "0.5.1a0.dev3"

View File

@ -37,7 +37,7 @@ from naxalnet.log import logger
from naxalnet.iwd import Adapter, Device, IWD from naxalnet.iwd import Adapter, Device, IWD
from naxalnet.config import args from naxalnet.config import args
from naxalnet.daemon import Daemon from naxalnet.daemon import Daemon
from naxalnet.network import NetworkD from naxalnet.network import NetworkD, NetworkLoop
def get_sorted_glob(directory: str, glob: str) -> list: def get_sorted_glob(directory: str, glob: str) -> list:
@ -56,17 +56,14 @@ def get_sorted_glob(directory: str, glob: str) -> list:
def any_interface_is_routable(): def any_interface_is_routable():
"""returns true if any of the interfaces is routable""" """returns true if any of the interfaces is routable"""
networkd = NetworkD(runtime_dir=args.networkd_runtime_dir) networkd = NetworkLoop(runtime_dir=args.networkd_runtime_dir)
# First, add the temporary configs to networkd. # First, add the temporary configs to networkd.
for i in get_sorted_glob(args.networkd_config_dir, TMP_NET_GLOB): for i in get_sorted_glob(args.networkd_config_dir, TMP_NET_GLOB):
logger.debug("Adding temporary config %s", i) logger.debug("Adding temporary config %s", i)
networkd.add_config(i) networkd.add_config(i)
# Then, wait for some time to setup the network.
# This can probably be replaced by a d-bus wait-for-signal routable = networkd.wait_until_routable()
# function that timeouts after 10 seconds.
time.sleep(10)
routable = networkd.is_routable()
networkd.remove_all_configs() networkd.remove_all_configs()
return routable return routable