165c1ad0fSMaciej Szwed# JSON-RPC Remote access {#jsonrpc_proxy} 265c1ad0fSMaciej Szwed 312fcbc9bSwawrykSPDK provides a sample python script `rpc_http_proxy.py`, that provides http server which listens for JSON 412fcbc9bSwawrykobjects from users. It uses HTTP POST method to receive JSON objects including methods and parameters 512fcbc9bSwawrykdescribed in this chapter. 665c1ad0fSMaciej Szwed 765c1ad0fSMaciej Szwed## Parameters 865c1ad0fSMaciej Szwed 965c1ad0fSMaciej SzwedName | Optional | Type | Description 1065c1ad0fSMaciej Szwed----------------------- | -------- | ----------- | ----------- 1165c1ad0fSMaciej Szwedserver IP | Required | string | IP address that JSON objects shall be received on 1265c1ad0fSMaciej Szwedserver port | Required | number | Port number that JSON objects shall be received on 1365c1ad0fSMaciej Szweduser name | Required | string | User name that will be used for authentication 1465c1ad0fSMaciej Szwedpassword | Required | string | Password that will be used for authentication 1565c1ad0fSMaciej SzwedRPC listen address | Optional | string | Path to SPDK JSON RPC socket. Default: /var/tmp/spdk.sock 1665c1ad0fSMaciej Szwed 1765c1ad0fSMaciej Szwed## Example usage 1865c1ad0fSMaciej Szwed 1965c1ad0fSMaciej Szwed`spdk/scripts/rpc_http_proxy.py 192.168.0.2 8000 user password` 2065c1ad0fSMaciej Szwed 2165c1ad0fSMaciej Szwed## Returns 2265c1ad0fSMaciej Szwed 2365c1ad0fSMaciej SzwedError 401 - missing or incorrect user and/or password. 2465c1ad0fSMaciej Szwed 2565c1ad0fSMaciej SzwedError 400 - wrong JSON syntax or incorrect JSON method 2665c1ad0fSMaciej Szwed 2765c1ad0fSMaciej SzwedStatus 200 with resultant JSON object included on success. 2865c1ad0fSMaciej Szwed 2965c1ad0fSMaciej Szwed## Client side 3065c1ad0fSMaciej Szwed 3112fcbc9bSwawrykBelow is a sample python script acting as a client side. It sends `bdev_get_bdevs` method with optional `name` 3212fcbc9bSwawrykparameter and prints JSON object returned from remote_rpc script. 3365c1ad0fSMaciej Szwed 34*63ee471bSMaciej Wawryk~~~python 3565c1ad0fSMaciej Szwedimport json 3665c1ad0fSMaciej Szwedimport requests 3765c1ad0fSMaciej Szwed 3865c1ad0fSMaciej Szwedif __name__ == '__main__': 392c49e910SMaciej Wawryk payload = {'id':1, 'method': 'bdev_get_bdevs', 'params': {'name': 'Malloc0'}} 4065c1ad0fSMaciej Szwed url = 'http://192.168.0.2:8000/' 4165c1ad0fSMaciej Szwed req = requests.post(url, 4265c1ad0fSMaciej Szwed data=json.dumps(payload), 4365c1ad0fSMaciej Szwed auth=('user', 'password'), 4465c1ad0fSMaciej Szwed verify=False, 4565c1ad0fSMaciej Szwed timeout=30) 4665c1ad0fSMaciej Szwed print (req.json()) 4765c1ad0fSMaciej Szwed~~~ 4865c1ad0fSMaciej Szwed 4965c1ad0fSMaciej SzwedOutput: 5065c1ad0fSMaciej Szwed 51*63ee471bSMaciej Wawryk~~~python 5265c1ad0fSMaciej Szwedpython client.py 5312fcbc9bSwawryk[{u'num_blocks': 2621440, u'name': u'Malloc0', u'uuid': u'fb57e59c-599d-42f1-8b89-3e46dbe12641', u'claimed': True, 5412fcbc9bSwawryku'driver_specific': {}, u'supported_io_types': {u'reset': True, u'nvme_admin': False, u'unmap': True, u'read': True, 5512fcbc9bSwawryku'nvme_io': False, u'write': True, u'flush': True, u'write_zeroes': True}, u'qos_ios_per_sec': 0, u'block_size': 4096, 5612fcbc9bSwawryku'product_name': u'Malloc disk', u'aliases': []}] 5765c1ad0fSMaciej Szwed~~~ 58