diff mbox series

[net-next] tools: ynl: add --list-ops and --list-msgs to CLI

Message ID 20240502164043.2130184-1-kuba@kernel.org (mailing list archive)
State Accepted
Commit 3e51f2cbbc5dc854f89ca37d95d295bfcabb5b43
Delegated to: Netdev Maintainers
Headers show
Series [net-next] tools: ynl: add --list-ops and --list-msgs to CLI | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 8 this patch: 8
netdev/build_tools success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 5 of 5 maintainers
netdev/build_clang success Errors and warnings before: 8 this patch: 8
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 8 this patch: 8
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 35 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-05-03--15-00 (tests: 1001)

Commit Message

Jakub Kicinski May 2, 2024, 4:40 p.m. UTC
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.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
CC: donald.hunter@gmail.com
CC: jiri@resnulli.us
CC: alessandromarcolini99@gmail.com
---
 tools/net/ynl/cli.py        | 9 +++++++++
 tools/net/ynl/lib/nlspec.py | 2 ++
 2 files changed, 11 insertions(+)

Comments

Jiri Pirko May 2, 2024, 4:57 p.m. UTC | #1
Thu, May 02, 2024 at 06:40:43PM CEST, kuba@kernel.org wrote:
>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.
>
>Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Had that on my todo list :) Thanks!

Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Donald Hunter May 3, 2024, 10:17 a.m. UTC | #2
Jakub Kicinski <kuba@kernel.org> writes:

> 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.
>
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Reviewed-by: Donald Hunter <donald.hunter@gmail.com>
patchwork-bot+netdevbpf@kernel.org May 3, 2024, 10:40 p.m. UTC | #3
Hello:

This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Thu,  2 May 2024 09:40:43 -0700 you wrote:
> 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 ]
> 
> [...]

Here is the summary with links:
  - [net-next] tools: ynl: add --list-ops and --list-msgs to CLI
    https://git.kernel.org/netdev/net-next/c/3e51f2cbbc5d

You are awesome, thank you!
diff mbox series

Patch

diff --git a/tools/net/ynl/cli.py b/tools/net/ynl/cli.py
index 058926d69ef0..b8481f401376 100755
--- a/tools/net/ynl/cli.py
+++ b/tools/net/ynl/cli.py
@@ -40,6 +40,8 @@  from lib import YnlFamily, Netlink, NlError
     group.add_argument('--multi', dest='multi', nargs=2, action='append',
                        metavar=('DO-OPERATION', 'JSON_TEXT'), type=str)
     group.add_argument('--dump', dest='dump', metavar='DUMP-OPERATION', type=str)
+    group.add_argument('--list-ops', action='store_true')
+    group.add_argument('--list-msgs', action='store_true')
 
     parser.add_argument('--sleep', dest='sleep', type=int)
     parser.add_argument('--subscribe', dest='ntf', type=str)
@@ -81,6 +83,13 @@  from lib import YnlFamily, Netlink, NlError
     if args.sleep:
         time.sleep(args.sleep)
 
+    if args.list_ops:
+        for op_name, op in ynl.ops.items():
+            print(op_name, " [", ", ".join(op.modes), "]")
+    if args.list_msgs:
+        for op_name, op in ynl.msgs.items():
+            print(op_name, " [", ", ".join(op.modes), "]")
+
     try:
         if args.do:
             reply = ynl.do(args.do, attrs, args.flags)
diff --git a/tools/net/ynl/lib/nlspec.py b/tools/net/ynl/lib/nlspec.py
index 6d08ab9e213f..b6d6f8aef423 100644
--- a/tools/net/ynl/lib/nlspec.py
+++ b/tools/net/ynl/lib/nlspec.py
@@ -335,6 +335,7 @@  jsonschema = None
 
         req_value       numerical ID when serialized, user -> kernel
         rsp_value       numerical ID when serialized, user <- kernel
+        modes           supported operation modes (do, dump, event etc.)
         is_call         bool, whether the operation is a call
         is_async        bool, whether the operation is a notification
         is_resv         bool, whether the operation does not exist (it's just a reserved ID)
@@ -350,6 +351,7 @@  jsonschema = None
         self.req_value = req_value
         self.rsp_value = rsp_value
 
+        self.modes = yaml.keys() & {'do', 'dump', 'event', 'notify'}
         self.is_call = 'do' in yaml or 'dump' in yaml
         self.is_async = 'notify' in yaml or 'event' in yaml
         self.is_resv = not self.is_async and not self.is_call