2018-03-09 20:19:34 +00:00
|
|
|
import json
|
|
|
|
import sys
|
2017-06-06 21:22:03 +00:00
|
|
|
|
2018-03-20 00:37:58 +00:00
|
|
|
from . import app
|
|
|
|
from . import bdev
|
|
|
|
from . import iscsi
|
|
|
|
from . import log
|
|
|
|
from . import lvol
|
|
|
|
from . import nbd
|
|
|
|
from . import net
|
|
|
|
from . import nvmf
|
|
|
|
from . import pmem
|
|
|
|
from . import subsystem
|
|
|
|
from . import vhost
|
|
|
|
|
2017-06-06 21:22:03 +00:00
|
|
|
|
2018-03-27 21:31:52 +00:00
|
|
|
def get_rpc_methods(client):
|
|
|
|
return client.call('get_rpc_methods')
|
2018-03-09 20:19:34 +00:00
|
|
|
|
|
|
|
|
2018-03-27 21:31:52 +00:00
|
|
|
def save_config(client, args):
|
2018-03-09 20:19:34 +00:00
|
|
|
config = {
|
|
|
|
'subsystems': []
|
|
|
|
}
|
|
|
|
|
2018-03-27 21:31:52 +00:00
|
|
|
for elem in client.call('get_subsystems'):
|
2018-03-09 20:19:34 +00:00
|
|
|
cfg = {
|
|
|
|
'subsystem': elem['subsystem'],
|
2018-03-27 21:31:52 +00:00
|
|
|
'config': client.call('get_subsystem_config', {"name": elem['subsystem']})
|
2018-03-09 20:19:34 +00:00
|
|
|
}
|
|
|
|
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')
|
|
|
|
|
|
|
|
|
2018-04-03 06:12:36 +00:00
|
|
|
def load_config(client, args):
|
2018-03-09 20:19:34 +00:00
|
|
|
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']:
|
2018-04-05 20:40:14 +00:00
|
|
|
if not elem or 'method' not in elem:
|
2018-04-04 15:29:54 +00:00
|
|
|
continue
|
2018-03-27 21:31:52 +00:00
|
|
|
client.call(elem['method'], elem['params'])
|