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
|
import json
class VhostTgt(object):
def __init__(self, py):
super(VhostTgt, self).__init__()
self.py = py
def get_rpc_methods(self):
rpc_methods = self._get_json_objs('get_rpc_methods', '127.0.0.1')
return rpc_methods
def get_scsi_devices(self):
scsi_devices = self._get_json_objs(
'get_scsi_devices', '127.0.0.1')
return scsi_devices
def get_luns(self):
luns = self._get_json_objs('get_luns', '127.0.0.1')
return luns
def get_interfaces(self):
interfaces = self._get_json_objs(
'get_interfaces', '127.0.0.1')
return interfaces
def add_ip_address(self, ifc_index, ip_addr):
sub_args = [ifc_index, ip_addr]
res = self.py.exec_rpc(
'add_ip_address',
'127.0.0.1',
sub_args=sub_args)
return res
def delete_ip_address(self, ifc_index, ip_addr):
sub_args = [ifc_index, ip_addr]
res = self.py.exec_rpc(
'delete_ip_address',
'127.0.0.1',
sub_args=sub_args)
return res
def get_bdevs(self):
block_devices = self._get_json_objs(
'get_bdevs', '127.0.0.1')
return block_devices
def delete_bdev(self, name):
sub_args = [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 = [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 = [filename, name, 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 = [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)
return res
def construct_null_bdev(self, name, total_size, block_size):
sub_args = [name, str(total_size), str(block_size)]
res = self.py.exec_rpc(
'construct_null_bdev',
'127.0.0.1',
sub_args=sub_args)
return res
def construct_malloc_bdev(self, total_size, block_size):
sub_args = [str(total_size), str(block_size)]
res = self.py.exec_rpc(
'construct_malloc_bdev',
'10.0.2.15',
sub_args=sub_args)
print res
def _get_json_objs(self, method, server_ip):
res = self.py.exec_rpc(method, server_ip)
json_obj = json.loads(res)
return json_obj
|