1# JSON-RPC Remote access {#jsonrpc_proxy} 2 3SPDK provides a sample python script `rpc_http_proxy.py`, that provides http server which listens for JSON objects from users. It uses HTTP POST method to receive JSON objects including methods and parameters described in this chapter. 4 5## Parameters 6 7Name | Optional | Type | Description 8----------------------- | -------- | ----------- | ----------- 9server IP | Required | string | IP address that JSON objects shall be received on 10server port | Required | number | Port number that JSON objects shall be received on 11user name | Required | string | User name that will be used for authentication 12password | Required | string | Password that will be used for authentication 13RPC listen address | Optional | string | Path to SPDK JSON RPC socket. Default: /var/tmp/spdk.sock 14 15## Example usage 16 17`spdk/scripts/rpc_http_proxy.py 192.168.0.2 8000 user password` 18 19## Returns 20 21Error 401 - missing or incorrect user and/or password. 22 23Error 400 - wrong JSON syntax or incorrect JSON method 24 25Status 200 with resultant JSON object included on success. 26 27## Client side 28 29Below is a sample python script acting as a client side. It sends `get_bdevs` method with optional `name` parameter and prints JSON object returned from remote_rpc script. 30 31~~~ 32import json 33import requests 34 35if __name__ == '__main__': 36 payload = {'id':1, 'method': 'get_bdevs', 'params': {'name': 'Malloc0'}} 37 url = 'http://192.168.0.2:8000/' 38 req = requests.post(url, 39 data=json.dumps(payload), 40 auth=('user', 'password'), 41 verify=False, 42 timeout=30) 43 print (req.json()) 44~~~ 45 46Output: 47 48~~~ 49python client.py 50[{u'num_blocks': 2621440, u'name': u'Malloc0', u'uuid': u'fb57e59c-599d-42f1-8b89-3e46dbe12641', u'claimed': True, u'driver_specific': {}, u'supported_io_types': {u'reset': True, u'nvme_admin': False, u'unmap': True, u'read': True, u'nvme_io': False, u'write': True, u'flush': True, u'write_zeroes': True}, u'qos_ios_per_sec': 0, u'block_size': 4096, u'product_name': u'Malloc disk', u'aliases': []}] 51~~~ 52