Spdk/scripts/rpc/__init__.py
Daniel Verkamp df897ed490 scripts/rpc.py: move printing into main rpc.py
The modules in scripts/rpc/*.py should be a generic, reusable library;
the printing should be done by the command-line frontend (rpc.py)
instead of the library code.

Change-Id: Ibeb022a3591f0a140fc43104d8dcf17d7041e48b
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-on: https://review.gerrithub.io/404426
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
2018-03-26 00:57:53 -04:00

62 lines
1.4 KiB
Python
Executable File

import app
import bdev
import iscsi
import log
import lvol
import nbd
import net
import nvmf
import pmem
import subsystem
import vhost
import json
import sys
def get_rpc_methods(args):
return 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'])