scripts/rpc.py: pass named args to vhost.py

Add docstrings while at it.

Change-Id: Ic3ecc178f7e3721bafb3d758e34eb14d273410ed
Signed-off-by: Karol Latecki <karol.latecki@intel.com>
Reviewed-on: https://review.gerrithub.io/414966
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Karol Latecki 2018-06-13 12:55:38 +02:00 committed by Jim Harris
parent 7df80205b4
commit 25c11b8e25
2 changed files with 212 additions and 81 deletions

View File

@ -1084,7 +1084,10 @@ if __name__ == "__main__":
# vhost # vhost
@call_cmd @call_cmd
def set_vhost_controller_coalescing(args): def set_vhost_controller_coalescing(args):
rpc.vhost.set_vhost_controller_coalescing(args.client, args) rpc.vhost.set_vhost_controller_coalescing(args.client,
ctrlr=args.ctrlr,
delay_base_us=args.delay_base_us,
iops_threshold=args.iops_threshold)
p = subparsers.add_parser('set_vhost_controller_coalescing', help='Set vhost controller coalescing') p = subparsers.add_parser('set_vhost_controller_coalescing', help='Set vhost controller coalescing')
p.add_argument('ctrlr', help='controller name') p.add_argument('ctrlr', help='controller name')
@ -1094,7 +1097,9 @@ if __name__ == "__main__":
@call_cmd @call_cmd
def construct_vhost_scsi_controller(args): def construct_vhost_scsi_controller(args):
rpc.vhost.construct_vhost_scsi_controller(args.client, args) rpc.vhost.construct_vhost_scsi_controller(args.client,
ctrlr=args.ctrlr,
cpumask=args.cpumask)
p = subparsers.add_parser( p = subparsers.add_parser(
'construct_vhost_scsi_controller', help='Add new vhost controller') 'construct_vhost_scsi_controller', help='Add new vhost controller')
@ -1104,7 +1109,10 @@ if __name__ == "__main__":
@call_cmd @call_cmd
def add_vhost_scsi_lun(args): def add_vhost_scsi_lun(args):
rpc.vhost.add_vhost_scsi_lun(args.client, args) rpc.vhost.add_vhost_scsi_lun(args.client,
ctrlr=args.ctrlr,
scsi_target_num=args.scsi_target_num,
bdev_name=args.bdev_name)
p = subparsers.add_parser('add_vhost_scsi_lun', p = subparsers.add_parser('add_vhost_scsi_lun',
help='Add lun to vhost controller') help='Add lun to vhost controller')
@ -1115,7 +1123,9 @@ if __name__ == "__main__":
@call_cmd @call_cmd
def remove_vhost_scsi_target(args): def remove_vhost_scsi_target(args):
rpc.vhost.remove_vhost_scsi_target(args.client, args) rpc.vhost.remove_vhost_scsi_target(args.client,
ctrlr=args.ctrlr,
scsi_target_num=args.scsi_target_num)
p = subparsers.add_parser('remove_vhost_scsi_target', help='Remove target from vhost controller') p = subparsers.add_parser('remove_vhost_scsi_target', help='Remove target from vhost controller')
p.add_argument('ctrlr', help='controller name to remove target from') p.add_argument('ctrlr', help='controller name to remove target from')
@ -1124,7 +1134,11 @@ if __name__ == "__main__":
@call_cmd @call_cmd
def construct_vhost_blk_controller(args): def construct_vhost_blk_controller(args):
rpc.vhost.construct_vhost_blk_controller(args.client, args) rpc.vhost.construct_vhost_blk_controller(args.client,
ctrlr=args.ctrlr,
dev_name=args.dev_name,
cpumask=args.cpumask,
readonly=args.readonly)
p = subparsers.add_parser('construct_vhost_blk_controller', help='Add a new vhost block controller') p = subparsers.add_parser('construct_vhost_blk_controller', help='Add a new vhost block controller')
p.add_argument('ctrlr', help='controller name') p.add_argument('ctrlr', help='controller name')
@ -1135,7 +1149,10 @@ if __name__ == "__main__":
@call_cmd @call_cmd
def construct_vhost_nvme_controller(args): def construct_vhost_nvme_controller(args):
rpc.vhost.construct_vhost_nvme_controller(args.client, args) rpc.vhost.construct_vhost_nvme_controller(args.client,
ctrlr=args.ctrlr,
io_queues=args.io_queues,
cpumask=args.cpumask)
p = subparsers.add_parser('construct_vhost_nvme_controller', help='Add new vhost controller') p = subparsers.add_parser('construct_vhost_nvme_controller', help='Add new vhost controller')
p.add_argument('ctrlr', help='controller name') p.add_argument('ctrlr', help='controller name')
@ -1145,7 +1162,9 @@ if __name__ == "__main__":
@call_cmd @call_cmd
def add_vhost_nvme_ns(args): def add_vhost_nvme_ns(args):
rpc.vhost.add_vhost_nvme_ns(args.client, args) rpc.vhost.add_vhost_nvme_ns(args.client,
ctrlr=args.ctrlr,
bdev_name=args.bdev_name)
p = subparsers.add_parser('add_vhost_nvme_ns', help='Add a Namespace to vhost controller') p = subparsers.add_parser('add_vhost_nvme_ns', help='Add a Namespace to vhost controller')
p.add_argument('ctrlr', help='conntroller name where add a Namespace') p.add_argument('ctrlr', help='conntroller name where add a Namespace')
@ -1154,14 +1173,15 @@ if __name__ == "__main__":
@call_cmd @call_cmd
def get_vhost_controllers(args): def get_vhost_controllers(args):
print_dict(rpc.vhost.get_vhost_controllers(args.client, args)) print_dict(rpc.vhost.get_vhost_controllers(args.client))
p = subparsers.add_parser('get_vhost_controllers', help='List vhost controllers') p = subparsers.add_parser('get_vhost_controllers', help='List vhost controllers')
p.set_defaults(func=get_vhost_controllers) p.set_defaults(func=get_vhost_controllers)
@call_cmd @call_cmd
def remove_vhost_controller(args): def remove_vhost_controller(args):
rpc.vhost.remove_vhost_controller(args.client, args) rpc.vhost.remove_vhost_controller(args.client,
ctrlr=args.ctrlr)
p = subparsers.add_parser('remove_vhost_controller', help='Remove a vhost controller') p = subparsers.add_parser('remove_vhost_controller', help='Remove a vhost controller')
p.add_argument('ctrlr', help='controller name') p.add_argument('ctrlr', help='controller name')
@ -1169,7 +1189,12 @@ if __name__ == "__main__":
@call_cmd @call_cmd
def construct_virtio_dev(args): def construct_virtio_dev(args):
print_dict(rpc.vhost.construct_virtio_dev(args.client, args)) print_dict(rpc.vhost.construct_virtio_dev(args.client,
trtype=args.trtype,
traddr=args.traddr,
dev_type=args.dev_type,
vq_count=args.vq_count,
vq_size=args.vq_size))
p = subparsers.add_parser('construct_virtio_dev', help="""Construct new virtio device using provided p = subparsers.add_parser('construct_virtio_dev', help="""Construct new virtio device using provided
transport type and device type. In case of SCSI device type this implies scan and add bdevs offered by transport type and device type. In case of SCSI device type this implies scan and add bdevs offered by
@ -1187,7 +1212,11 @@ if __name__ == "__main__":
@call_cmd @call_cmd
def construct_virtio_user_scsi_bdev(args): def construct_virtio_user_scsi_bdev(args):
print_dict(rpc.vhost.construct_virtio_user_scsi_bdev(args.client, args)) print_dict(rpc.vhost.construct_virtio_user_scsi_bdev(args.client,
path=args.path,
name=args.name,
vq_count=args.vq_count,
vq_size=args.vq_size))
p = subparsers.add_parser('construct_virtio_user_scsi_bdev', help="""Connect to virtio user scsi device. p = subparsers.add_parser('construct_virtio_user_scsi_bdev', help="""Connect to virtio user scsi device.
This imply scan and add bdevs offered by remote side. This imply scan and add bdevs offered by remote side.
@ -1201,7 +1230,9 @@ if __name__ == "__main__":
@call_cmd @call_cmd
def construct_virtio_pci_scsi_bdev(args): def construct_virtio_pci_scsi_bdev(args):
print_dict(rpc.vhost.construct_virtio_pci_scsi_bdev(args.client, args)) print_dict(rpc.vhost.construct_virtio_pci_scsi_bdev(args.client,
pci_address=args.pci_address,
name=args.name))
p = subparsers.add_parser('construct_virtio_pci_scsi_bdev', help="""Create a Virtio p = subparsers.add_parser('construct_virtio_pci_scsi_bdev', help="""Create a Virtio
SCSI device from a virtio-pci device.""") SCSI device from a virtio-pci device.""")
@ -1213,14 +1244,15 @@ if __name__ == "__main__":
@call_cmd @call_cmd
def get_virtio_scsi_devs(args): def get_virtio_scsi_devs(args):
print_dict(rpc.vhost.get_virtio_scsi_devs(args.client, args)) print_dict(rpc.vhost.get_virtio_scsi_devs(args.client))
p = subparsers.add_parser('get_virtio_scsi_devs', help='List all Virtio-SCSI devices.') p = subparsers.add_parser('get_virtio_scsi_devs', help='List all Virtio-SCSI devices.')
p.set_defaults(func=get_virtio_scsi_devs) p.set_defaults(func=get_virtio_scsi_devs)
@call_cmd @call_cmd
def remove_virtio_scsi_bdev(args): def remove_virtio_scsi_bdev(args):
rpc.vhost.remove_virtio_scsi_bdev(args.client, args) rpc.vhost.remove_virtio_scsi_bdev(args.client,
name=args.name)
p = subparsers.add_parser('remove_virtio_scsi_bdev', help="""Remove a Virtio-SCSI device p = subparsers.add_parser('remove_virtio_scsi_bdev', help="""Remove a Virtio-SCSI device
This will delete all bdevs exposed by this device""") This will delete all bdevs exposed by this device""")
@ -1229,7 +1261,11 @@ if __name__ == "__main__":
@call_cmd @call_cmd
def construct_virtio_user_blk_bdev(args): def construct_virtio_user_blk_bdev(args):
print_dict(rpc.vhost.construct_virtio_user_blk_bdev(args.client, args)) print_dict(rpc.vhost.construct_virtio_user_blk_bdev(args.client,
path=args.path,
name=args.name,
vq_count=args.vq_count,
vq_size=args.vq_size))
p = subparsers.add_parser('construct_virtio_user_blk_bdev', help='Connect to a virtio user blk device.') p = subparsers.add_parser('construct_virtio_user_blk_bdev', help='Connect to a virtio user blk device.')
p.add_argument('path', help='Path to Virtio BLK socket') p.add_argument('path', help='Path to Virtio BLK socket')
@ -1240,7 +1276,9 @@ if __name__ == "__main__":
@call_cmd @call_cmd
def construct_virtio_pci_blk_bdev(args): def construct_virtio_pci_blk_bdev(args):
print_dict(rpc.vhost.construct_virtio_pci_blk_bdev(args.client, args)) print_dict(rpc.vhost.construct_virtio_pci_blk_bdev(args.client,
pci_address=args.pci_address,
name=args.name))
p = subparsers.add_parser('construct_virtio_pci_blk_bdev', help='Create a Virtio Blk device from a virtio-pci device.') p = subparsers.add_parser('construct_virtio_pci_blk_bdev', help='Create a Virtio Blk device from a virtio-pci device.')
p.add_argument('pci_address', help="""PCI address in domain:bus:device.function format or p.add_argument('pci_address', help="""PCI address in domain:bus:device.function format or

View File

@ -1,138 +1,231 @@
def set_vhost_controller_coalescing(client, args): def set_vhost_controller_coalescing(client, ctrlr, delay_base_us, iops_threshold):
"""Set coalescing for vhost controller.
Args:
ctrlr: controller name
delay_base_us: base delay time
iops_threshold: IOPS threshold when coalescing is enabled
"""
params = { params = {
'ctrlr': args.ctrlr, 'ctrlr': ctrlr,
'delay_base_us': args.delay_base_us, 'delay_base_us': delay_base_us,
'iops_threshold': args.iops_threshold, 'iops_threshold': iops_threshold,
} }
return client.call('set_vhost_controller_coalescing', params) return client.call('set_vhost_controller_coalescing', params)
def construct_vhost_scsi_controller(client, args): def construct_vhost_scsi_controller(client, ctrlr, cpumask=None):
params = {'ctrlr': args.ctrlr} """Construct a vhost scsi controller.
Args:
ctrlr: controller name
cpumask: cpu mask for this controller
"""
params = {'ctrlr': ctrlr}
if args.cpumask: if cpumask:
params['cpumask'] = args.cpumask params['cpumask'] = cpumask
return client.call('construct_vhost_scsi_controller', params) return client.call('construct_vhost_scsi_controller', params)
def add_vhost_scsi_lun(client, args): def add_vhost_scsi_lun(client, ctrlr, scsi_target_num, bdev_name):
"""Add LUN to vhost scsi controller target.
Args:
ctrlr: controller name
scsi_target_num: target number to use
bdev_name: name of bdev to add to target
"""
params = { params = {
'ctrlr': args.ctrlr, 'ctrlr': ctrlr,
'bdev_name': args.bdev_name, 'scsi_target_num': scsi_target_num,
'scsi_target_num': args.scsi_target_num 'bdev_name': bdev_name,
} }
return client.call('add_vhost_scsi_lun', params) return client.call('add_vhost_scsi_lun', params)
def remove_vhost_scsi_target(client, args): def remove_vhost_scsi_target(client, ctrlr, scsi_target_num):
"""Remove target from vhost scsi controller.
Args:
ctrlr: controller name to remove target from
scsi_target_num: number of target to remove from controller
"""
params = { params = {
'ctrlr': args.ctrlr, 'ctrlr': ctrlr,
'scsi_target_num': args.scsi_target_num 'scsi_target_num': scsi_target_num
} }
return client.call('remove_vhost_scsi_target', params) return client.call('remove_vhost_scsi_target', params)
def construct_vhost_nvme_controller(client, args): def construct_vhost_nvme_controller(client, ctrlr, io_queues, cpumask=None):
"""Construct vhost NVMe controller.
Args:
ctrlr: controller name
io_queues: number of IO queues for the controller
cpumask: cpu mask for this controller
"""
params = { params = {
'ctrlr': args.ctrlr, 'ctrlr': ctrlr,
'io_queues': args.io_queues 'io_queues': io_queues
} }
if args.cpumask: if cpumask:
params['cpumask'] = args.cpumask params['cpumask'] = cpumask
return client.call('construct_vhost_nvme_controller', params) return client.call('construct_vhost_nvme_controller', params)
def add_vhost_nvme_ns(client, args): def add_vhost_nvme_ns(client, ctrlr, bdev_name):
"""Add namespace to vhost nvme controller.
Args:
ctrlr: controller name where to add a namespace
bdev_name: block device name for a new namespace
"""
params = { params = {
'ctrlr': args.ctrlr, 'ctrlr': ctrlr,
'bdev_name': args.bdev_name, 'bdev_name': bdev_name,
} }
return client.call('add_vhost_nvme_ns', params) return client.call('add_vhost_nvme_ns', params)
def construct_vhost_blk_controller(client, args): def construct_vhost_blk_controller(client, ctrlr, dev_name, cpumask=None, readonly=None):
"""Construct vhost BLK controller.
Args:
ctrlr: controller name
dev_name: device name to add to controller
cpumask: cpu mask for this controller
readonly: set controller as read-only
"""
params = { params = {
'ctrlr': args.ctrlr, 'ctrlr': ctrlr,
'dev_name': args.dev_name, 'dev_name': dev_name,
} }
if args.cpumask: if cpumask:
params['cpumask'] = args.cpumask params['cpumask'] = cpumask
if args.readonly: if readonly:
params['readonly'] = args.readonly params['readonly'] = readonly
return client.call('construct_vhost_blk_controller', params) return client.call('construct_vhost_blk_controller', params)
def get_vhost_controllers(client, args): def get_vhost_controllers(client):
"""Get list of configured vhost controllers.
Returns:
List of vhost controllers.
"""
return client.call('get_vhost_controllers') return client.call('get_vhost_controllers')
def remove_vhost_controller(client, args): def remove_vhost_controller(client, ctrlr):
params = {'ctrlr': args.ctrlr} """Remove vhost controller from configuration.
Args:
ctrlr: controller name to remove
"""
params = {'ctrlr': ctrlr}
return client.call('remove_vhost_controller', params) return client.call('remove_vhost_controller', params)
def construct_virtio_dev(client, args): def construct_virtio_dev(client, name, trtype, traddr, dev_type, vq_count=None, vq_size=None):
"""Construct new virtio device using provided
transport type and device type.
Args:
name: name base for new created bdevs
trtype: virtio target transport type: pci or user
traddr: transport type specific target address: e.g. UNIX
domain socket path or BDF
dev_type: device type: blk or scsi
vq_count: number of virtual queues to be used
vq_size: size of each queue
"""
params = { params = {
'name': args.name, 'name': name,
'trtype': args.trtype, 'trtype': trtype,
'traddr': args.traddr, 'traddr': traddr,
'dev_type': args.dev_type 'dev_type': dev_type
} }
if args.vq_count: if vq_count:
params['vq_count'] = args.vq_count params['vq_count'] = vq_count
if args.vq_size: if vq_size:
params['vq_size'] = args.vq_size params['vq_size'] = vq_size
return client.call('construct_virtio_dev', params) return client.call('construct_virtio_dev', params)
def construct_virtio_user_scsi_bdev(client, args): def construct_virtio_user_scsi_bdev(client, path, name, vq_count=None, vq_size=None):
"""Connect to virtio user scsi device.
Args:
path: path to Virtio SCSI socket
name: use this name as base instead of 'VirtioScsiN'
vq_count: number of virtual queues to be used
vq_size: size of each queue
"""
params = { params = {
'path': args.path, 'path': path,
'name': args.name, 'name': name,
} }
if args.vq_count: if vq_count:
params['vq_count'] = args.vq_count params['vq_count'] = vq_count
if args.vq_size: if vq_size:
params['vq_size'] = args.vq_size params['vq_size'] = vq_size
return client.call('construct_virtio_user_scsi_bdev', params) return client.call('construct_virtio_user_scsi_bdev', params)
def construct_virtio_pci_scsi_bdev(client, args): def construct_virtio_pci_scsi_bdev(client, pci_address, name):
"""Create a Virtio SCSI device from a virtio-pci device.
Args:
pci_address: PCI address in domain:bus:device.function format or
domain.bus.device.function format
name: Name for the virtio device. It will be inhereted by all created
bdevs, which are named n the following format:
<name>t<target_id>
"""
params = { params = {
'pci_address': args.pci_address, 'pci_address': pci_address,
'name': args.name, 'name': name,
} }
return client.call('construct_virtio_pci_scsi_bdev', params) return client.call('construct_virtio_pci_scsi_bdev', params)
def remove_virtio_scsi_bdev(client, args): def remove_virtio_scsi_bdev(client, name):
params = {'name': args.name} """Remove a Virtio-SCSI device
This will delete all bdevs exposed by this device.
Args:
name: virtio device name
"""
params = {'name': name}
return client.call('remove_virtio_scsi_bdev', params) return client.call('remove_virtio_scsi_bdev', params)
def get_virtio_scsi_devs(client, args): def get_virtio_scsi_devs(client):
"""Get list of virtio scsi devices."""
return client.call('get_virtio_scsi_devs') return client.call('get_virtio_scsi_devs')
def construct_virtio_user_blk_bdev(client, args): def construct_virtio_user_blk_bdev(client, path, name, vq_count=None, vq_size=None):
"""Connect to virtio user BLK device.
Args:
path: path to Virtio BLK socket
name: use this name as base instead of 'VirtioScsiN'
vq_count: number of virtual queues to be used
vq_size: size of each queue
"""
params = { params = {
'path': args.path, 'path': path,
'name': args.name, 'name': name,
} }
if args.vq_count: if vq_count:
params['vq_count'] = args.vq_count params['vq_count'] = vq_count
if args.vq_size: if vq_size:
params['vq_size'] = args.vq_size params['vq_size'] = vq_size
return client.call('construct_virtio_user_blk_bdev', params) return client.call('construct_virtio_user_blk_bdev', params)
def construct_virtio_pci_blk_bdev(client, args): def construct_virtio_pci_blk_bdev(client, pci_address, name):
"""Create a Virtio Blk device from a virtio-pci device.
Args:
pci_address: PCI address in domain:bus:device.function format or
domain.bus.device.function format
name: name for the blk device
"""
params = { params = {
'pci_address': args.pci_address, 'pci_address': pci_address,
'name': args.name, 'name': name,
} }
return client.call('construct_virtio_pci_blk_bdev', params) return client.call('construct_virtio_pci_blk_bdev', params)