scripts/rpc: add configuration save and load
Change-Id: I37f2174fd6c3092b25e127a4cd578d202ee8c98a Signed-off-by: Pawel Wodkowski <pawelx.wodkowski@intel.com> Reviewed-on: https://review.gerrithub.io/403351 Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
This commit is contained in:
parent
bd4ecea505
commit
50d738b447
@ -21,6 +21,18 @@ if __name__ == "__main__":
|
||||
p = subparsers.add_parser('get_rpc_methods', help='Get list of supported RPC methods')
|
||||
p.set_defaults(func=rpc.get_rpc_methods)
|
||||
|
||||
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.""")
|
||||
p.add_argument('-f', '--filename', help="""File where to save JSON configuration to.""")
|
||||
p.add_argument('-i', '--indent', help="""Indent level. Value less than 0 mean compact mode. If filename is not given default
|
||||
indent level is 2. If writing to file of filename is '-' then default is compact mode.""", type=int, default=2)
|
||||
p.set_defaults(func=rpc.save_config)
|
||||
|
||||
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.""")
|
||||
p.add_argument('--filename', help="""JSON Configuration file.""")
|
||||
p.set_defaults(func=rpc.load_config)
|
||||
|
||||
# app
|
||||
p = subparsers.add_parser('kill_instance', help='Send signal to instance')
|
||||
p.add_argument('sig_name', help='signal will be sent to server.')
|
||||
|
@ -10,7 +10,53 @@ import nvmf
|
||||
import pmem
|
||||
import subsystem
|
||||
import vhost
|
||||
import json
|
||||
import sys
|
||||
|
||||
|
||||
def get_rpc_methods(args):
|
||||
print_dict(args.client.call('get_rpc_methods'))
|
||||
|
||||
|
||||
def save_config(args):
|
||||
config = {
|
||||
'subsystems': []
|
||||
}
|
||||
|
||||
for elem in args.client.call('get_subsystems'):
|
||||
cfg = {
|
||||
'subsystem': elem['subsystem'],
|
||||
'config': args.client.call('get_subsystem_config', {"name": elem['subsystem']})
|
||||
}
|
||||
config['subsystems'].append(cfg)
|
||||
|
||||
indent = args.indent
|
||||
if args.filename is None:
|
||||
if indent is None:
|
||||
indent = 2
|
||||
elif indent < 0:
|
||||
indent = None
|
||||
json.dump(config, sys.stdout, indent=indent)
|
||||
sys.stdout.write('\n')
|
||||
else:
|
||||
if indent is None or indent < 0:
|
||||
indent = None
|
||||
with open(args.filename, 'w') as file:
|
||||
json.dump(config, file, indent=indent)
|
||||
file.write('\n')
|
||||
|
||||
|
||||
def load_config(args):
|
||||
if not args.filename or args.filename == '-':
|
||||
config = json.load(sys.stdin)
|
||||
else:
|
||||
with open(args.filename, 'r') as file:
|
||||
config = json.load(file)
|
||||
|
||||
for subsystem in config['subsystems']:
|
||||
name = subsystem['subsystem']
|
||||
config = subsystem['config']
|
||||
if not config:
|
||||
continue
|
||||
for elem in subsystem['config']:
|
||||
args.client.call(elem['method'], elem['params'])
|
||||
|
Loading…
Reference in New Issue
Block a user