]> www.infradead.org Git - users/dwmw2/linux.git/commit
tools/net/ynl: add async notification handling
authorDonald Hunter <donald.hunter@gmail.com>
Wed, 13 Nov 2024 09:08:43 +0000 (09:08 +0000)
committerJakub Kicinski <kuba@kernel.org>
Fri, 15 Nov 2024 02:09:06 +0000 (18:09 -0800)
commit8aefcfa04beaab070a2009828da40bdd4888eee6
tree524f0b3b6b7d50d38898f3f8fcf5e1fe4ce3286f
parentcef009cc4a76c5bfd28d68eab2b3273243fddcdc
tools/net/ynl: add async notification handling

The notification handling in ynl is currently very simple, using sleep()
to wait a period of time and then handling all the buffered messages in
a single batch.

This patch adds async notification handling so that messages can be
processed as they are received. This makes it possible to use ynl as a
library that supplies notifications in a timely manner.

- Add poll_ntf() to be a generator that yields 1 notification at a
  time and blocks until a notification is available.
- Add a --duration parameter to the CLI, with --sleep as an alias.

./tools/net/ynl/cli.py \
    --spec <SPEC> --subscribe <TOPIC> [ --duration <SECS> ]

The cli will report any notifications for duration seconds and then
exit. If duration is not specified, then it will poll forever, until
interrupted.

Here is an example python snippet that shows how to use ynl as a library
for receiving notifications:

    ynl = YnlFamily(f"{dir}/rt_route.yaml")
    ynl.ntf_subscribe('rtnlgrp-ipv4-route')

    for event in ynl.poll_ntf():
        handle(event)

Signed-off-by: Donald Hunter <donald.hunter@gmail.com>
Link: https://patch.msgid.link/20241113090843.72917-3-donald.hunter@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
tools/net/ynl/cli.py
tools/net/ynl/lib/ynl.py