-
Notifications
You must be signed in to change notification settings - Fork 0
/
vhost_client.py
145 lines (126 loc) · 4.51 KB
/
vhost_client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import json
from proto import spdk_pb2
from util import pbjson
class VhostTgt(object):
def __init__(self, py):
super(VhostTgt, self).__init__()
self.py = py
def get_rpc_methods(self):
res = self.py.exec_rpc('get_rpc_methods', '127.0.0.1')
json_obj = json.loads(res)
proto_obj = spdk_pb2.RpcMethods().name
for name_i in range(len(json_obj)):
proto_obj.append(json_obj[name_i])
return proto_obj
def get_scsi_devices(self):
scsi_devices = spdk_pb2.ScsiDevices().scsiDevice
scsi_device = spdk_pb2.ScsiDevice
scsi_devices = self._get_proto_objs(
'get_scsi_devices', '127.0.0.1', scsi_devices, scsi_device)
return scsi_devices
def get_luns(self):
luns = spdk_pb2.Luns().lun
lun = spdk_pb2.Lun
luns = self._get_proto_objs('get_luns', '127.0.0.1', luns, lun)
return luns
def get_interfaces(self):
interfaces = spdk_pb2.Interfaces().interface
interface = spdk_pb2.Interface
interfaces = self._get_proto_objs(
'get_interfaces', '127.0.0.1', interfaces, interface)
return interfaces
def add_ip_address(self, ifc_index, ip_addr):
sub_args = []
sub_args.append(ifc_index)
sub_args.append(ip_addr)
res = self.py.exec_rpc('add_ip_address', '127.0.0.1', sub_args=sub_args)
print res
def delete_ip_address(self, ifc_index, ip_addr):
sub_args = []
sub_args.append(ifc_index)
sub_args.append(ip_addr)
res = self.py.exec_rpc('delete_ip_address', '127.0.0.1', sub_args=sub_args)
print res
def get_bdevs(self):
block_devices = spdk_pb2.BlockDevices().blockDevice
block_device = spdk_pb2.BlockDevice
block_devices = self._get_proto_objs(
'get_bdevs', '127.0.0.1', block_devices, block_device)
return block_devices
def delete_bdev(self, name):
sub_args = []
sub_args.append(name)
res = self.py.exec_rpc('delete_bdev', '127.0.0.1', sub_args=sub_args)
print res
def kill_instance(self, sig_name):
sub_args = []
sub_args.append(sig_name)
res = self.py.exec_rpc('kill_instance', '127.0.0.1', sub_args=sub_args)
print res
def construct_aio_bdev(self, filename, name, block_size):
sub_args = []
sub_args.append(filename)
sub_args.append(name)
sub_args.append(str(block_size))
res = self.py.exec_rpc('construct_aio_bdev', '127.0.0.1', sub_args=sub_args)
print res
def construct_error_bdev(self, basename):
sub_args = []
sub_args.append(basename)
res = self.py.exec_rpc(
'construct_error_bdev',
'127.0.0.1',
sub_args=sub_args)
print res
def construct_nvme_bdev(
self,
name,
trtype,
traddr,
adrfam=None,
trsvcid=None,
subnqn=None):
sub_args = ["-b", "-t", "-a"]
sub_args.insert(1, name)
sub_args.insert(2, trtype)
sub_args.insert(3, traddr)
if adrfam is not None:
sub_args.append("-f")
sub_args.append(adrfam)
if trsvcid is not None:
sub_args.append("-s")
sub_args.append(trsvcid)
if subnqn is not None:
sub_args.append("-n")
sub_args.append(subnqn)
res = self.py.exec_rpc(
'construct_nvme_bdev',
'127.0.0.1',
sub_args=sub_args)
print res
def construct_null_bdev(self, name, total_size, block_size):
sub_args = []
sub_args.append(name)
sub_args.append(str(total_size))
sub_args.append(str(block_size))
res = self.py.exec_rpc(
'construct_null_bdev',
'127.0.0.1',
sub_args=sub_args)
print res
def construct_malloc_bdev(self, total_size, block_size):
sub_args = []
sub_args.append(str(total_size))
sub_args.append(str(block_size))
res = self.py.exec_rpc(
'construct_malloc_bdev',
'10.0.2.15',
sub_args=sub_args)
print res
def _get_proto_objs(self, method, server_ip, proto_objs, proto_obj):
res = self.py.exec_rpc(method, server_ip)
json_obj = json.loads(res)
for list_i in range(len(json_obj)):
vproto_obj = pbjson.dict2pb(proto_obj, json_obj[list_i])
proto_objs.extend([vproto_obj])
return proto_objs