summaryrefslogtreecommitdiffstats
path: root/src/spdk/scripts/rpc/iscsi.py
blob: 6d64b6185287479d5b75f48a4d3dbbb667dd5fd2 (plain)
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
from .helpers import deprecated_alias


@deprecated_alias('set_iscsi_options')
def iscsi_set_options(
        client,
        auth_file=None,
        node_base=None,
        nop_timeout=None,
        nop_in_interval=None,
        disable_chap=None,
        require_chap=None,
        mutual_chap=None,
        chap_group=None,
        max_sessions=None,
        max_queue_depth=None,
        max_connections_per_session=None,
        default_time2wait=None,
        default_time2retain=None,
        first_burst_length=None,
        immediate_data=None,
        error_recovery_level=None,
        allow_duplicated_isid=None):
    """Set iSCSI target options.

    Args:
        auth_file: Path to CHAP shared secret file (optional)
        node_base: Prefix of the name of iSCSI target node (optional)
        nop_timeout: Timeout in seconds to nop-in request to the initiator (optional)
        nop_in_interval: Time interval in secs between nop-in requests by the target (optional)
        disable_chap: CHAP for discovery session should be disabled (optional)
        require_chap: CHAP for discovery session should be required
        mutual_chap: CHAP for discovery session should be mutual
        chap_group: Authentication group ID for discovery session
        max_sessions: Maximum number of sessions in the host
        max_queue_depth: Maximum number of outstanding I/Os per queue
        max_connections_per_session: Negotiated parameter, MaxConnections
        default_time2wait: Negotiated parameter, DefaultTime2Wait
        default_time2retain: Negotiated parameter, DefaultTime2Retain
        first_burst_length: Negotiated parameter, FirstBurstLength
        immediate_data: Negotiated parameter, ImmediateData
        error_recovery_level: Negotiated parameter, ErrorRecoveryLevel
        allow_duplicated_isid: Allow duplicated initiator session ID

    Returns:
        True or False
    """
    params = {}

    if auth_file:
        params['auth_file'] = auth_file
    if node_base:
        params['node_base'] = node_base
    if nop_timeout:
        params['nop_timeout'] = nop_timeout
    if nop_in_interval:
        params['nop_in_interval'] = nop_in_interval
    if disable_chap:
        params['disable_chap'] = disable_chap
    if require_chap:
        params['require_chap'] = require_chap
    if mutual_chap:
        params['mutual_chap'] = mutual_chap
    if chap_group:
        params['chap_group'] = chap_group
    if max_sessions:
        params['max_sessions'] = max_sessions
    if max_queue_depth:
        params['max_queue_depth'] = max_queue_depth
    if max_connections_per_session:
        params['max_connections_per_session'] = max_connections_per_session
    if default_time2wait:
        params['default_time2wait'] = default_time2wait
    if default_time2retain:
        params['default_time2retain'] = default_time2retain
    if first_burst_length:
        params['first_burst_length'] = first_burst_length
    if immediate_data:
        params['immediate_data'] = immediate_data
    if error_recovery_level:
        params['error_recovery_level'] = error_recovery_level
    if allow_duplicated_isid:
        params['allow_duplicated_isid'] = allow_duplicated_isid

    return client.call('iscsi_set_options', params)


@deprecated_alias('set_iscsi_discovery_auth')
def iscsi_set_discovery_auth(
        client,
        disable_chap=None,
        require_chap=None,
        mutual_chap=None,
        chap_group=None):
    """Set CHAP authentication for discovery service.

    Args:
        disable_chap: CHAP for discovery session should be disabled (optional)
        require_chap: CHAP for discovery session should be required (optional)
        mutual_chap: CHAP for discovery session should be mutual (optional)
        chap_group: Authentication group ID for discovery session (optional)

    Returns:
        True or False
    """
    params = {}

    if disable_chap:
        params['disable_chap'] = disable_chap
    if require_chap:
        params['require_chap'] = require_chap
    if mutual_chap:
        params['mutual_chap'] = mutual_chap
    if chap_group:
        params['chap_group'] = chap_group

    return client.call('iscsi_set_discovery_auth', params)


