Skip to content

Commit 3e51f2c

Browse files
committed
tools: ynl: add --list-ops and --list-msgs to CLI
I often forget the exact naming of ops and have to look at the spec to find it. Add support for listing the operations: $ ./cli.py --spec .../netdev.yaml --list-ops dev-get [ do, dump ] page-pool-get [ do, dump ] page-pool-stats-get [ do, dump ] queue-get [ do, dump ] napi-get [ do, dump ] qstats-get [ dump ] For completeness also support listing all ops (including notifications: # ./cli.py --spec .../netdev.yaml --list-msgs dev-get [ dump, do ] dev-add-ntf [ notify ] dev-del-ntf [ notify ] dev-change-ntf [ notify ] page-pool-get [ dump, do ] page-pool-add-ntf [ notify ] page-pool-del-ntf [ notify ] page-pool-change-ntf [ notify ] page-pool-stats-get [ dump, do ] queue-get [ dump, do ] napi-get [ dump, do ] qstats-get [ dump ] Use double space after the name for slightly easier to read output. Reviewed-by: Jiri Pirko <jiri@nvidia.com> Reviewed-by: Donald Hunter <donald.hunter@gmail.com> Link: https://lore.kernel.org/r/20240502164043.2130184-1-kuba@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent f3ad491 commit 3e51f2c

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

tools/net/ynl/cli.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ def main():
4040
group.add_argument('--multi', dest='multi', nargs=2, action='append',
4141
metavar=('DO-OPERATION', 'JSON_TEXT'), type=str)
4242
group.add_argument('--dump', dest='dump', metavar='DUMP-OPERATION', type=str)
43+
group.add_argument('--list-ops', action='store_true')
44+
group.add_argument('--list-msgs', action='store_true')
4345

4446
parser.add_argument('--sleep', dest='sleep', type=int)
4547
parser.add_argument('--subscribe', dest='ntf', type=str)
@@ -81,6 +83,13 @@ def output(msg):
8183
if args.sleep:
8284
time.sleep(args.sleep)
8385

86+
if args.list_ops:
87+
for op_name, op in ynl.ops.items():
88+
print(op_name, " [", ", ".join(op.modes), "]")
89+
if args.list_msgs:
90+
for op_name, op in ynl.msgs.items():
91+
print(op_name, " [", ", ".join(op.modes), "]")
92+
8493
try:
8594
if args.do:
8695
reply = ynl.do(args.do, attrs, args.flags)

tools/net/ynl/lib/nlspec.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ class SpecOperation(SpecElement):
335335
336336
req_value numerical ID when serialized, user -> kernel
337337
rsp_value numerical ID when serialized, user <- kernel
338+
modes supported operation modes (do, dump, event etc.)
338339
is_call bool, whether the operation is a call
339340
is_async bool, whether the operation is a notification
340341
is_resv bool, whether the operation does not exist (it's just a reserved ID)
@@ -350,6 +351,7 @@ def __init__(self, family, yaml, req_value, rsp_value):
350351
self.req_value = req_value
351352
self.rsp_value = rsp_value
352353

354+
self.modes = yaml.keys() & {'do', 'dump', 'event', 'notify'}
353355
self.is_call = 'do' in yaml or 'dump' in yaml
354356
self.is_async = 'notify' in yaml or 'event' in yaml
355357
self.is_resv = not self.is_async and not self.is_call

0 commit comments

Comments
 (0)