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

122 lines
3.0 KiB
Python
Executable File

def get_nvmf_subsystems(args):
return args.client.call('get_nvmf_subsystems')
def construct_nvmf_subsystem(args):
params = {
'nqn': args.nqn,
'serial_number': args.serial_number,
}
if args.listen:
params['listen_addresses'] = [dict(u.split(":", 1) for u in a.split(" "))
for a in args.listen.split(",")]
if args.hosts:
hosts = []
for u in args.hosts.strip().split(" "):
hosts.append(u)
params['hosts'] = hosts
if args.allow_any_host:
params['allow_any_host'] = True
if args.namespaces:
namespaces = []
for u in args.namespaces.strip().split(" "):
bdev_name = u
nsid = 0
if ':' in u:
(bdev_name, nsid) = u.split(":")
ns_params = {'bdev_name': bdev_name}
nsid = int(nsid)
if nsid != 0:
ns_params['nsid'] = nsid
namespaces.append(ns_params)
params['namespaces'] = namespaces
return args.client.call('construct_nvmf_subsystem', params)
def nvmf_subsystem_add_listener(args):
listen_address = {'trtype': args.trtype,
'traddr': args.traddr,
'trsvcid': args.trsvcid}
if args.adrfam:
listen_address['adrfam'] = args.adrfam
params = {'nqn': args.nqn,
'listen_address': listen_address}
return args.client.call('nvmf_subsystem_add_listener', params)
def nvmf_subsystem_remove_listener(args):
listen_address = {'trtype': args.trtype,
'traddr': args.traddr,
'trsvcid': args.trsvcid}
if args.adrfam:
listen_address['adrfam'] = args.adrfam
params = {'nqn': args.nqn,
'listen_address': listen_address}
return args.client.call('nvmf_subsystem_remove_listener', params)
def nvmf_subsystem_add_ns(args):
ns = {'bdev_name': args.bdev_name}
if args.nsid:
ns['nsid'] = args.nsid
if args.nguid:
ns['nguid'] = args.nguid
if args.eui64:
ns['eui64'] = args.eui64
params = {'nqn': args.nqn,
'namespace': ns}
return args.client.call('nvmf_subsystem_add_ns', params)
def nvmf_subsystem_remove_ns(args):
params = {'nqn': args.nqn,
'nsid': args.nsid}
return args.client.call('nvmf_subsystem_remove_ns', params)
def nvmf_subsystem_add_host(args):
params = {'nqn': args.nqn,
'host': args.host}
return args.client.call('nvmf_subsystem_add_host', params)
def nvmf_subsystem_remove_host(args):
params = {'nqn': args.nqn,
'host': args.host}
return args.client.call('nvmf_subsystem_remove_host', params)
def nvmf_subsystem_allow_any_host(args):
params = {'nqn': args.nqn}
params['allow_any_host'] = False if args.disable else True
return args.client.call('nvmf_subsystem_allow_any_host', params)
def delete_nvmf_subsystem(args):
params = {'nqn': args.subsystem_nqn}
return args.client.call('delete_nvmf_subsystem', params)