]> git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/scripts/rpc/iscsi.py
import 15.2.0 Octopus source
[ceph.git] / ceph / src / spdk / scripts / rpc / iscsi.py
1
2
3 def set_iscsi_options(
4 client,
5 auth_file=None,
6 node_base=None,
7 nop_timeout=None,
8 nop_in_interval=None,
9 disable_chap=None,
10 require_chap=None,
11 mutual_chap=None,
12 chap_group=None,
13 max_sessions=None,
14 max_queue_depth=None,
15 max_connections_per_session=None,
16 default_time2wait=None,
17 default_time2retain=None,
18 first_burst_length=None,
19 immediate_data=None,
20 error_recovery_level=None,
21 allow_duplicated_isid=None):
22 """Set iSCSI target options.
23
24 Args:
25 auth_file: Path to CHAP shared secret file (optional)
26 node_base: Prefix of the name of iSCSI target node (optional)
27 nop_timeout: Timeout in seconds to nop-in request to the initiator (optional)
28 nop_in_interval: Time interval in secs between nop-in requests by the target (optional)
29 disable_chap: CHAP for discovery session should be disabled (optional)
30 require_chap: CHAP for discovery session should be required
31 mutual_chap: CHAP for discovery session should be mutual
32 chap_group: Authentication group ID for discovery session
33 max_sessions: Maximum number of sessions in the host
34 max_queue_depth: Maximum number of outstanding I/Os per queue
35 max_connections_per_session: Negotiated parameter, MaxConnections
36 default_time2wait: Negotiated parameter, DefaultTime2Wait
37 default_time2retain: Negotiated parameter, DefaultTime2Retain
38 first_burst_length: Negotiated parameter, FirstBurstLength
39 immediate_data: Negotiated parameter, ImmediateData
40 error_recovery_level: Negotiated parameter, ErrorRecoveryLevel
41 allow_duplicated_isid: Allow duplicated initiator session ID
42
43 Returns:
44 True or False
45 """
46 params = {}
47
48 if auth_file:
49 params['auth_file'] = auth_file
50 if node_base:
51 params['node_base'] = node_base
52 if nop_timeout:
53 params['nop_timeout'] = nop_timeout
54 if nop_in_interval:
55 params['nop_in_interval'] = nop_in_interval
56 if disable_chap:
57 params['disable_chap'] = disable_chap
58 if require_chap:
59 params['require_chap'] = require_chap
60 if mutual_chap:
61 params['mutual_chap'] = mutual_chap
62 if chap_group:
63 params['chap_group'] = chap_group
64 if max_sessions:
65 params['max_sessions'] = max_sessions
66 if max_queue_depth:
67 params['max_queue_depth'] = max_queue_depth
68 if max_connections_per_session:
69 params['max_connections_per_session'] = max_connections_per_session
70 if default_time2wait:
71 params['default_time2wait'] = default_time2wait
72 if default_time2retain:
73 params['default_time2retain'] = default_time2retain
74 if first_burst_length:
75 params['first_burst_length'] = first_burst_length
76 if immediate_data:
77 params['immediate_data'] = immediate_data
78 if error_recovery_level:
79 params['error_recovery_level'] = error_recovery_level
80 if allow_duplicated_isid:
81 params['allow_duplicated_isid'] = allow_duplicated_isid
82
83 return client.call('set_iscsi_options', params)
84
85
86 def set_iscsi_discovery_auth(
87 client,
88 disable_chap=None,
89 require_chap=None,
90 mutual_chap=None,
91 chap_group=None):
92 """Set CHAP authentication for discovery service.
93
94 Args:
95 disable_chap: CHAP for discovery session should be disabled (optional)
96 require_chap: CHAP for discovery session should be required (optional)
97 mutual_chap: CHAP for discovery session should be mutual (optional)
98 chap_group: Authentication group ID for discovery session (optional)
99
100 Returns:
101 True or False
102 """
103 params = {}
104
105 if disable_chap:
106 params['disable_chap'] = disable_chap
107 if require_chap:
108 params['require_chap'] = require_chap
109 if mutual_chap:
110 params['mutual_chap'] = mutual_chap
111 if chap_group:
112 params['chap_group'] = chap_group
113
114 return client.call('set_iscsi_discovery_auth', params)
115
116
117 def get_iscsi_auth_groups(client):
118 """Display current authentication group configuration.
119
120 Returns:
121 List of current authentication group configuration.
122 """
123 return client.call('get_iscsi_auth_groups')
124
125
126 def get_portal_groups(client):
127 """Display current portal group configuration.
128
129 Returns:
130 List of current portal group configuration.
131 """
132 return client.call('get_portal_groups')
133
134
135 def get_initiator_groups(client):
136 """Display current initiator group configuration.
137
138 Returns:
139 List of current initiator group configuration.
140 """
141 return client.call('get_initiator_groups')
142
143
144 def get_target_nodes(client):
145 """Display target nodes.
146
147 Returns:
148 List of ISCSI target node objects.
149 """
150 return client.call('get_target_nodes')
151
152
153 def construct_target_node(
154 client,
155 luns,
156 pg_ig_maps,
157 name,
158 alias_name,
159 queue_depth,
160 chap_group=None,
161 disable_chap=None,
162 require_chap=None,
163 mutual_chap=None,
164 header_digest=None,
165 data_digest=None):
166 """Add a target node.
167
168 Args:
169 luns: List of bdev_name_id_pairs, e.g. [{"bdev_name": "Malloc1", "lun_id": 1}]
170 pg_ig_maps: List of pg_ig_mappings, e.g. [{"pg_tag": pg, "ig_tag": ig}]
171 name: Target node name (ASCII)
172 alias_name: Target node alias name (ASCII)
173 queue_depth: Desired target queue depth
174 chap_group: Authentication group ID for this target node
175 disable_chap: CHAP authentication should be disabled for this target node
176 require_chap: CHAP authentication should be required for this target node
177 mutual_chap: CHAP authentication should be mutual/bidirectional
178 header_digest: Header Digest should be required for this target node
179 data_digest: Data Digest should be required for this target node
180
181 Returns:
182 True or False
183 """
184 params = {
185 'name': name,
186 'alias_name': alias_name,
187 'pg_ig_maps': pg_ig_maps,
188 'luns': luns,
189 'queue_depth': queue_depth,
190 }
191
192 if chap_group:
193 params['chap_group'] = chap_group
194 if disable_chap:
195 params['disable_chap'] = disable_chap
196 if require_chap:
197 params['require_chap'] = require_chap
198 if mutual_chap:
199 params['mutual_chap'] = mutual_chap
200 if header_digest:
201 params['header_digest'] = header_digest
202 if data_digest:
203 params['data_digest'] = data_digest
204 return client.call('construct_target_node', params)
205
206
207 def target_node_add_lun(client, name, bdev_name, lun_id=None):
208 """Add LUN to the target node.
209
210 Args:
211 name: Target node name (ASCII)
212 bdev_name: bdev name
213 lun_id: LUN ID (integer >= 0)
214
215 Returns:
216 True or False
217 """
218 params = {
219 'name': name,
220 'bdev_name': bdev_name,
221 }
222 if lun_id:
223 params['lun_id'] = lun_id
224 return client.call('target_node_add_lun', params)
225
226
227 def set_iscsi_target_node_auth(
228 client,
229 name,
230 chap_group=None,
231 disable_chap=None,
232 require_chap=None,
233 mutual_chap=None):
234 """Set CHAP authentication for the target node.
235
236 Args:
237 name: Target node name (ASCII)
238 chap_group: Authentication group ID for this target node
239 disable_chap: CHAP authentication should be disabled for this target node
240 require_chap: CHAP authentication should be required for this target node
241 mutual_chap: CHAP authentication should be mutual/bidirectional
242
243 Returns:
244 True or False
245 """
246 params = {
247 'name': name,
248 }
249
250 if chap_group:
251 params['chap_group'] = chap_group
252 if disable_chap:
253 params['disable_chap'] = disable_chap
254 if require_chap:
255 params['require_chap'] = require_chap
256 if mutual_chap:
257 params['mutual_chap'] = mutual_chap
258 return client.call('set_iscsi_target_node_auth', params)
259
260
261 def add_iscsi_auth_group(client, tag, secrets=None):
262 """Add authentication group for CHAP authentication.
263
264 Args:
265 tag: Authentication group tag (unique, integer > 0).
266 secrets: Array of secrets objects (optional).
267
268 Returns:
269 True or False
270 """
271 params = {'tag': tag}
272
273 if secrets:
274 params['secrets'] = secrets
275 return client.call('add_iscsi_auth_group', params)
276
277
278 def delete_iscsi_auth_group(client, tag):
279 """Delete an authentication group.
280
281 Args:
282 tag: Authentication group tag (unique, integer > 0)
283
284 Returns:
285 True or False
286 """
287 params = {'tag': tag}
288 return client.call('delete_iscsi_auth_group', params)
289
290
291 def add_secret_to_iscsi_auth_group(client, tag, user, secret, muser=None, msecret=None):
292 """Add a secret to an authentication group.
293
294 Args:
295 tag: Authentication group tag (unique, integer > 0)
296 user: User name for one-way CHAP authentication
297 secret: Secret for one-way CHAP authentication
298 muser: User name for mutual CHAP authentication (optional)
299 msecret: Secret for mutual CHAP authentication (optional)
300
301 Returns:
302 True or False
303 """
304 params = {'tag': tag, 'user': user, 'secret': secret}
305
306 if muser:
307 params['muser'] = muser
308 if msecret:
309 params['msecret'] = msecret
310 return client.call('add_secret_to_iscsi_auth_group', params)
311
312
313 def delete_secret_from_iscsi_auth_group(client, tag, user):
314 """Delete a secret from an authentication group.
315
316 Args:
317 tag: Authentication group tag (unique, integer > 0)
318 user: User name for one-way CHAP authentication
319
320 Returns:
321 True or False
322 """
323 params = {'tag': tag, 'user': user}
324 return client.call('delete_secret_from_iscsi_auth_group', params)
325
326
327 def delete_pg_ig_maps(client, pg_ig_maps, name):
328 """Delete PG-IG maps from the target node.
329
330 Args:
331 pg_ig_maps: List of pg_ig_mappings, e.g. [{"pg_tag": pg, "ig_tag": ig}]
332 name: Target node alias name (ASCII)
333
334 Returns:
335 True or False
336 """
337 params = {
338 'name': name,
339 'pg_ig_maps': pg_ig_maps,
340 }
341 return client.call('delete_pg_ig_maps', params)
342
343
344 def add_pg_ig_maps(client, pg_ig_maps, name):
345 """Add PG-IG maps to the target node.
346
347 Args:
348 pg_ig_maps: List of pg_ig_mappings, e.g. [{"pg_tag": pg, "ig_tag": ig}]
349 name: Target node alias name (ASCII)
350
351 Returns:
352 True or False
353 """
354 params = {
355 'name': name,
356 'pg_ig_maps': pg_ig_maps,
357 }
358 return client.call('add_pg_ig_maps', params)
359
360
361 def add_portal_group(client, portals, tag):
362 """Add a portal group.
363
364 Args:
365 portals: List of portals, e.g. [{'host': ip, 'port': port}] or [{'host': ip, 'port': port, 'cpumask': cpumask}]
366 tag: Initiator group tag (unique, integer > 0)
367
368 Returns:
369 True or False
370 """
371 params = {'tag': tag, 'portals': portals}
372 return client.call('add_portal_group', params)
373
374
375 def add_initiator_group(client, tag, initiators, netmasks):
376 """Add an initiator group.
377
378 Args:
379 tag: Initiator group tag (unique, integer > 0)
380 initiators: List of initiator hostnames or IP addresses, e.g. ["127.0.0.1","192.168.200.100"]
381 netmasks: List of initiator netmasks, e.g. ["255.255.0.0","255.248.0.0"]
382
383 Returns:
384 True or False
385 """
386 params = {'tag': tag, 'initiators': initiators, 'netmasks': netmasks}
387 return client.call('add_initiator_group', params)
388
389
390 def add_initiators_to_initiator_group(
391 client,
392 tag,
393 initiators=None,
394 netmasks=None):
395 """Add initiators to an existing initiator group.
396
397 Args:
398 tag: Initiator group tag (unique, integer > 0)
399 initiators: List of initiator hostnames or IP addresses, e.g. ["127.0.0.1","192.168.200.100"]
400 netmasks: List of initiator netmasks, e.g. ["255.255.0.0","255.248.0.0"]
401
402 Returns:
403 True or False
404 """
405 params = {'tag': tag}
406
407 if initiators:
408 params['initiators'] = initiators
409 if netmasks:
410 params['netmasks'] = netmasks
411 return client.call('add_initiators_to_initiator_group', params)
412
413
414 def delete_initiators_from_initiator_group(
415 client, tag, initiators=None, netmasks=None):
416 """Delete initiators from an existing initiator group.
417
418 Args:
419 tag: Initiator group tag (unique, integer > 0)
420 initiators: List of initiator hostnames or IP addresses, e.g. ["127.0.0.1","192.168.200.100"]
421 netmasks: List of initiator netmasks, e.g. ["255.255.0.0","255.248.0.0"]
422
423 Returns:
424 True or False
425 """
426 params = {'tag': tag}
427
428 if initiators:
429 params['initiators'] = initiators
430 if netmasks:
431 params['netmasks'] = netmasks
432 return client.call('delete_initiators_from_initiator_group', params)
433
434
435 def delete_target_node(client, target_node_name):
436 """Delete a target node.
437
438 Args:
439 target_node_name: Target node name to be deleted. Example: iqn.2016-06.io.spdk:disk1.
440
441 Returns:
442 True or False
443 """
444 params = {'name': target_node_name}
445 return client.call('delete_target_node', params)
446
447
448 def delete_portal_group(client, tag):
449 """Delete a portal group.
450
451 Args:
452 tag: Portal group tag (unique, integer > 0)
453
454 Returns:
455 True or False
456 """
457 params = {'tag': tag}
458 return client.call('delete_portal_group', params)
459
460
461 def delete_initiator_group(client, tag):
462 """Delete an initiator group.
463
464 Args:
465 tag: Initiator group tag (unique, integer > 0)
466
467 Returns:
468 True or False
469 """
470 params = {'tag': tag}
471 return client.call('delete_initiator_group', params)
472
473
474 def get_iscsi_connections(client):
475 """Display iSCSI connections.
476
477 Returns:
478 List of iSCSI connection.
479 """
480 return client.call('get_iscsi_connections')
481
482
483 def get_iscsi_global_params(client):
484 """Display iSCSI global parameters.
485
486 Returns:
487 List of iSCSI global parameter.
488 """
489 return client.call('get_iscsi_global_params')
490
491
492 def get_scsi_devices(client):
493 """Display SCSI devices.
494
495 Returns:
496 List of SCSI device.
497 """
498 return client.call('get_scsi_devices')