github.com/swiftstack/ProxyFS@v0.0.0-20210203235616-4017c267d62f/jrpcfs/test/client_test.py (about) 1 # Copyright (c) 2015-2021, NVIDIA CORPORATION. 2 # SPDX-License-Identifier: Apache-2.0 3 4 import json 5 import requests 6 import socket 7 8 # This version works as well, leaving here as a reference 9 #def main(): 10 # args = {'VolumeName' : "CommonVolume", 'MountOptions': 0, 'AuthUser': "balajirao"} 11 # 12 # payload = { 13 # "method": "Server.RpcMount", 14 # "params": [args], 15 # "id": 1, 16 # } 17 # 18 # s = socket.create_connection(("localhost", 12345)) 19 # s.sendall(json.dumps((payload))) 20 # rdata = s.recv(1024) 21 # 22 # print "received data:", rdata 23 # print "decoded received data:", json.loads(rdata) 24 # 25 # s.close 26 27 def main(): 28 args = {'VolumeName' : "CommonVolume", 'MountOptions': 0, 'AuthUser': "balajirao"} 29 30 id = 0 31 payload = { 32 "method": "Server.RpcMount", 33 "params": [args], 34 "jsonrpc": "2.0", 35 "id": id, 36 } 37 38 s = socket.create_connection(("localhost", 12345)) 39 data = json.dumps((payload)) 40 print "sending data:", data 41 s.sendall(data) 42 43 # This will actually have to loop if resp is bigger 44 rdata = s.recv(1024) 45 46 #print "received data:", rdata 47 resp = json.loads(rdata) 48 #print "decoded received data:", resp 49 50 if resp["id"] != id: 51 raise Exception("expected id=%s, received id=%s: %s" %(id, resp["id"], resp["error"])) 52 53 if resp["error"] is not None: 54 raise Exception(resp["error"]) 55 56 57 print "Returned MountID:", resp["result"]["MountID"] 58 59 s.close 60 61 62 if __name__ == "__main__": 63 main()