Skip to content

Commit e4b48ed

Browse files
kuba-mooPaolo Abeni
authored andcommitted
tools: ynl: add a completely generic client
Add a CLI sample which can take in arbitrary request in JSON format, convert it to Netlink and do the inverse for output. It's meant as a development tool primarily and perhaps for selftests which need to tickle netlink in a special way. Acked-by: Stanislav Fomichev <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
1 parent 1d562c3 commit e4b48ed

File tree

2 files changed

+581
-0
lines changed

2 files changed

+581
-0
lines changed

tools/net/ynl/samples/cli.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env python
2+
# SPDX-License-Identifier: BSD-3-Clause
3+
4+
import argparse
5+
import json
6+
import pprint
7+
import time
8+
9+
from ynl import YnlFamily
10+
11+
12+
def main():
13+
parser = argparse.ArgumentParser(description='YNL CLI sample')
14+
parser.add_argument('--spec', dest='spec', type=str, required=True)
15+
parser.add_argument('--schema', dest='schema', type=str)
16+
parser.add_argument('--json', dest='json_text', type=str)
17+
parser.add_argument('--do', dest='do', type=str)
18+
parser.add_argument('--dump', dest='dump', type=str)
19+
parser.add_argument('--sleep', dest='sleep', type=int)
20+
parser.add_argument('--subscribe', dest='ntf', type=str)
21+
args = parser.parse_args()
22+
23+
attrs = {}
24+
if args.json_text:
25+
attrs = json.loads(args.json_text)
26+
27+
ynl = YnlFamily(args.spec, args.schema)
28+
29+
if args.ntf:
30+
ynl.ntf_subscribe(args.ntf)
31+
32+
if args.sleep:
33+
time.sleep(args.sleep)
34+
35+
if args.do or args.dump:
36+
method = getattr(ynl, args.do if args.do else args.dump)
37+
38+
reply = method(attrs, dump=bool(args.dump))
39+
pprint.PrettyPrinter().pprint(reply)
40+
41+
if args.ntf:
42+
ynl.check_ntf()
43+
pprint.PrettyPrinter().pprint(ynl.async_msg_queue)
44+
45+
46+
if __name__ == "__main__":
47+
main()

0 commit comments

Comments
 (0)