@deprecated_alias('get_iscsi_auth_groups')
def iscsi_get_auth_groups(client):
    """Display current authentication group configuration.

    Returns:
        List of current authentication group configuration.
    """
    return client.call('iscsi_get_auth_groups')


@deprecated_alias('get_portal_groups')
def iscsi_get_portal_groups(client):
    """Display current portal group configuration.

    Returns:
        List of current portal group configuration.
    """
    return client.call('iscsi_get_portal_groups')


@deprecated_alias('get_initiator_groups')
def iscsi_get_initiator_groups(client):
    """Display current initiator group configuration.

    Returns:
        List of current initiator group configuration.
    """
    return client.call('iscsi_get_initiator_groups')


@deprecated_alias('get_target_nodes')
def iscsi_get_target_nodes(client):
    """Display target nodes.

    Returns:
        List of ISCSI target node objects.
    """
    return client.call('iscsi_get_target_nodes')


@deprecated_alias('construct_target_node')
def iscsi_create_target_node(
        client,
        luns,
        pg_ig_maps,
        name,
        alias_name,
        queue_depth,
        chap_group=None,
        disable_chap=None,
        require_chap=None,
        mutual_chap=None,
        header_digest=None,
        data_digest=None):
    """Add a target node.

    Args:
        luns: List of bdev_name_id_pairs, e.g. [{"bdev_name": "Malloc1", "lun_id": 1}]
        pg_ig_maps: List of pg_ig_mappings, e.g. [{"pg_tag": pg, "ig_tag": ig}]
        name: Target node name (ASCII)
        alias_name: Target node alias name (ASCII)
        queue_depth: Desired target queue depth
        chap_group: Authentication group ID for this target node
        disable_chap: CHAP authentication should be disabled for this target node
        require_chap: CHAP authentication should be required for this target node
        mutual_chap: CHAP authentication should be mutual/bidirectional
        header_digest: Header Digest should be required for this target node
        data_digest: Data Digest should be required for this target node

    Returns:
        True or False
    """
    params = {
        'name': name,
        'alias_name': alias_name,
        'pg_ig_maps': pg_ig_maps,
        'luns': luns,
        'queue_depth': queue_depth,
    }

    if chap_group:
        params['chap_group'] = chap_group
    if disable_chap:
        params['disable_chap'] = disable_chap
    if require_chap:
        params['require_chap'] = require_chap
    if mutual_chap:
        params['mutual_chap'] = mutual_chap
    if header_digest:
        params['header_digest'] = header_digest
    if data_digest:
        params['data_digest'] = data_digest
    return client.call('iscsi_create_target_node', params)


@deprecated_alias('target_node_add_lun')
def iscsi_target_node_add_lun(client, name, bdev_name, lun_id=None):
    """Add LUN to the target node.

    Args:
        name: Target node name (ASCII)
        bdev_name: bdev name
        lun_id: LUN ID (integer >= 0)

    Returns:
        True or False
    """
    params = {
        'name': name,
        'bdev_name': bdev_name,
    }
    if lun_id:
        params['lun_id'] = lun_id
    return client.call('iscsi_target_node_add_lun', params)


@deprecated_alias('set_iscsi_target_node_auth')
def iscsi_target_node_set_auth(
        client,
        name,
        chap_group=None,
        disable_chap=None,
        require_chap=None,
        mutual_chap=None):
    """Set CHAP authentication for the target node.

    Args:
        name: Target node name (ASCII)
        chap_group: Authentication group ID for this target node
        disable_chap: CHAP authentication should be disabled for this target node
        require_chap: CHAP authentication should be required for this target node
        mutual_chap: CHAP authentication should be mutual/bidirectional

    Returns:
        True or False
    """
    params = {
        'name': name,
    }

    if chap_group:
        params['chap_group'] = chap_group
    if disable_chap:
        params['disable_chap'] = disable_chap
    if require_chap:
        params['require_chap'] = require_chap
    if mutual_chap:
        params['mutual_chap'] = mutual_chap
    return client.call('iscsi_target_node_set_auth', params)


