nft-update-addresses: extract kickoff_ip from monitor_ip

main
Felix Stupp 1 month ago
parent 52ddde1d6a
commit 84fc26d1dc
Signed by: zocker
GPG Key ID: 93E1BD26F6B02FB7

@ -271,17 +271,10 @@ class IpAddressUpdate:
) )
def monitor_ip( def kickoff_ip(
ip_cmd: list[str], ip_cmd: list[str],
handler: UpdateHandler[IpAddressUpdate], handler: UpdateHandler[IpAddressUpdate],
) -> NoReturn: ) -> None:
proc = subprocess.Popen(
ip_cmd + ["-o", "monitor", "address"],
stdout=subprocess.PIPE,
text=True,
)
# initial kickoff (AFTER starting monitoring, to not miss any update)
logger.info("kickoff IP monitoring with current data")
res = subprocess.run( res = subprocess.run(
ip_cmd + ["-o", "address", "show"], ip_cmd + ["-o", "address", "show"],
check=True, check=True,
@ -295,7 +288,21 @@ def monitor_ip(
update = IpAddressUpdate.parse_line(line) update = IpAddressUpdate.parse_line(line)
logger.debug(f"pass IP update: {update!r}") logger.debug(f"pass IP update: {update!r}")
handler.update(update) handler.update(update)
logger.info("loading kickoff finished; start regular monitoring")
def monitor_ip(
ip_cmd: list[str],
handler: UpdateHandler[IpAddressUpdate],
) -> NoReturn:
proc = subprocess.Popen(
ip_cmd + ["-o", "monitor", "address"],
stdout=subprocess.PIPE,
text=True,
)
# initial kickoff (AFTER starting monitoring, to not miss any update)
logger.info("kickoff IP monitoring with current data")
kickoff_ip(ip_cmd, handler)
logger.info("start regular monitoring")
while True: while True:
rc = proc.poll() rc = proc.poll()
if rc != None: if rc != None:

Loading…
Cancel
Save