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
|
import json
class NvmfTgt(object):
def __init__(self, py):
super(NvmfTgt, self).__init__()
self.py = py
def get_rpc_methods(self):
rpc_methods = self._get_json_objs(
'get_rpc_methods', '10.0.2.15')
return rpc_methods
def get_bdevs(self):
block_devices = self._get_json_objs(
'get_bdevs', '10.0.2.15')
return block_devices
def delete_bdev(self, name):
sub_args = [name]
res = self.py.exec_rpc('delete_bdev', '10.0.2.15', sub_args=sub_args)
print res
def kill_instance(self, sig_name):
sub_args = [sig_name]
res = self.py.exec_rpc('kill_instance', '10.0.2.15', 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',
'10.0.2.15',
sub_args=sub_args)
print res
def construct_error_bdev(self, basename):
sub_args = [basename]
res = self.py.exec_rpc(
'construct_error_bdev',
'10.0.2.15',
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',
'10.0.2.15',
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',
'10.0.2.15',
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 delete_nvmf_subsystem(self, nqn):
sub_args = [nqn]
res = self.py.exec_rpc(
'delete_nvmf_subsystem',
'10.0.2.15',
sub_args=sub_args)
print res
def construct_nvmf_subsystem(
self,
nqn,
listen,
hosts,
serial_number,
namespaces):
sub_args = [nqn, listen, hosts, serial_number, namespaces]
res = self.py.exec_rpc(
'construct_nvmf_subsystem',
'10.0.2.15',
sub_args=sub_args)
print res
def get_nvmf_subsystems(self):
subsystems = self._get_json_objs(
'get_nvmf_subsystems', '10.0.2.15')
return subsystems
def _get_json_objs(self, method, server_ip):
res = self.py.exec_rpc(method, server_ip)
json_obj = json.loads(res)
return json_obj
|