@deprecated_alias('add_iscsi_auth_group')
def iscsi_create_auth_group(client, tag, secrets=None):
    """Create authentication group for CHAP authentication.

    Args:
        tag: Authentication group tag (unique, integer > 0).
        secrets: Array of secrets objects (optional).

    Returns:
        True or False
    """
    params = {'tag': tag}

    if secrets:
        params['secrets'] = secrets
    return client.call('iscsi_create_auth_group', params)


@deprecated_alias('delete_iscsi_auth_group')
def iscsi_delete_auth_group(client, tag):
    """Delete an authentication group.

    Args:
        tag: Authentication group tag (unique, integer > 0)

    Returns:
        True or False
    """
    params = {'tag': tag}
    return client.call('iscsi_delete_auth_group', params)


@deprecated_alias('add_secret_to_iscsi_auth_group')
def iscsi_auth_group_add_secret(client, tag, user, secret, muser=None, msecret=None):
    """Add a secret to an authentication group.

    Args:
        tag: Authentication group tag (unique, integer > 0)
        user: User name for one-way CHAP authentication
        secret: Secret for one-way CHAP authentication
        muser: User name for mutual CHAP authentication (optional)
        msecret: Secret for mutual CHAP authentication (optional)

    Returns:
        True or False
    """
    params = {'tag': tag, 'user': user, 'secret': secret}

    if muser:
        params['muser'] = muser
    if msecret:
        params['msecret'] = msecret
    return client.call('iscsi_auth_group_add_secret', params)


@deprecated_alias('delete_secret_from_iscsi_auth_group')
def iscsi_auth_group_remove_secret(client, tag, user):
    """Remove a secret from an authentication group.

    Args:
        tag: Authentication group tag (unique, integer > 0)
        user: User name for one-way CHAP authentication

    Returns:
        True or False
    """
    params = {'tag': tag, 'user': user}
    return client.call('iscsi_auth_group_remove_secret', params)


@deprecated_alias('delete_pg_ig_maps')
def iscsi_target_node_remove_pg_ig_maps(client, pg_ig_maps, name):
    """Delete PG-IG maps from the target node.

    Args:
        pg_ig_maps: List of pg_ig_mappings, e.g. [{"pg_tag": pg, "ig_tag": ig}]
        name: Target node alias name (ASCII)

    Returns:
        True or False
    """
    params = {
        'name': name,
        'pg_ig_maps': pg_ig_maps,
    }
    return client.call('iscsi_target_node_remove_pg_ig_maps', params)


@deprecated_alias('add_pg_ig_maps')
def iscsi_target_node_add_pg_ig_maps(client, pg_ig_maps, name):
    """Add PG-IG maps to the target node.

    Args:
        pg_ig_maps: List of pg_ig_mappings, e.g. [{"pg_tag": pg, "ig_tag": ig}]
        name: Target node alias name (ASCII)

    Returns:
        True or False
    """
    params = {
        'name': name,
        'pg_ig_maps': pg_ig_maps,
    }
    return client.call('iscsi_target_node_add_pg_ig_maps', params)


@deprecated_alias('add_portal_group')
def iscsi_create_portal_group(client, portals, tag):
    """Add a portal group.

    Args:
        portals: List of portals, e.g. [{'host': ip, 'port': port}]
        tag: Initiator group tag (unique, integer > 0)

    Returns:
        True or False
    """
    params = {'tag': tag, 'portals': portals}
    return client.call('iscsi_create_portal_group', params)


@deprecated_alias('add_initiator_group')
def iscsi_create_initiator_group(client, tag, initiators, netmasks):
    """Add an initiator group.

    Args:
        tag: Initiator group tag (unique, integer > 0)
        initiators: List of initiator hostnames or IP addresses, e.g. ["127.0.0.1","192.168.200.100"]
        netmasks: List of initiator netmasks, e.g. ["255.255.0.0","255.248.0.0"]

    Returns:
        True or False
    """
    params = {'tag': tag, 'initiators': initiators, 'netmasks': netmasks}
    return client.call('iscsi_create_initiator_group', params)


