14e4480e8SJakub Kicinski#!/usr/bin/env python 24e4480e8SJakub Kicinski# SPDX-License-Identifier: BSD-3-Clause 34e4480e8SJakub Kicinski 44e4480e8SJakub Kicinskiimport argparse 54e4480e8SJakub Kicinskiimport json 64e4480e8SJakub Kicinskiimport pprint 74e4480e8SJakub Kicinskiimport time 84e4480e8SJakub Kicinski 94e4480e8SJakub Kicinskifrom lib import YnlFamily 104e4480e8SJakub Kicinski 114e4480e8SJakub Kicinski 124e4480e8SJakub Kicinskidef main(): 134e4480e8SJakub Kicinski parser = argparse.ArgumentParser(description='YNL CLI sample') 144e4480e8SJakub Kicinski parser.add_argument('--spec', dest='spec', type=str, required=True) 154e4480e8SJakub Kicinski parser.add_argument('--schema', dest='schema', type=str) 164e4480e8SJakub Kicinski parser.add_argument('--json', dest='json_text', type=str) 174e4480e8SJakub Kicinski parser.add_argument('--do', dest='do', type=str) 184e4480e8SJakub Kicinski parser.add_argument('--dump', dest='dump', type=str) 194e4480e8SJakub Kicinski parser.add_argument('--sleep', dest='sleep', type=int) 204e4480e8SJakub Kicinski parser.add_argument('--subscribe', dest='ntf', type=str) 214e4480e8SJakub Kicinski args = parser.parse_args() 224e4480e8SJakub Kicinski 234e4480e8SJakub Kicinski attrs = {} 244e4480e8SJakub Kicinski if args.json_text: 254e4480e8SJakub Kicinski attrs = json.loads(args.json_text) 264e4480e8SJakub Kicinski 274e4480e8SJakub Kicinski ynl = YnlFamily(args.spec, args.schema) 284e4480e8SJakub Kicinski 294e4480e8SJakub Kicinski if args.ntf: 304e4480e8SJakub Kicinski ynl.ntf_subscribe(args.ntf) 314e4480e8SJakub Kicinski 324e4480e8SJakub Kicinski if args.sleep: 334e4480e8SJakub Kicinski time.sleep(args.sleep) 344e4480e8SJakub Kicinski 35*8dfec0a8SJakub Kicinski if args.do: 36*8dfec0a8SJakub Kicinski reply = ynl.do(args.do, attrs) 37*8dfec0a8SJakub Kicinski pprint.PrettyPrinter().pprint(reply) 38*8dfec0a8SJakub Kicinski if args.dump: 39*8dfec0a8SJakub Kicinski reply = ynl.dump(args.dump, attrs) 404e4480e8SJakub Kicinski pprint.PrettyPrinter().pprint(reply) 414e4480e8SJakub Kicinski 424e4480e8SJakub Kicinski if args.ntf: 434e4480e8SJakub Kicinski ynl.check_ntf() 444e4480e8SJakub Kicinski pprint.PrettyPrinter().pprint(ynl.async_msg_queue) 454e4480e8SJakub Kicinski 464e4480e8SJakub Kicinski 474e4480e8SJakub Kicinskiif __name__ == "__main__": 484e4480e8SJakub Kicinski main() 49