Commit 9ff7313f authored by Karol Latecki's avatar Karol Latecki Committed by Ben Walker
Browse files

scripts/rpc.py: pass named arguments in json rpc functions



Add docstrings while at it.

Change-Id: I2b723ae1f00d0a840a7498f5cabb6c33e60c652a
Signed-off-by: default avatarKarol Latecki <karol.latecki@intel.com>
Reviewed-on: https://review.gerrithub.io/419506


Reviewed-by: default avatarPawel Wodkowski <pawelx.wodkowski@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
parent 35411ae5
Loading
Loading
Loading
Loading
+13 −5
Original line number Diff line number Diff line
@@ -49,7 +49,8 @@ if __name__ == "__main__":

    @call_cmd
    def get_rpc_methods(args):
        print_dict(rpc.get_rpc_methods(args.client, args))
        print_dict(rpc.get_rpc_methods(args.client,
                                       current=args.current))

    p = subparsers.add_parser('get_rpc_methods', help='Get list of supported RPC methods')
    p.add_argument('-c', '--current', help='Get list of RPC methods only callable in the current state.', action='store_true')
@@ -57,7 +58,9 @@ if __name__ == "__main__":

    @call_cmd
    def save_config(args):
        rpc.save_config(args.client, args)
        rpc.save_config(args.client,
                        filename=args.filename,
                        indent=args.indent)

    p = subparsers.add_parser('save_config', help="""Write current (live) configuration of SPDK subsystems and targets.
    If no filename is given write configuration to stdout.""")
@@ -68,7 +71,8 @@ if __name__ == "__main__":

    @call_cmd
    def load_config(args):
        rpc.load_config(args.client, args)
        rpc.load_config(args.client,
                        filename=args.filename)

    p = subparsers.add_parser('load_config', help="""Configure SPDK subsystems and tagets using JSON RPC. If no file is
    provided or file is '-' read configuration from stdin.""")
@@ -77,7 +81,10 @@ if __name__ == "__main__":

    @call_cmd
    def save_subsystem_config(args):
        rpc.save_subsystem_config(args.client, args)
        rpc.save_subsystem_config(args.client,
                                  filename=args.filename,
                                  indent=args.indent,
                                  name=args.name)

    p = subparsers.add_parser('save_subsystem_config', help="""Write current (live) configuration of SPDK subsystem.
    If no filename is given write configuration to stdout.""")
@@ -89,7 +96,8 @@ if __name__ == "__main__":

    @call_cmd
    def load_subsystem_config(args):
        rpc.load_subsystem_config(args.client, args)
        rpc.load_subsystem_config(args.client,
                                  filename=args.filename)

    p = subparsers.add_parser('load_subsystem_config', help="""Configure SPDK subsystem using JSON RPC. If no file is
    provided or file is '-' read configuration from stdin.""")
+44 −13
Original line number Diff line number Diff line
@@ -17,14 +17,19 @@ from . import client as rpc_client


def start_subsystem_init(client):
    """Start initialization of subsystems"""
    return client.call('start_subsystem_init')


def get_rpc_methods(client, args):
def get_rpc_methods(client, current=None):
    """Get list of supported RPC methods.
    Args:
        current: Get list of RPC methods only callable in the current state.
    """
    params = {}

    if args.current:
        params['current'] = args.current
    if current:
        params['current'] = current

    return client.call('get_rpc_methods', params)

@@ -54,7 +59,15 @@ def _json_load(filename):
            return json.load(file)


def save_config(client, args):
def save_config(client, filename=None, indent=2):
    """Write current (live) configuration of SPDK subsystems and targets.
    Args:
        filename: File where to save JSON configuration to.
            Print to stdout if not provided.
        indent: Indent level. Value less than 0 mean compact mode.
            If filename is not given default then indent level is 2.
            If writing to file of filename is '-' then default is compact mode.
    """
    config = {
        'subsystems': []
    }
@@ -66,11 +79,16 @@ def save_config(client, args):
        }
        config['subsystems'].append(cfg)

    _json_dump(config, args.filename, args.indent)
    _json_dump(config, filename, indent)


def load_config(client, args):
    json_config = _json_load(args.filename)
def load_config(client, filename=None):
    """Configure SPDK subsystems and tagets using JSON RPC.
    Args:
        filename: JSON Configuration file location.
            If no file path is provided or file is '-' then read configuration from stdin.
    """
    json_config = _json_load(filename)

    # remove subsystems with no config
    subsystems = json_config['subsystems']
@@ -114,17 +132,30 @@ def load_config(client, args):
        print("Some configs were skipped because the RPC state that can call them passed over.")


def save_subsystem_config(client, args):
def save_subsystem_config(client, filename=None, indent=2, name=None):
    """Write current (live) configuration of SPDK subsystem.
    Args:
        filename: File where to save JSON configuration to.
            Print to stdout if not provided.
        indent: Indent level. Value less than 0 mean compact mode.
            If filename is not given default then indent level is 2.
            If writing to file of filename is '-' then default is compact mode.
    """
    cfg = {
        'subsystem': args.name,
        'config': client.call('get_subsystem_config', {"name": args.name})
        'subsystem': name,
        'config': client.call('get_subsystem_config', {"name": name})
    }

    _json_dump(cfg, args.filename, args.indent)
    _json_dump(cfg, filename, indent)


def load_subsystem_config(client, args):
    subsystem = _json_load(args.filename)
def load_subsystem_config(client, filename=None):
    """Configure SPDK subsystem using JSON RPC.
    Args:
        filename: JSON Configuration file location.
            If no file path is provided or file is '-' then read configuration from stdin.
    """
    subsystem = _json_load(filename)

    if not subsystem['config']:
        return