@deprecated_alias('add_initiators_to_initiator_group')
def iscsi_initiator_group_add_initiators(
        client,
        tag,
        initiators=None,
        netmasks=None):
    """Add initiators to an existing initiator group.

    Args:
        tag: Initiator group tag (unique, integer > 0)
        initiators: List of initiator hostnames or IP addresses, e.g. ["127.0.0.1","192.168.200.100"]
        netmasks: List of initiator netmasks, e.g. ["255.255.0.0","255.248.0.0"]

    Returns:
        True or False
    """
    params = {'tag': tag}

    if initiators:
        params['initiators'] = initiators
    if netmasks:
        params['netmasks'] = netmasks
    return client.call('iscsi_initiator_group_add_initiators', params)


@deprecated_alias('delete_initiators_from_initiator_group')
def iscsi_initiator_group_remove_initiators(
        client, tag, initiators=None, netmasks=None):
    """Delete initiators from an existing initiator group.

    Args:
        tag: Initiator group tag (unique, integer > 0)
        initiators: List of initiator hostnames or IP addresses, e.g. ["127.0.0.1","192.168.200.100"]
        netmasks: List of initiator netmasks, e.g. ["255.255.0.0","255.248.0.0"]

    Returns:
        True or False
    """
    params = {'tag': tag}

    if initiators:
        params['initiators'] = initiators
    if netmasks:
        params['netmasks'] = netmasks
    return client.call('iscsi_initiator_group_remove_initiators', params)


@deprecated_alias('delete_target_node')
def iscsi_delete_target_node(client, target_node_name):
    """Delete a target node.

    Args:
        target_node_name: Target node name to be deleted. Example: iqn.2016-06.io.spdk:disk1.

    Returns:
        True or False
    """
    params = {'name': target_node_name}
    return client.call('iscsi_delete_target_node', params)


@deprecated_alias('delete_portal_group')
def iscsi_delete_portal_group(client, tag):
    """Delete a portal group.

    Args:
        tag: Portal group tag (unique, integer > 0)

    Returns:
        True or False
    """
    params = {'tag': tag}
    return client.call('iscsi_delete_portal_group', params)


@deprecated_alias('delete_initiator_group')
def iscsi_delete_initiator_group(client, tag):
    """Delete an initiator group.

    Args:
        tag: Initiator group tag (unique, integer > 0)

    Returns:
        True or False
    """
    params = {'tag': tag}
    return client.call('iscsi_delete_initiator_group', params)


def iscsi_portal_group_set_auth(
        client,
        tag,
        chap_group=None,
        disable_chap=None,
        require_chap=None,
        mutual_chap=None):
    """Set CHAP authentication for discovery sessions specific for the portal group.

    Args:
        tag: Portal group tag (unique, integer > 0)
        chap_group: Authentication group ID for this portal group
        disable_chap: CHAP authentication should be disabled for this portal group
        require_chap: CHAP authentication should be required for this portal group
        mutual_chap: CHAP authentication should be mutual/bidirectional

    Returns:
        True or False
    """
    params = {
        'tag': tag,
    }

    if chap_group:
        params['chap_group'] = chap_group
    if disable_chap:
        params['disable_chap'] = disable_chap
    if require_chap:
        params['require_chap'] = require_chap
    if mutual_chap:
        params['mutual_chap'] = mutual_chap
    return client.call('iscsi_portal_group_set_auth', params)


@deprecated_alias('get_iscsi_connections')
def iscsi_get_connections(client):
    """Display iSCSI connections.

    Returns:
        List of iSCSI connection.
    """
    return client.call('iscsi_get_connections')


@deprecated_alias('get_iscsi_global_params')
def iscsi_get_options(client):
    """Display iSCSI global parameters.

    Returns:
        List of iSCSI global parameter.
    """
    return client.call('iscsi_get_options')


@deprecated_alias('get_iscsi_devices')
def scsi_get_devices(client):
    """Display SCSI devices.

    Returns:
        List of SCSI device.
    """
    return client.call('scsi_get_devices')