Commit b0bac20a authored by Maciej Szwed's avatar Maciej Szwed Committed by Tomasz Zawadzki
Browse files

rpc: Add possibility to load module with additional RPC commands



This patch adds '--plugin <module_name>' parameter
to rpc.py script which is used to provide module
name with additional RPC commands that should be
included in rpc.py script. User must export path
to rpc module with PYTHONPATH before calling rpc.py
with this new parameter.

Signed-off-by: default avatarMaciej Szwed <maciej.szwed@intel.com>
Change-Id: I971429a33cf4ea943d2b7f3abd5a6cb82398d2a4

Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/2263


Community-CI: Mellanox Build Bot
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent 8cc72fe4
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ from rpc.helpers import deprecated_aliases

import logging
import argparse
import importlib
import rpc
import sys
import shlex
@@ -45,6 +46,7 @@ if __name__ == "__main__":
                                pipes and can be used as a faster way to send RPC commands. If enabled, rpc.py \
                                must be executed without any other parameters.")
    parser.set_defaults(is_server=False)
    parser.add_argument('--plugin', dest='rpc_plugin', help='Module name of plugin with additional RPC commands')
    subparsers = parser.add_subparsers(help='RPC methods', dest='called_rpc_name', metavar='')

    def framework_start_init(args):
@@ -2401,6 +2403,21 @@ Format: 'user:u1 secret:s1 muser:mu1 msecret:ms1,user:u2 secret:s2 muser:mu2 mse
                print(ex.message)
                exit(1)

    # Create temporary parser, pull out the plugin parameter, load the module, and then run the real argument parser
    plugin_parser = argparse.ArgumentParser(add_help=False)
    plugin_parser.add_argument('--plugin', dest='rpc_plugin', help='Module name of plugin with additional RPC commands')

    rpc_module = plugin_parser.parse_known_args()[0].rpc_plugin
    if rpc_module is not None:
        try:
            rpc_plugin = importlib.import_module(rpc_module)
            try:
                rpc_plugin.spdk_rpc_plugin_initialize(subparsers)
            except AttributeError:
                print("Module %s does not contain 'spdk_rpc_plugin_initialize' function" % rpc_module)
        except ModuleNotFoundError:
            print("Module %s not found" % rpc_module)

    args = parser.parse_args()

    if sys.stdin.isatty() and not hasattr(args, 'func'):