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