1# SPDX-License-Identifier: BSD-3-Clause 2# Copyright (C) 2017 Intel Corporation. 3# All rights reserved. 4 5 6def iscsi_set_options( 7 client, 8 auth_file=None, 9 node_base=None, 10 nop_timeout=None, 11 nop_in_interval=None, 12 disable_chap=None, 13 require_chap=None, 14 mutual_chap=None, 15 chap_group=None, 16 max_sessions=None, 17 max_queue_depth=None, 18 max_connections_per_session=None, 19 default_time2wait=None, 20 default_time2retain=None, 21 first_burst_length=None, 22 immediate_data=None, 23 error_recovery_level=None, 24 allow_duplicated_isid=None, 25 max_large_datain_per_connection=None, 26 max_r2t_per_connection=None, 27 pdu_pool_size=None, 28 immediate_data_pool_size=None, 29 data_out_pool_size=None): 30 """Set iSCSI target options. 31 32 Args: 33 auth_file: Path to CHAP shared secret file (optional) 34 node_base: Prefix of the name of iSCSI target node (optional) 35 nop_timeout: Timeout in seconds to nop-in request to the initiator (optional) 36 nop_in_interval: Time interval in secs between nop-in requests by the target (optional) 37 disable_chap: CHAP for discovery session should be disabled (optional) 38 require_chap: CHAP for discovery session should be required 39 mutual_chap: CHAP for discovery session should be mutual 40 chap_group: Authentication group ID for discovery session 41 max_sessions: Maximum number of sessions in the host 42 max_queue_depth: Maximum number of outstanding I/Os per queue 43 max_connections_per_session: Negotiated parameter, MaxConnections 44 default_time2wait: Negotiated parameter, DefaultTime2Wait 45 default_time2retain: Negotiated parameter, DefaultTime2Retain 46 first_burst_length: Negotiated parameter, FirstBurstLength 47 immediate_data: Negotiated parameter, ImmediateData 48 error_recovery_level: Negotiated parameter, ErrorRecoveryLevel 49 allow_duplicated_isid: Allow duplicated initiator session ID 50 max_large_datain_per_connection: Max number of outstanding split read I/Os per connection (optional) 51 max_r2t_per_connection: Max number of outstanding R2Ts per connection (optional) 52 pdu_pool_size: Number of PDUs in the pool (optional) 53 immediate_data_pool_size: Number of immediate data buffers in the pool (optional) 54 data_out_pool_size: Number of data out buffers in the pool (optional) 55 56 Returns: 57 True or False 58 """ 59 params = {} 60 61 if auth_file: 62 params['auth_file'] = auth_file 63 if node_base: 64 params['node_base'] = node_base 65 if nop_timeout: 66 params['nop_timeout'] = nop_timeout 67 if nop_in_interval: 68 params['nop_in_interval'] = nop_in_interval 69 if disable_chap: 70 params['disable_chap'] = disable_chap 71 if require_chap: 72 params['require_chap'] = require_chap 73 if mutual_chap: 74 params['mutual_chap'] = mutual_chap 75 if chap_group: 76 params['chap_group'] = chap_group 77 if max_sessions: 78 params['max_sessions'] = max_sessions 79 if max_queue_depth: 80 params['max_queue_depth'] = max_queue_depth 81 if max_connections_per_session: 82 params['max_connections_per_session'] = max_connections_per_session 83 if default_time2wait: 84 params['default_time2wait'] = default_time2wait 85 if default_time2retain: 86 params['default_time2retain'] = default_time2retain 87 if first_burst_length: 88 params['first_burst_length'] = first_burst_length 89 if immediate_data: 90 params['immediate_data'] = immediate_data 91 if error_recovery_level: 92 params['error_recovery_level'] = error_recovery_level 93 if allow_duplicated_isid: 94 params['allow_duplicated_isid'] = allow_duplicated_isid 95 if max_large_datain_per_connection: 96 params['max_large_datain_per_connection'] = max_large_datain_per_connection 97 if max_r2t_per_connection: 98 params['max_r2t_per_connection'] = max_r2t_per_connection 99 if pdu_pool_size: 100 params['pdu_pool_size'] = pdu_pool_size 101 if immediate_data_pool_size: 102 params['immediate_data_pool_size'] = immediate_data_pool_size 103 if data_out_pool_size: 104 params['data_out_pool_size'] = data_out_pool_size 105 106 return client.call('iscsi_set_options', params) 107 108 109def iscsi_set_discovery_auth( 110 client, 111 disable_chap=None, 112 require_chap=None, 113 mutual_chap=None, 114 chap_group=None): 115 """Set CHAP authentication for discovery service. 116 117 Args: 118 disable_chap: CHAP for discovery session should be disabled (optional) 119 require_chap: CHAP for discovery session should be required (optional) 120 mutual_chap: CHAP for discovery session should be mutual (optional) 121 chap_group: Authentication group ID for discovery session (optional) 122 123 Returns: 124 True or False 125 """ 126 params = {} 127 128 if disable_chap: 129 params['disable_chap'] = disable_chap 130 if require_chap: 131 params['require_chap'] = require_chap 132 if mutual_chap: 133 params['mutual_chap'] = mutual_chap 134 if chap_group: 135 params['chap_group'] = chap_group 136 137 return client.call('iscsi_set_discovery_auth', params) 138 139 140def iscsi_get_auth_groups(client): 141 """Display current authentication group configuration. 142 143 Returns: 144 List of current authentication group configuration. 145 """ 146 return client.call('iscsi_get_auth_groups') 147 148 149def iscsi_get_portal_groups(client): 150 """Display current portal group configuration. 151 152 Returns: 153 List of current portal group configuration. 154 """ 155 return client.call('iscsi_get_portal_groups') 156 157 158def iscsi_get_initiator_groups(client): 159 """Display current initiator group configuration. 160 161 Returns: 162 List of current initiator group configuration. 163 """ 164 return client.call('iscsi_get_initiator_groups') 165 166 167def iscsi_get_target_nodes(client): 168 """Display target nodes. 169 170 Returns: 171 List of ISCSI target node objects. 172 """ 173 return client.call('iscsi_get_target_nodes') 174 175 176def iscsi_enable_histogram(client, name, enable): 177 """Enable/disable histogram dynamically for the specified iscsi target node. 178 179 Args: 180 name: name of iscsi target 181 """ 182 params = {'name': name, "enable": enable} 183 return client.call('iscsi_enable_histogram', params) 184 185 186def iscsi_get_histogram(client, name): 187 """Get histogram for specified iscsi target. 188 189 Args: 190 name: name of iscsi target 191 """ 192 params = {'name': name} 193 return client.call('iscsi_get_histogram', params) 194 195 196def iscsi_create_target_node( 197 client, 198 luns, 199 pg_ig_maps, 200 name, 201 alias_name, 202 queue_depth, 203 chap_group=None, 204 disable_chap=None, 205 require_chap=None, 206 mutual_chap=None, 207 header_digest=None, 208 data_digest=None): 209 """Add a target node. 210 211 Args: 212 luns: List of bdev_name_id_pairs, e.g. [{"bdev_name": "Malloc1", "lun_id": 1}] 213 pg_ig_maps: List of pg_ig_mappings, e.g. [{"pg_tag": pg, "ig_tag": ig}] 214 name: Target node name (ASCII) 215 alias_name: Target node alias name (ASCII) 216 queue_depth: Desired target queue depth 217 chap_group: Authentication group ID for this target node 218 disable_chap: CHAP authentication should be disabled for this target node 219 require_chap: CHAP authentication should be required for this target node 220 mutual_chap: CHAP authentication should be mutual/bidirectional 221 header_digest: Header Digest should be required for this target node 222 data_digest: Data Digest should be required for this target node 223 224 Returns: 225 True or False 226 """ 227 params = { 228 'name': name, 229 'alias_name': alias_name, 230 'pg_ig_maps': pg_ig_maps, 231 'luns': luns, 232 'queue_depth': queue_depth, 233 } 234 235 if chap_group: 236 params['chap_group'] = chap_group 237 if disable_chap: 238 params['disable_chap'] = disable_chap 239 if require_chap: 240 params['require_chap'] = require_chap 241 if mutual_chap: 242 params['mutual_chap'] = mutual_chap 243 if header_digest: 244 params['header_digest'] = header_digest 245 if data_digest: 246 params['data_digest'] = data_digest 247 return client.call('iscsi_create_target_node', params) 248 249 250def iscsi_target_node_add_lun(client, name, bdev_name, lun_id=None): 251 """Add LUN to the target node. 252 253 Args: 254 name: Target node name (ASCII) 255 bdev_name: bdev name 256 lun_id: LUN ID (integer >= 0) 257 258 Returns: 259 True or False 260 """ 261 params = { 262 'name': name, 263 'bdev_name': bdev_name, 264 } 265 if lun_id: 266 params['lun_id'] = lun_id 267 return client.call('iscsi_target_node_add_lun', params) 268 269 270def iscsi_target_node_set_auth( 271 client, 272 name, 273 chap_group=None, 274 disable_chap=None, 275 require_chap=None, 276 mutual_chap=None): 277 """Set CHAP authentication for the target node. 278 279 Args: 280 name: Target node name (ASCII) 281 chap_group: Authentication group ID for this target node 282 disable_chap: CHAP authentication should be disabled for this target node 283 require_chap: CHAP authentication should be required for this target node 284 mutual_chap: CHAP authentication should be mutual/bidirectional 285 286 Returns: 287 True or False 288 """ 289 params = { 290 'name': name, 291 } 292 293 if chap_group: 294 params['chap_group'] = chap_group 295 if disable_chap: 296 params['disable_chap'] = disable_chap 297 if require_chap: 298 params['require_chap'] = require_chap 299 if mutual_chap: 300 params['mutual_chap'] = mutual_chap 301 return client.call('iscsi_target_node_set_auth', params) 302 303 304def iscsi_create_auth_group(client, tag, secrets=None): 305 """Create authentication group for CHAP authentication. 306 307 Args: 308 tag: Authentication group tag (unique, integer > 0). 309 secrets: Array of secrets objects (optional). 310 311 Returns: 312 True or False 313 """ 314 params = {'tag': tag} 315 316 if secrets: 317 params['secrets'] = secrets 318 return client.call('iscsi_create_auth_group', params) 319 320 321def iscsi_delete_auth_group(client, tag): 322 """Delete an authentication group. 323 324 Args: 325 tag: Authentication group tag (unique, integer > 0) 326 327 Returns: 328 True or False 329 """ 330 params = {'tag': tag} 331 return client.call('iscsi_delete_auth_group', params) 332 333 334def iscsi_auth_group_add_secret(client, tag, user, secret, muser=None, msecret=None): 335 """Add a secret to an authentication group. 336 337 Args: 338 tag: Authentication group tag (unique, integer > 0) 339 user: User name for one-way CHAP authentication 340 secret: Secret for one-way CHAP authentication 341 muser: User name for mutual CHAP authentication (optional) 342 msecret: Secret for mutual CHAP authentication (optional) 343 344 Returns: 345 True or False 346 """ 347 params = {'tag': tag, 'user': user, 'secret': secret} 348 349 if muser: 350 params['muser'] = muser 351 if msecret: 352 params['msecret'] = msecret 353 return client.call('iscsi_auth_group_add_secret', params) 354 355 356def iscsi_auth_group_remove_secret(client, tag, user): 357 """Remove a secret from an authentication group. 358 359 Args: 360 tag: Authentication group tag (unique, integer > 0) 361 user: User name for one-way CHAP authentication 362 363 Returns: 364 True or False 365 """ 366 params = {'tag': tag, 'user': user} 367 return client.call('iscsi_auth_group_remove_secret', params) 368 369 370def iscsi_target_node_remove_pg_ig_maps(client, pg_ig_maps, name): 371 """Delete PG-IG maps from the target node. 372 373 Args: 374 pg_ig_maps: List of pg_ig_mappings, e.g. [{"pg_tag": pg, "ig_tag": ig}] 375 name: Target node alias name (ASCII) 376 377 Returns: 378 True or False 379 """ 380 params = { 381 'name': name, 382 'pg_ig_maps': pg_ig_maps, 383 } 384 return client.call('iscsi_target_node_remove_pg_ig_maps', params) 385 386 387def iscsi_target_node_add_pg_ig_maps(client, pg_ig_maps, name): 388 """Add PG-IG maps to the target node. 389 390 Args: 391 pg_ig_maps: List of pg_ig_mappings, e.g. [{"pg_tag": pg, "ig_tag": ig}] 392 name: Target node alias name (ASCII) 393 394 Returns: 395 True or False 396 """ 397 params = { 398 'name': name, 399 'pg_ig_maps': pg_ig_maps, 400 } 401 return client.call('iscsi_target_node_add_pg_ig_maps', params) 402 403 404def iscsi_target_node_set_redirect(client, name, pg_tag, redirect_host, redirect_port): 405 """Update redirect portal of the public portal group for the target node. 406 407 Args: 408 name: Target node name (ASCII) 409 pg_tag: Portal group tag (unique, integer > 0) 410 redirect_host: Numeric IP address to which the target node is redirected 411 redirect_port: Numeric TCP port to which the target node is redirected 412 413 Returns: 414 True or False 415 """ 416 params = { 417 'name': name, 418 'pg_tag': pg_tag 419 } 420 421 if redirect_host: 422 params['redirect_host'] = redirect_host 423 if redirect_port: 424 params['redirect_port'] = redirect_port 425 return client.call('iscsi_target_node_set_redirect', params) 426 427 428def iscsi_target_node_request_logout(client, name, pg_tag): 429 """Request connections to the target node to logout. 430 431 Args: 432 name: Target node name (ASCII) 433 pg_tag: Portal group tag (unique, integer > 0) (optional) 434 435 Returns: 436 True or False 437 """ 438 params = {'name': name} 439 440 if pg_tag: 441 params['pg_tag'] = pg_tag 442 return client.call('iscsi_target_node_request_logout', params) 443 444 445def iscsi_create_portal_group(client, portals, tag, private, wait): 446 """Add a portal group. 447 448 Args: 449 portals: List of portals, e.g. [{'host': ip, 'port': port}] 450 tag: Initiator group tag (unique, integer > 0) 451 private: Public (false) or private (true) portal group for login redirection. 452 wait: Do not listen on portals until it is allowed explicitly. 453 454 Returns: 455 True or False 456 """ 457 params = {'tag': tag, 'portals': portals} 458 459 if private: 460 params['private'] = private 461 if wait: 462 params['wait'] = wait 463 return client.call('iscsi_create_portal_group', params) 464 465 466def iscsi_start_portal_group(client, tag): 467 """Start listening on portals if it is not started yet. 468 469 Args: 470 tag: Portal group tag (unique, integer > 0) 471 472 Returns: 473 True or False 474 """ 475 params = {'tag': tag} 476 return client.call('iscsi_start_portal_group', params) 477 478 479def iscsi_create_initiator_group(client, tag, initiators, netmasks): 480 """Add an initiator group. 481 482 Args: 483 tag: Initiator group tag (unique, integer > 0) 484 initiators: List of initiator hostnames or IP addresses, e.g. 485 ["ANY"] or ["iqn.2016-06.io.spdk:host1","iqn.2016-06.io.spdk:host2"] 486 netmasks: List of initiator netmasks, e.g. ["255.255.0.0","255.248.0.0"] 487 488 Returns: 489 True or False 490 """ 491 params = {'tag': tag, 'initiators': initiators, 'netmasks': netmasks} 492 return client.call('iscsi_create_initiator_group', params) 493 494 495def iscsi_initiator_group_add_initiators( 496 client, 497 tag, 498 initiators=None, 499 netmasks=None): 500 """Add initiators to an existing initiator group. 501 502 Args: 503 tag: Initiator group tag (unique, integer > 0) 504 initiators: List of initiator hostnames or IP addresses, e.g. 505 ["ANY"] or ["iqn.2016-06.io.spdk:host1","iqn.2016-06.io.spdk:host2"] 506 netmasks: List of initiator netmasks, e.g. ["255.255.0.0","255.248.0.0"] 507 508 Returns: 509 True or False 510 """ 511 params = {'tag': tag} 512 513 if initiators: 514 params['initiators'] = initiators 515 if netmasks: 516 params['netmasks'] = netmasks 517 return client.call('iscsi_initiator_group_add_initiators', params) 518 519 520def iscsi_initiator_group_remove_initiators( 521 client, tag, initiators=None, netmasks=None): 522 """Delete initiators from an existing initiator group. 523 524 Args: 525 tag: Initiator group tag (unique, integer > 0) 526 initiators: List of initiator hostnames or IP addresses, e.g. ["127.0.0.1","192.168.200.100"] 527 netmasks: List of initiator netmasks, e.g. ["255.255.0.0","255.248.0.0"] 528 529 Returns: 530 True or False 531 """ 532 params = {'tag': tag} 533 534 if initiators: 535 params['initiators'] = initiators 536 if netmasks: 537 params['netmasks'] = netmasks 538 return client.call('iscsi_initiator_group_remove_initiators', params) 539 540 541def iscsi_delete_target_node(client, target_node_name): 542 """Delete a target node. 543 544 Args: 545 target_node_name: Target node name to be deleted. Example: iqn.2016-06.io.spdk:disk1. 546 547 Returns: 548 True or False 549 """ 550 params = {'name': target_node_name} 551 return client.call('iscsi_delete_target_node', params) 552 553 554def iscsi_delete_portal_group(client, tag): 555 """Delete a portal group. 556 557 Args: 558 tag: Portal group tag (unique, integer > 0) 559 560 Returns: 561 True or False 562 """ 563 params = {'tag': tag} 564 return client.call('iscsi_delete_portal_group', params) 565 566 567def iscsi_delete_initiator_group(client, tag): 568 """Delete an initiator group. 569 570 Args: 571 tag: Initiator group tag (unique, integer > 0) 572 573 Returns: 574 True or False 575 """ 576 params = {'tag': tag} 577 return client.call('iscsi_delete_initiator_group', params) 578 579 580def iscsi_portal_group_set_auth( 581 client, 582 tag, 583 chap_group=None, 584 disable_chap=None, 585 require_chap=None, 586 mutual_chap=None): 587 """Set CHAP authentication for discovery sessions specific for the portal group. 588 589 Args: 590 tag: Portal group tag (unique, integer > 0) 591 chap_group: Authentication group ID for this portal group 592 disable_chap: CHAP authentication should be disabled for this portal group 593 require_chap: CHAP authentication should be required for this portal group 594 mutual_chap: CHAP authentication should be mutual/bidirectional 595 596 Returns: 597 True or False 598 """ 599 params = { 600 'tag': tag, 601 } 602 603 if chap_group: 604 params['chap_group'] = chap_group 605 if disable_chap: 606 params['disable_chap'] = disable_chap 607 if require_chap: 608 params['require_chap'] = require_chap 609 if mutual_chap: 610 params['mutual_chap'] = mutual_chap 611 return client.call('iscsi_portal_group_set_auth', params) 612 613 614def iscsi_get_connections(client): 615 """Display iSCSI connections. 616 617 Returns: 618 List of iSCSI connection. 619 """ 620 return client.call('iscsi_get_connections') 621 622 623def iscsi_get_stats(client): 624 """Display stat information of iSCSI connections. 625 626 Returns: 627 Stat information of iSCSI connections. 628 """ 629 return client.call('iscsi_get_stats') 630 631 632def iscsi_get_options(client): 633 """Display iSCSI global parameters. 634 635 Returns: 636 List of iSCSI global parameter. 637 """ 638 return client.call('iscsi_get_options') 639 640 641def scsi_get_devices(client): 642 """Display SCSI devices. 643 644 Returns: 645 List of SCSI device. 646 """ 647 return client.call('scsi_get_devices') 648