~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/net/ynl/cli.py

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /tools/net/ynl/cli.py (Version linux-6.12-rc7) and /tools/net/ynl/cli.py (Version linux-6.8.12)


  1 #!/usr/bin/env python3                              1 #!/usr/bin/env python3
  2 # SPDX-License-Identifier: GPL-2.0 OR BSD-3-Cl      2 # SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
  3                                                     3 
  4 import argparse                                     4 import argparse
  5 import json                                         5 import json
  6 import pprint                                       6 import pprint
  7 import time                                         7 import time
  8                                                     8 
  9 from lib import YnlFamily, Netlink, NlError    !!   9 from lib import YnlFamily, Netlink
 10                                                << 
 11                                                << 
 12 class YnlEncoder(json.JSONEncoder):            << 
 13     def default(self, obj):                    << 
 14         if isinstance(obj, bytes):             << 
 15             return bytes.hex(obj)              << 
 16         if isinstance(obj, set):               << 
 17             return list(obj)                   << 
 18         return json.JSONEncoder.default(self,  << 
 19                                                    10 
 20                                                    11 
 21 def main():                                        12 def main():
 22     description = """                          !!  13     parser = argparse.ArgumentParser(description='YNL CLI sample')
 23     YNL CLI utility - a general purpose netlin << 
 24     specs to drive protocol encoding and decod << 
 25     """                                        << 
 26     epilog = """                               << 
 27     The --multi option can be repeated to incl << 
 28     in the same netlink payload.               << 
 29     """                                        << 
 30                                                << 
 31     parser = argparse.ArgumentParser(descripti << 
 32                                      epilog=ep << 
 33     parser.add_argument('--spec', dest='spec',     14     parser.add_argument('--spec', dest='spec', type=str, required=True)
 34     parser.add_argument('--schema', dest='sche     15     parser.add_argument('--schema', dest='schema', type=str)
 35     parser.add_argument('--no-schema', action=     16     parser.add_argument('--no-schema', action='store_true')
 36     parser.add_argument('--json', dest='json_t     17     parser.add_argument('--json', dest='json_text', type=str)
 37                                                !!  18     parser.add_argument('--do', dest='do', type=str)
 38     group = parser.add_mutually_exclusive_grou !!  19     parser.add_argument('--dump', dest='dump', type=str)
 39     group.add_argument('--do', dest='do', meta << 
 40     group.add_argument('--multi', dest='multi' << 
 41                        metavar=('DO-OPERATION' << 
 42     group.add_argument('--dump', dest='dump',  << 
 43     group.add_argument('--list-ops', action='s << 
 44     group.add_argument('--list-msgs', action=' << 
 45                                                << 
 46     parser.add_argument('--sleep', dest='sleep     20     parser.add_argument('--sleep', dest='sleep', type=int)
 47     parser.add_argument('--subscribe', dest='n     21     parser.add_argument('--subscribe', dest='ntf', type=str)
 48     parser.add_argument('--replace', dest='fla     22     parser.add_argument('--replace', dest='flags', action='append_const',
 49                         const=Netlink.NLM_F_RE     23                         const=Netlink.NLM_F_REPLACE)
 50     parser.add_argument('--excl', dest='flags'     24     parser.add_argument('--excl', dest='flags', action='append_const',
 51                         const=Netlink.NLM_F_EX     25                         const=Netlink.NLM_F_EXCL)
 52     parser.add_argument('--create', dest='flag     26     parser.add_argument('--create', dest='flags', action='append_const',
 53                         const=Netlink.NLM_F_CR     27                         const=Netlink.NLM_F_CREATE)
 54     parser.add_argument('--append', dest='flag     28     parser.add_argument('--append', dest='flags', action='append_const',
 55                         const=Netlink.NLM_F_AP     29                         const=Netlink.NLM_F_APPEND)
 56     parser.add_argument('--process-unknown', a     30     parser.add_argument('--process-unknown', action=argparse.BooleanOptionalAction)
 57     parser.add_argument('--output-json', actio << 
 58     parser.add_argument('--dbg-small-recv', de << 
 59                         action='store', nargs= << 
 60     args = parser.parse_args()                     31     args = parser.parse_args()
 61                                                    32 
 62     def output(msg):                           << 
 63         if args.output_json:                   << 
 64             print(json.dumps(msg, cls=YnlEncod << 
 65         else:                                  << 
 66             pprint.PrettyPrinter().pprint(msg) << 
 67                                                << 
 68     if args.no_schema:                             33     if args.no_schema:
 69         args.schema = ''                           34         args.schema = ''
 70                                                    35 
 71     attrs = {}                                     36     attrs = {}
 72     if args.json_text:                             37     if args.json_text:
 73         attrs = json.loads(args.json_text)         38         attrs = json.loads(args.json_text)
 74                                                    39 
 75     ynl = YnlFamily(args.spec, args.schema, ar !!  40     ynl = YnlFamily(args.spec, args.schema, args.process_unknown)
 76                     recv_size=args.dbg_small_r << 
 77     if args.dbg_small_recv:                    << 
 78         ynl.set_recv_dbg(True)                 << 
 79                                                    41 
 80     if args.ntf:                                   42     if args.ntf:
 81         ynl.ntf_subscribe(args.ntf)                43         ynl.ntf_subscribe(args.ntf)
 82                                                    44 
 83     if args.sleep:                                 45     if args.sleep:
 84         time.sleep(args.sleep)                     46         time.sleep(args.sleep)
 85                                                    47 
 86     if args.list_ops:                          !!  48     if args.do:
 87         for op_name, op in ynl.ops.items():    !!  49         reply = ynl.do(args.do, attrs, args.flags)
 88             print(op_name, " [", ", ".join(op. !!  50         pprint.PrettyPrinter().pprint(reply)
 89     if args.list_msgs:                         !!  51     if args.dump:
 90         for op_name, op in ynl.msgs.items():   !!  52         reply = ynl.dump(args.dump, attrs)
 91             print(op_name, " [", ", ".join(op. !!  53         pprint.PrettyPrinter().pprint(reply)
 92                                                << 
 93     try:                                       << 
 94         if args.do:                            << 
 95             reply = ynl.do(args.do, attrs, arg << 
 96             output(reply)                      << 
 97         if args.dump:                          << 
 98             reply = ynl.dump(args.dump, attrs) << 
 99             output(reply)                      << 
100         if args.multi:                         << 
101             ops = [ (item[0], json.loads(item[ << 
102             reply = ynl.do_multi(ops)          << 
103             output(reply)                      << 
104     except NlError as e:                       << 
105         print(e)                               << 
106         exit(1)                                << 
107                                                    54 
108     if args.ntf:                                   55     if args.ntf:
109         ynl.check_ntf()                            56         ynl.check_ntf()
110         output(ynl.async_msg_queue)            !!  57         pprint.PrettyPrinter().pprint(ynl.async_msg_queue)
111                                                    58 
112                                                    59 
113 if __name__ == "__main__":                         60 if __name__ == "__main__":
114     main()                                         61     main()
                                                      

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php