Class List Method List File List

# Class: Yast::IscsiClientLibClass

Inherits:
  Module
  - Object
  - Module
  - Yast::IscsiClientLibClass
  show all
Defined in:
  ../../src/modules/IscsiClientLib.rb

## Instance Method Summary (collapse)

- - (Object) autoLogOn
- - (Object) autoyastPrepare
- - (Object) autoyastWrite
- - (Object) CallConfigScript
- - (Object) checkInitiatorName

  check initiatorname if exist, if no - create it.

- - (Object) connected(check_ip)

  check if given target is connected.

- - (Object) createMap(old_map, comments)

  create map from given map in format needed by ini-agent.

- - (Object) delete(old_list, key)

  delete record with given key.

- - (Object) deleteRecord

  delete deiscovered target from database.

- - (Object) GetAdmCmd(params)
- - (Object) getConfig

  read configuration file.

- - (Object) GetDiscIfaces
- - (Object) getDiscovered

  get all discovered targets.

- - (Object) GetDiscoveryCmd(ip, port, fw)
- - (Object) getiBFT

  get iBFT (available only on some special hardware).

- - (Object) getNode
- - (Object) GetOffloadCard
- - (Object) GetOffloadItems
- - (Object) GetOffloadModules
- - (Object) getReverseDomainName
- - (Object) getServiceStatus

  get status of iscsid.

- - (Object) GetStartService

  get accessor for service status.

- - (Object) getStartupStatus

  get (manual/onboot) status of target connecting.

- - (Object) hidePassword(orig)
- - (Object) InitIfaceFile
- - (Object) InitOffloadCard
- - (Object) LoadOffloadModules
- - (Object) loginIntoTarget(target)
- - (Object) main
- - (Object) oldConfig

  write temporary changed old config.

- - (Object) Overview
- - (Object) readSessions

  get all connected targets.

- - (Object) saveConfig(user_in, pass_in, user_out, pass_out)

  temporary change config for discovery authentication.

- - (Object) ScanDiscovered(data)
- - (Object) setConfig(new_config)
- - (Object) SetOffloadCard(new_card)
- - (Object) setOrAdd(old_list, key, value)

  add or modify given map.

- - (Object) setServiceStatus

  set startup status of iscsid.

- - (Object) SetStartService(status)

  set accessor for service status.

- - (Object) setStartupStatus(status)

  change startup status (manual/onboot) for target.

- - (Object) setValue(name, value)

  update authentication value.

- - (Object) startIScsid
- - (Object) useISNS

  do we use iSNS for targets?.

- - (Object) writeInitiatorName(new_value)

  write InitiatorName, create backup from previous if needed.

## Instance Method Details

### - (`Object`) autoLogOn

    792
    793
    794
    795
    796
    797
    798
    799
    800
    801
    # File '../../src/modules/IscsiClientLib.rb', line 792

    def autoLogOn
      Builtins.y2milestone("begin of autoLogOn function")
      if Ops.greater_than(Builtins.size(getiBFT), 0)
        Builtins.y2milestone(
          "Autologin into iBFT : %1",
          SCR.Execute(path(".target.bash_output"), GetAdmCmd("-m fw -l"))
        )
      end
      true
    end

### - (`Object`) autoyastPrepare

    898
    899
    900
    901
    902
    903
    904
    905
    906
    907
    908
    909
    910
    911
    912
    913
    914
    # File '../../src/modules/IscsiClientLib.rb', line 898

    def autoyastPrepare
      @initiatorname = Ops.get_string(@ay_settings, "initiatorname", "")
      if Ops.greater_than(Builtins.size(@initiatorname), 0)
        file = "/etc/iscsi/initiatorname.iscsi"
        SCR.Write(
          path(".target.string"),
          [file, 384],
          Builtins.sformat("InitiatorName=%1\n", @initiatorname)
        )
      else
        checkInitiatorName
      end
      # start daemon before
      startIScsid

      nil
    end

### - (`Object`) autoyastWrite

    916
    917
    918
    919
    920
    921
    922
    923
    924
    925
    926
    927
    928
    929
    930
    931
    932
    933
    934
    935
    936
    937
    938
    939
    940
    941
    942
    943
    944
    945
    946
    947
    948
    949
    950
    951
    952
    953
    954
    955
    956
    957
    958
    959
    960
    961
    962
    # File '../../src/modules/IscsiClientLib.rb', line 916

    def autoyastWrite
      # do discovery first
      portals = []
      ifaces = []
      ifacepar = ""
      Builtins.foreach(Ops.get_list(@ay_settings, "targets", [])) do |target|
        iface = Ops.get_string(target, "iface", "default")
        if !Builtins.contains(ifaces, iface)
          if Ops.greater_than(Builtins.size(ifacepar), 0)
            ifacepar = Ops.add(ifacepar, " ")
          end
          ifacepar = Ops.add(Ops.add(ifacepar, "-I "), iface)
          ifaces = Builtins.add(ifaces, iface)
        end
      end
      if Ops.greater_than(Builtins.size(Builtins.filter(ifaces) do |s|
          s != "default"
        end), 0)
        CallConfigScript()
      end
      Builtins.foreach(Ops.get_list(@ay_settings, "targets", [])) do |target|
        if !Builtins.contains(portals, Ops.get_string(target, "portal", ""))
          SCR.Execute(
            path(".target.bash"),
            GetAdmCmd(
              Builtins.sformat(
                "-m discovery %1 -t st -p %2",
                ifacepar,
                Ops.get_string(target, "portal", "")
              )
            )
          )
          portals = Builtins.add(portals, Ops.get_string(target, "portal", ""))
        end
      end
      Builtins.foreach(Ops.get_list(@ay_settings, "targets", [])) do |target|
        Builtins.y2internal("login into target %1", target)
        loginIntoTarget(target)
        @currentRecord = [
          Ops.get_string(target, "portal", ""),
          Ops.get_string(target, "target", ""),
          Ops.get_string(target, "iface", "")
        ]
        setStartupStatus(Ops.get_string(target, "startup", "manual"))
      end
      true
    end

### - (`Object`) CallConfigScript

    1393
    1394
    1395
    1396
    1397
    1398
    1399
    1400
    1401
    1402
    1403
    1404
    1405
    1406
    1407
    1408
    1409
    1410
    1411
    1412
    1413
    1414
    1415
    1416
    1417
    1418
    1419
    1420
    1421
    1422
    1423
    # File '../../src/modules/IscsiClientLib.rb', line 1393

    def CallConfigScript
      sl = Builtins.filter(GetDiscIfaces()) { |s| s != "default" }
      Builtins.y2milestone("CallConfigScript list:%1", sl)
      Builtins.foreach(sl) do |s|
        hw = []
        hw = Ops.get(Builtins.maplist(Builtins.filter(@offload_valid) do |i, eth|
          Builtins.contains(
            Builtins.flatten(
              Convert.convert(eth, :from => "list", :to => "list <list>")
            ),
            s
          )
        end) { |i, e| e }, 0, [])
        Builtins.y2milestone("CallConfigScript hw:%1", hw)
        hw = Builtins.find(
          Convert.convert(hw, :from => "list", :to => "list <list>")
        ) { |l| Ops.get_string(l, 2, "") == s }
        Builtins.y2milestone("CallConfigScript hw:%1", hw)
        if hw != nil
          cmd = Ops.add(
            Ops.add(@offboard_script, " "),
            Ops.get_string(hw, 0, "")
          )
          Builtins.y2milestone("CallConfigScript cmd:%1", cmd)
          output = Convert.to_map(SCR.Execute(path(".target.bash_output"), cmd))
          Builtins.y2milestone("CallConfigScript %1", output)
        end
      end

      nil
    end

### - (`Object`) checkInitiatorName

check initiatorname if exist, if no - create it

    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
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    # File '../../src/modules/IscsiClientLib.rb', line 519

    def checkInitiatorName
      ret = true
      file = "/etc/iscsi/initiatorname.iscsi"
      name_from_bios = Ops.get_string(getiBFT, "iface.initiatorname", "")
      # if (size((map<string, any>)SCR::Read (.target.lstat, file)) == 0 || ((map<string, any>)SCR::Read (.target.lstat, file))["size"]:0==0){
      @initiatorname = Ops.get_string(
        Convert.convert(
          SCR.Execute(
            path(".target.bash_output"),
            Builtins.sformat(
              "grep -v '^#' %1 | grep InitiatorName | cut -d'=' -f2 | tr -d '\n'",
              file
            )
          ),
          :from => "any",
          :to   => "map <string, any>"
        ),
        "stdout",
        ""
      )
      # }
      if Builtins.size(@initiatorname) == 0
        if Ops.greater_than(Builtins.size(name_from_bios), 0)
          Builtins.y2milestone(
            "%1 is empty or doesnt exists - replace with name stored in iBFT",
            file
          )
          @initiatorname = name_from_bios
        else
          Builtins.y2milestone("InitiatorName does not exist - generate it")
          domain = Ops.get_string(
            Convert.convert(
              SCR.Execute(path(".target.bash_output"), ""),
              :from => "any",
              :to   => "map <string, any>"
            ),
            "stdout",
            "com.example"
          )
          output = Convert.convert(
            SCR.Execute(
              path(".target.bash_output"),
              Builtins.sformat(
                "/sbin/iscsi-iname -p iqn.%1.%2:01 | tr -d '\n'",
                "`date +%Y-%m`",
                getReverseDomainName
              ),
              {}
            ),
            :from => "any",
            :to   => "map <string, any>"
          )
          if Builtins.size(Ops.get_string(output, "stderr", "")) == 0
            @initiatorname = Ops.get_string(output, "stdout", "")
          else
            ret = false
          end
        end
        ret = writeInitiatorName(@initiatorname)
      else
        Builtins.y2milestone(
          "checkInitiatorName initiatorname=%1",
          @initiatorname
        )
        if Ops.greater_than(Builtins.size(name_from_bios), 0) &&
            name_from_bios != @initiatorname
          Popup.Warning(
            _(
              "InitiatorName from iBFT and from <tt>/etc/iscsi/initiatorname.iscsi</tt>\n" +
                "differ. The old initiator name will be replaced by the value of iBFT and a \n" +
                "backup created. If you want to use a different initiator name, change it \n" +
                "in the BIOS.\n"
            )
          )
          Builtins.y2milestone(
            "replacing old name %1 by name %2 from iBFT",
            @initiatorname,
            name_from_bios
          )
          @initiatorname = name_from_bios
          ret = writeInitiatorName(@initiatorname)
        end
      end
      ret
    end

### - (`Object`) connected(check_ip)

check if given target is connected

    710
    711
    712
    713
    714
    715
    716
    717
    718
    719
    720
    721
    722
    723
    724
    725
    726
    727
    728
    729
    730
    731
    732
    733
    734
    735
    736
    737
    738
    # File '../../src/modules/IscsiClientLib.rb', line 710

    def connected(check_ip)
      Builtins.y2internal(
        "check connected status for %1 with IP check:%2",
        @currentRecord,
        check_ip
      )
      ret = false
      Builtins.foreach(@sessions) do |row|
        list_row = Builtins.splitstring(row, " ")
        if Ops.get(list_row, 1, "") == Ops.get(@currentRecord, 1, "") &&
            Ops.get(list_row, 2, "") == Ops.get(@currentRecord, 2, "") &&
            (check_ip ?
              Ops.get(
                Builtins.splitstring(Ops.get(list_row, 0, ""), ","),
                0,
                ""
              ) ==
                Ops.get(
                  Builtins.splitstring(Ops.get(@currentRecord, 0, ""), ","),
                  0,
                  ""
                ) :
              true)
          ret = true
          raise Break
        end
      end
      ret
    end

### - (`Object`) createMap(old_map, comments)

create map from given map in format needed by ini-agent

    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    # File '../../src/modules/IscsiClientLib.rb', line 258

    def createMap(old_map, comments)
      old_map = deep_copy(old_map)
      comments = deep_copy(comments)
      comment = ""
      Builtins.foreach(comments) do |row|
        comment = Builtins.sformat("%1%2", comment, row)
      end
      {
        "name"    => Ops.get_string(old_map, "KEY", ""),
        "value"   => Ops.get_string(old_map, "VALUE", ""),
        "kind"    => "value",
        "type"    => 1,
        "comment" => comment
      }
    end

### - (`Object`) delete(old_list, key)

delete record with given key

    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    # File '../../src/modules/IscsiClientLib.rb', line 296

    def delete(old_list, key)
      old_list = deep_copy(old_list)
      Builtins.y2milestone("Delete record for %1", key)
      new_list = []
      Builtins.foreach(old_list) do |row|
        if Ops.get_string(row, "name", "") != key
          new_list = Builtins.add(new_list, row)
        end
      end
      deep_copy(new_list)
    end

### - (`Object`) deleteRecord

delete deiscovered target from database

    607
    608
    609
    610
    611
    612
    613
    614
    615
    616
    617
    618
    619
    620
    621
    622
    623
    624
    625
    626
    627
    628
    629
    630
    631
    632
    633
    634
    635
    # File '../../src/modules/IscsiClientLib.rb', line 607

    def deleteRecord
      ret = true
      Builtins.y2milestone("Delete record %1", @currentRecord)

      retcode = Convert.convert(
        SCR.Execute(
          path(".target.bash_output"),
          GetAdmCmd(
            Builtins.sformat(
              "-m node -I %3 -T %1 -p %2 --logout",
              Ops.get(@currentRecord, 1, ""),
              Ops.get(@currentRecord, 0, ""),
              Ops.get(@currentRecord, 2, "default")
            )
          )
        ),
        :from => "any",
        :to   => "map <string, any>"
      )
      if Ops.greater_than(
          Builtins.size(Ops.get_string(retcode, "stderr", "")),
          0
        )
        return false
      end

      readSessions
      ret
    end

### - (`Object`) GetAdmCmd(params)

    94
    95
    96
    97
    98
    99
    # File '../../src/modules/IscsiClientLib.rb', line 94

    def GetAdmCmd(params)
      ret = "iscsiadm"
      ret = Ops.add(Ops.add(ret, " "), params)
      Builtins.y2milestone("GetAdmCmd:%1", ret)
      ret
    end

### - (`Object`) getConfig

read configuration file

    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    # File '../../src/modules/IscsiClientLib.rb', line 176

    def getConfig
      # use cache if available
      if Builtins.size(@config) == 0
        @config = Convert.convert(
          SCR.Read(path(".etc.iscsid.all")),
          :from => "any",
          :to   => "map <string, any>"
        )
        Builtins.y2debug("read config %1", @config)
      end
      Ops.get_list(@config, "value", [])
    end

### - (`Object`) GetDiscIfaces

    1379
    1380
    1381
    1382
    1383
    1384
    1385
    1386
    1387
    1388
    1389
    1390
    1391
    1392
    # File '../../src/modules/IscsiClientLib.rb', line 1379

    def GetDiscIfaces
      ret = []
      if GetOffloadCard() == "all"
        tl = Builtins.maplist(GetOffloadItems()) do |t|
          Ops.get_string(Builtins.argsof(t), [0, 0], "")
        end
        Builtins.y2milestone("GetDiscIfaces:%1", tl)
        ret = Builtins.filter(tl) { |s| s != "all" }
      else
        ret = [GetOffloadCard()]
      end
      Builtins.y2milestone("GetDiscIfaces:%1", ret)
      deep_copy(ret)
    end

### - (`Object`) getDiscovered

get all discovered targets

    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    # File '../../src/modules/IscsiClientLib.rb', line 389

    def getDiscovered
      @discovered = []
      retcode = Convert.convert(
        SCR.Execute(path(".target.bash_output"), GetAdmCmd("-m node -P 1")),
        :from => "any",
        :to   => "map <string, any>"
      )
      if Builtins.size(Ops.get_string(retcode, "stderr", "")) == 0
        @discovered = ScanDiscovered(
          Builtins.splitstring(Ops.get_string(retcode, "stdout", ""), "\n")
        )
      end
      deep_copy(@discovered)
    end

### - (`Object`) GetDiscoveryCmd(ip, port, fw)

    1425
    1426
    1427
    1428
    1429
    1430
    1431
    1432
    1433
    1434
    1435
    1436
    1437
    1438
    1439
    1440
    1441
    1442
    1443
    1444
    1445
    1446
    1447
    1448
    1449
    1450
    1451
    # File '../../src/modules/IscsiClientLib.rb', line 1425

    def GetDiscoveryCmd(ip, port, fw)
      Builtins.y2milestone("GetDiscoveryCmd ip:%1 port:%2 fw:%3", ip, port, fw)
      command = "-m discovery -P 1"
      if useISNS
        command = Ops.add(command, " -t isns")
      else
        ifs = GetDiscIfaces()
        Builtins.y2milestone("ifs=%1", ifs)
        ifs = Builtins.maplist(ifs) { |s| Ops.add("-I ", s) }
        Builtins.y2milestone("ifs=%1", ifs)
        tgt = "st"
        tgt = "fw" if fw
        command = Ops.add(
          command,
          Builtins.sformat(
            " -t %4 %3 -p %1:%2",
            ip,
            port,
            Builtins.mergestring(ifs, " "),
            tgt
          )
        )
      end
      command = GetAdmCmd(command)
      Builtins.y2milestone("GetDiscoveryCmd %1", command)
      command
    end

### - (`Object`) getiBFT

get iBFT (available only on some special hardware)

    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
    # File '../../src/modules/IscsiClientLib.rb', line 113

    def getiBFT
      if @ibft == nil
        if !Arch.i386 && !Arch.x86_64
          Builtins.y2milestone(
            "Because architecture %1 is is different from x86, not using iBFT",
            Arch.arch_short
          )
          return {}
        end
        @ibft = {}
        Builtins.y2milestone(
          "check and modprobe iscsi_ibft : %1",
          SCR.Execute(
            path(".target.bash_output"),
            "lsmod |grep -q iscsi_ibft || modprobe iscsi_ibft"
          )
        )
        from_bios = Ops.get_string(
          Convert.convert(
            SCR.Execute(path(".target.bash_output"), GetAdmCmd("-m fw")),
            :from => "any",
            :to   => "map <string, any>"
          ),
          "stdout",
          ""
        )
        Builtins.foreach(Builtins.splitstring(from_bios, "\n")) do |row|
          key_val = Builtins.splitstring(row, "=")
          #   if (size(key_val[0]:"")>0) ibft[key_val[0]:""] = key_val[1]:"";
          kv = String.CutBlanks(Ops.get(key_val, 0, ""))
          if Ops.greater_than(Builtins.size(kv), 0)
            Ops.set(@ibft, kv, String.CutBlanks(Ops.get(key_val, 1, "")))
          end
        end
      end
      Builtins.y2milestone("iBFT %1", hidePassword(@ibft))
      deep_copy(@ibft)
    end

### - (`Object`) getNode

    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
    # File '../../src/modules/IscsiClientLib.rb', line 219

    def getNode
      cmdline = GetAdmCmd(
        Builtins.sformat(
          "-S -m node -I %3 -T %1 -p %2",
          Ops.get(@currentRecord, 1, ""),
          Ops.get(@currentRecord, 0, ""),
          Ops.get(@currentRecord, 2, "default")
        )
      )
      cmd = Convert.convert(
        SCR.Execute(path(".target.bash_output"), cmdline),
        :from => "any",
        :to   => "map <string, any>"
      )
      return {} if Ops.get_integer(cmd, "exit", 0) != 0
      auth = {}
      Builtins.foreach(
        Builtins.splitstring(Ops.get_string(cmd, "stdout", ""), "\n")
      ) do |row|
        key = Ops.get(Builtins.splitstring(row, " = "), 0, "")
        val = Ops.get(Builtins.splitstring(row, " = "), 3, "")
        val = "" if val == "<empty>"
        case key
          when "node.session.auth.authmethod"
            Ops.set(auth, "authmethod", val)
          when "node.session.auth.username"
            Ops.set(auth, "username", val)
          when "node.session.auth.password"
            Ops.set(auth, "password", val)
          when "node.session.auth.username_in"
            Ops.set(auth, "username_in", val)
          when "node.session.auth.password_in"
            Ops.set(auth, "password_in", val)
        end
      end
      deep_copy(auth)
    end

### - (`Object`) GetOffloadCard

    80
    81
    82
    # File '../../src/modules/IscsiClientLib.rb', line 80

    def GetOffloadCard
      @offload_card
    end

### - (`Object`) GetOffloadItems

    1105
    1106
    1107
    1108
    1109
    1110
    1111
    1112
    1113
    1114
    1115
    1116
    1117
    1118
    1119
    1120
    1121
    1122
    1123
    1124
    1125
    1126
    1127
    1128
    1129
    1130
    1131
    1132
    1133
    1134
    1135
    1136
    1137
    1138
    1139
    1140
    1141
    1142
    1143
    1144
    1145
    1146
    1147
    1148
    1149
    1150
    1151
    1152
    1153
    1154
    1155
    1156
    1157
    1158
    1159
    1160
    1161
    1162
    1163
    1164
    1165
    1166
    1167
    1168
    1169
    1170
    1171
    1172
    1173
    1174
    1175
    1176
    1177
    1178
    1179
    1180
    1181
    1182
    1183
    1184
    1185
    1186
    1187
    1188
    1189
    1190
    1191
    1192
    1193
    1194
    1195
    1196
    1197
    1198
    1199
    1200
    1201
    1202
    1203
    1204
    1205
    1206
    1207
    1208
    1209
    1210
    1211
    1212
    1213
    1214
    1215
    1216
    1217
    1218
    1219
    1220
    1221
    1222
    1223
    1224
    1225
    1226
    1227
    1228
    1229
    1230
    1231
    1232
    1233
    1234
    1235
    1236
    1237
    1238
    1239
    1240
    1241
    1242
    1243
    1244
    1245
    1246
    1247
    1248
    1249
    1250
    1251
    1252
    1253
    1254
    1255
    1256
    1257
    1258
    1259
    1260
    1261
    1262
    1263
    1264
    1265
    1266
    1267
    1268
    1269
    1270
    1271
    1272
    1273
    1274
    1275
    1276
    1277
    1278
    1279
    1280
    1281
    1282
    1283
    1284
    1285
    1286
    1287
    1288
    1289
    1290
    1291
    1292
    1293
    1294
    1295
    1296
    1297
    1298
    1299
    1300
    1301
    1302
    1303
    1304
    1305
    1306
    1307
    1308
    1309
    1310
    1311
    1312
    1313
    1314
    1315
    1316
    1317
    1318
    1319
    1320
    1321
    1322
    1323
    1324
    1325
    1326
    1327
    1328
    1329
    1330
    1331
    1332
    1333
    1334
    1335
    1336
    1337
    1338
    1339
    1340
    1341
    1342
    1343
    1344
    1345
    1346
    1347
    1348
    1349
    1350
    1351
    1352
    1353
    # File '../../src/modules/IscsiClientLib.rb', line 1105

    def GetOffloadItems
      i = 0
      init = false
      if @offload_valid == nil
        init = true
        InitIfaceFile()
        @offload_valid = {}
        cards = Convert.convert(
          SCR.Read(path(".probe.netcard")),
          :from => "any",
          :to   => "list <map>"
        )
        hw_mods = Builtins.maplist(cards) do |c|
          Builtins.y2milestone("GetOffloadItems card:%1", c)
          tmp = Builtins.maplist(Ops.get_list(c, "drivers", [])) do |m|
            Builtins.flatten(Ops.get_list(m, "modules", []))
          end
          r = {
            "modules" => Builtins.maplist(tmp) { |ml| Ops.get_string(ml, 0, "") },
            "iface"   => Ops.get_string(c, "dev_name", ""),
            "macaddr" => Ops.get_string(
              c,
              ["resource", "hwaddr", 0, "addr"],
              ""
            )
          }
          Builtins.y2milestone("GetOffloadItems cinf:%1", r)
          deep_copy(r)
        end
        idx = 0
        Builtins.foreach(@offload) do |l|
          valid = false
          mod = Convert.convert(
            Builtins.sort(Ops.get_list(l, 2, [])),
            :from => "list",
            :to   => "list <string>"
          )
          if Ops.greater_than(Builtins.size(mod), 0)
            i = 0
            Builtins.foreach(hw_mods) do |hw|
              if Ops.greater_than(
                  Builtins.size(
                    Builtins::Multiset.intersection(
                      mod,
                      Convert.convert(
                        Builtins.sort(Ops.get_list(hw, "modules", [])),
                        :from => "list",
                        :to   => "list <string>"
                      )
                    )
                  ),
                  0
                )
                Builtins.y2milestone("GetOffloadItems l:%1", l)
                Builtins.y2milestone("GetOffloadItems valid:%1", hw)
                Ops.set(
                  @offload_valid,
                  idx,
                  Builtins.add(
                    Ops.get(@offload_valid, idx, []),
                    [
                      Ops.get_string(hw, "iface", ""),
                      Ops.get_string(hw, "macaddr", ""),
                      Ops.add(
                        Ops.add(Ops.get_string(hw, "iface", ""), "-"),
                        Ops.get_string(l, [3, 0], "")
                      )
                    ]
                  )
                )
              end
            end
          end
          idx = Ops.add(idx, 1)
        end
        offload_res = {}
        cmd = ""
        Builtins.foreach(@offload_valid) do |i2, eth|
          Ops.set(
            @offload_valid,
            i2,
            Builtins.filter(
              Convert.convert(eth, :from => "list", :to => "list <list>")
            ) do |l|
              cmd = Ops.add(
                Ops.add(
                  Ops.add(@offboard_script, " "),
                  Ops.get_string(l, 0, "")
                ),
                " | grep ..:..:..:.."
              )
              Builtins.y2milestone("GetOffloadItems cmd:%1", cmd)
              out = Convert.to_map(
                SCR.Execute(path(".target.bash_output"), cmd)
              )
              Builtins.y2milestone(
                "GetOffloadItems iscsi_offload out:%1",
                SCR.Execute(
                  path(".target.bash_output"),
                  Ops.add(
                    Ops.add(@offboard_script, " "),
                    Ops.get_string(l, 0, "")
                  )
                )
              )
              Ops.set(offload_res, Ops.get_string(l, 0, ""), {})
              Ops.set(
                offload_res,
                [Ops.get_string(l, 0, ""), "exit"],
                Ops.get_integer(out, "exit", 1)
              )
              sl = []
              if Ops.get_integer(out, "exit", 1) == 0
                sl = Builtins.splitstring(
                  Ops.get_string(out, "stdout", ""),
                  " \n"
                )
                Ops.set(
                  offload_res,
                  [Ops.get_string(l, 0, ""), "hwaddr"],
                  Ops.get(sl, 0, "")
                )
                Ops.set(
                  offload_res,
                  [Ops.get_string(l, 0, ""), "ntype"],
                  Ops.get(sl, 1, "")
                )
              end
              Ops.get_integer(out, "exit", 1) == 0 &&
                Ops.greater_than(Builtins.size(Ops.get(sl, 0, "")), 0)
            end
          )
        end
        Builtins.y2milestone("GetOffloadItems offload_res:%1", offload_res)
        Builtins.y2milestone("GetOffloadItems offload_valid:%1", @offload_valid)
        Builtins.foreach(@offload_valid) do |i2, eth|
          Ops.set(
            @offload_valid,
            i2,
            Builtins.maplist(
              Convert.convert(eth, :from => "list", :to => "list <list>")
            ) do |l|
              Ops.set(
                l,
                1,
                Ops.get_string(
                  offload_res,
                  [Ops.get_string(l, 0, ""), "hwaddr"],
                  ""
                )
              )
              deep_copy(l)
            end
          )
        end
        Builtins.y2milestone("GetOffloadItems offload_valid:%1", @offload_valid)
        Builtins.foreach(@offload_valid) do |i2, eth|
          Ops.set(
            @offload_valid,
            i2,
            Builtins.maplist(
              Convert.convert(eth, :from => "list", :to => "list <list>")
            ) do |l|
              cmd = Ops.add("ifconfig ", Ops.get_string(l, 0, ""))
              Builtins.y2milestone("GetOffloadItems cmd:%1", cmd)
              out = Convert.to_map(
                SCR.Execute(path(".target.bash_output"), cmd)
              )
              Builtins.y2milestone("GetOffloadItems out:%1", out)
              line = Ops.get(
                Builtins.filter(
                  Builtins.splitstring(Ops.get_string(out, "stdout", ""), "\n")
                ) { |ln| Builtins.search(ln, "inet addr:") != nil },
                0,
                ""
              )
              Builtins.y2milestone("GetOffloadItems line:%1", line)
              ipaddr = "unknown"
              if Ops.greater_than(Builtins.size(line), 0)
                line = Builtins.substring(
                  line,
                  Ops.add(Builtins.search(line, "inet addr:"), 10)
                )
                Builtins.y2milestone("GetOffloadItems line:%1", line)
                ipaddr = Builtins.substring(
                  line,
                  0,
                  Builtins.findfirstof(line, " \t")
                )
              end
              l = Builtins.add(l, ipaddr)
              deep_copy(l)
            end
          )
        end
        Builtins.y2milestone("GetOffloadItems offload_valid:%1", @offload_valid)
      end
      entries = {}
      Builtins.foreach(@offload_valid) do |i2, eth|
        Builtins.foreach(
          Convert.convert(eth, :from => "list", :to => "list <list>")
        ) do |l|
          if Ops.greater_than(Builtins.size(Ops.get_string(l, 0, "")), 0)
            s = Ops.get_string(l, 0, "")
            if Ops.greater_than(Builtins.size(Ops.get_string(l, 1, "")), 0)
              s = Ops.add(Ops.add(s, " - "), Ops.get_string(l, 1, ""))
            end
            s = Ops.add(
              Ops.add(s, " - "),
              Ops.get_string(@offload, [i2, 1], "")
            )
            Ops.set(entries, Ops.get_string(l, 2, ""), s)
          end
        end
      end
      Builtins.y2milestone("GetOffloadItems entries:%1", entries)
      @iface_eth = Builtins.sort(Builtins.maplist(entries) { |e, val| e })
      Builtins.y2milestone("GetOffloadItems eth:%1", @iface_eth)
      if init
        @offload_card = InitOffloadCard()
        Builtins.y2milestone("GetOffloadItems offload_card:%1", @offload_card)
      end
      ret = [
        Item(
          Id(Ops.get_string(@offload, [0, 0], "")),
          Ops.get_string(@offload, [0, 1], ""),
          @offload_card == Ops.get_string(@offload, [0, 0], "")
        )
      ]
      if Ops.greater_than(Builtins.size(@offload_valid), 0)
        ret = Builtins.add(
          ret,
          Item(
            Id(Ops.get_string(@offload, [1, 0], "")),
            Ops.get_string(@offload, [1, 1], ""),
            @offload_card == Ops.get_string(@offload, [1, 0], "")
          )
        )
      end
      ret = Convert.convert(
        Builtins.merge(ret, Builtins.maplist(@iface_eth) do |e|
          Item(Id(e), Ops.get(entries, e, ""), @offload_card == e)
        end),
        :from => "list",
        :to   => "list <term>"
      )
      Builtins.y2milestone("GetOffloadItems ret:%1", ret)
      deep_copy(ret)
    end

### - (`Object`) GetOffloadModules

    1355
    1356
    1357
    1358
    1359
    1360
    1361
    1362
    1363
    1364
    1365
    1366
    1367
    1368
    # File '../../src/modules/IscsiClientLib.rb', line 1355

    def GetOffloadModules
      it = nil
      it = GetOffloadItems() if @offload_valid == nil
      modules = []
      Builtins.foreach(@offload_valid) do |i, l|
        modules = Convert.convert(
          Builtins.union(modules, Ops.get_list(@offload, [i, 3], [])),
          :from => "list",
          :to   => "list <string>"
        )
      end
      Builtins.y2milestone("GetOffloadModules %1", modules)
      deep_copy(modules)
    end

### - (`Object`) getReverseDomainName

    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
    # File '../../src/modules/IscsiClientLib.rb', line 490

    def getReverseDomainName
      host_fq = Hostname.SplitFQ(
        Ops.get_string(
          Convert.convert(
            SCR.Execute(path(".target.bash_output"), "hostname -f|tr -d '\n'"),
            :from => "any",
            :to   => "map <string, any>"
          ),
          "stdout",
          ""
        )
      )
      Builtins.y2internal("hostfw%1", host_fq)
      domain = ""

      Builtins.foreach(
        Builtins.splitstring(Ops.get(host_fq, 1, "example.com"), ".")
      ) do |item|
        Builtins.y2internal("item %1", item)
        domain = Builtins.size(domain) == 0 ?
          item :
          Builtins.sformat("%1.%2", item, domain)
      end

      Builtins.y2milestone("domain %1", domain)
      domain
    end

### - (`Object`) getServiceStatus

get status of iscsid

    866
    867
    868
    869
    870
    871
    872
    873
    874
    875
    876
    877
    878
    879
    # File '../../src/modules/IscsiClientLib.rb', line 866

    def getServiceStatus
      ret = true
      if Stage.initial
        ModuleLoading.Load("iscsi_tcp", "", "", "", false, true)
        # start daemon before
        startIScsid
      else
        @serviceStatus = true if Service.Status("iscsid") == 0
        Builtins.y2milestone("Service status = %1", @serviceStatus)
        # if not enabled, start it manually
        Service.Start("iscsid") if !@serviceStatus
      end
      ret
    end

### - (`Object`) GetStartService

get accessor for service status

    154
    155
    156
    157
    158
    # File '../../src/modules/IscsiClientLib.rb', line 154

    def GetStartService
      status = Service.Enabled("iscsid")
      Builtins.y2milestone("Status of iscsid %1", status)
      status
    end

### - (`Object`) getStartupStatus

get (manual/onboot) status of target connecting

    638
    639
    640
    641
    642
    643
    644
    645
    646
    647
    648
    649
    650
    651
    652
    653
    654
    655
    656
    657
    658
    659
    660
    661
    662
    663
    664
    665
    666
    667
    668
    669
    670
    671
    672
    673
    674
    675
    676
    # File '../../src/modules/IscsiClientLib.rb', line 638

    def getStartupStatus
      status = ""
      Builtins.y2milestone("Getting status of record %1", @currentRecord)
      retcode = Convert.convert(
        SCR.Execute(
          path(".target.bash_output"),
          GetAdmCmd(
            Builtins.sformat(
              "-m node -I %3 -T %1 -p %2",
              Ops.get(@currentRecord, 1, ""),
              Ops.get(@currentRecord, 0, ""),
              Ops.get(@currentRecord, 2, "default")
            )
          )
        ),
        :from => "any",
        :to   => "map <string, any>"
      )
      if Ops.greater_than(
          Builtins.size(Ops.get_string(retcode, "stderr", "")),
          0
        )
        return ""
      end
      Builtins.foreach(
        Builtins.splitstring(Ops.get_string(retcode, "stdout", ""), "\n")
      ) do |row|
        if Builtins.issubstring(row, "node.conn[0].startup")
          status = Ops.get(Builtins.splitstring(row, " "), 2, "")
          raise Break
        end
      end
      Builtins.y2milestone(
        "Startup status for %1 is %2",
        @currentRecord,
        status
      )
      status
    end

### - (`Object`) hidePassword(orig)

    101
    102
    103
    104
    105
    106
    107
    108
    109
    # File '../../src/modules/IscsiClientLib.rb', line 101

    def hidePassword(orig)
      orig = deep_copy(orig)
      hidden = {}
      Builtins.foreach(orig) do |key, value|
        value = "*****" if Builtins.issubstring(key, "PASS")
        Ops.set(hidden, key, value)
      end
      deep_copy(hidden)
    end

### - (`Object`) InitIfaceFile

    1047
    1048
    1049
    1050
    1051
    1052
    1053
    1054
    1055
    1056
    1057
    1058
    1059
    1060
    1061
    1062
    1063
    1064
    1065
    1066
    1067
    1068
    1069
    1070
    1071
    1072
    1073
    1074
    1075
    1076
    1077
    1078
    1079
    1080
    1081
    1082
    1083
    1084
    1085
    1086
    1087
    1088
    1089
    1090
    1091
    1092
    1093
    1094
    1095
    1096
    1097
    1098
    1099
    1100
    1101
    1102
    1103
    # File '../../src/modules/IscsiClientLib.rb', line 1047

    def InitIfaceFile
      @iface_file = {}
      files = Convert.convert(
        SCR.Read(path(".target.dir"), "/etc/iscsi/ifaces"),
        :from => "any",
        :to   => "list <string>"
      )
      Builtins.y2milestone("InitIfaceFile files:%1", files)
      if files == nil || Builtins.size(files) == 0
        cmd = GetAdmCmd("-m iface")
        Builtins.y2milestone("InitIfaceFile cmd:%1", cmd)
        Builtins.y2milestone(
          "InitIfaceFile ret:%1",
          SCR.Execute(path(".target.bash_output"), cmd)
        )
        files = Convert.convert(
          SCR.Read(path(".target.dir"), "/etc/iscsi/ifaces"),
          :from => "any",
          :to   => "list <string>"
        )
        Builtins.y2milestone("InitIfaceFile files:%1", files)
      end
      Builtins.foreach(files) do |file|
        ls = Builtins.splitstring(
          Convert.to_string(
            SCR.Read(
              path(".target.string"),
              Ops.add("/etc/iscsi/ifaces/", file)
            )
          ),
          "\n"
        )
        Builtins.y2milestone("InitIfaceFile file:%1", file)
        Builtins.y2milestone("InitIfaceFile ls:%1", ls)
        ls = Builtins.filter(ls) do |l|
          Builtins.search(l, "iface.iscsi_ifacename") != nil
        end
        Builtins.y2milestone("InitIfaceFile ls:%1", ls)
        if Ops.greater_than(Builtins.size(ls), 0)
          Ops.set(
            @iface_file,
            Ops.get(
              Builtins.splitstring(
                Builtins.deletechars(Ops.get(ls, 0, ""), " "),
                "="
              ),
              1,
              ""
            ),
            file
          )
        end
      end
      Builtins.y2milestone("InitIfaceFile iface_file:%1", @iface_file)

      nil
    end

### - (`Object`) InitOffloadCard

    1016
    1017
    1018
    1019
    1020
    1021
    1022
    1023
    1024
    1025
    1026
    1027
    1028
    1029
    1030
    1031
    1032
    1033
    1034
    1035
    1036
    1037
    1038
    1039
    1040
    1041
    1042
    1043
    1044
    1045
    # File '../../src/modules/IscsiClientLib.rb', line 1016

    def InitOffloadCard
      ret = "default"
      retcode = Convert.convert(
        SCR.Execute(path(".target.bash_output"), GetAdmCmd("-m node -P 1")),
        :from => "any",
        :to   => "map <string, any>"
      )
      ifaces = []
      if Builtins.size(Ops.get_string(retcode, "stderr", "")) == 0
        Builtins.foreach(
          ScanDiscovered(
            Builtins.splitstring(Ops.get_string(retcode, "stdout", ""), "\n")
          )
        ) do |s|
          sl = Builtins.splitstring(s, "  ")
          if Ops.greater_than(Builtins.size(Ops.get(sl, 2, "")), 0) &&
              !Builtins.contains(ifaces, Ops.get(sl, 2, ""))
            ifaces = Builtins.add(ifaces, Ops.get(sl, 2, ""))
          end
        end
      end
      Builtins.y2milestone("InitOffloadCard ifaces:%1", ifaces)
      if Ops.greater_than(Builtins.size(ifaces), 1)
        ret = "all"
      elsif Builtins.contains(@iface_eth, Ops.get(ifaces, 0, ""))
        ret = Ops.get(ifaces, 0, "default")
      end
      Builtins.y2milestone("InitOffloadCard ret:%1", ret)
      ret
    end

### - (`Object`) LoadOffloadModules

    1370
    1371
    1372
    1373
    1374
    1375
    1376
    1377
    # File '../../src/modules/IscsiClientLib.rb', line 1370

    def LoadOffloadModules
      mods = GetOffloadModules()
      Builtins.foreach(mods) do |s|
        Builtins.y2milestone("Loading module %1", s)
        ModuleLoading.Load(s, "", "", "", false, true)
      end
      deep_copy(mods)
    end

### - (`Object`) loginIntoTarget(target)

    804
    805
    806
    807
    808
    809
    810
    811
    812
    813
    814
    815
    816
    817
    818
    819
    820
    821
    822
    823
    824
    825
    826
    827
    828
    829
    830
    831
    832
    833
    834
    835
    836
    837
    838
    839
    840
    841
    842
    843
    844
    845
    846
    847
    848
    849
    850
    851
    852
    853
    854
    855
    856
    857
    858
    859
    860
    861
    862
    # File '../../src/modules/IscsiClientLib.rb', line 804

    def loginIntoTarget(target)
      target = deep_copy(target)
      @currentRecord = [
        Ops.get_string(target, "portal", ""),
        Ops.get_string(target, "target", ""),
        Ops.get_string(target, "iface", "")
      ]
      if Ops.get_string(target, "authmethod", "None") != "None"
        user_in = Ops.get_string(target, "username_in", "")
        pass_in = Ops.get_string(target, "password_in", "")
        if Ops.greater_than(Builtins.size(user_in), 0) &&
            Ops.greater_than(Builtins.size(pass_in), 0)
          setValue("node.session.auth.username_in", user_in)
          setValue("node.session.auth.password_in", pass_in)
        else
          setValue("node.session.auth.username_in", "")
          setValue("node.session.auth.password_in", "")
        end
        user_out = Ops.get_string(target, "username", "")
        pass_out = Ops.get_string(target, "password", "")
        if Ops.greater_than(Builtins.size(user_out), 0) &&
            Ops.greater_than(Builtins.size(pass_out), 0)
          setValue("node.session.auth.username", user_out)
          setValue("node.session.auth.password", pass_out)
          setValue("node.session.auth.authmethod", "CHAP")
        else
          setValue("node.session.auth.username", "")
          setValue("node.session.auth.password", "")
          setValue("node.session.auth.authmethod", "")
        end
      else
        setValue("node.session.auth.authmethod", "None")
      end

      output = Convert.convert(
        SCR.Execute(
          path(".target.bash_output"),
          GetAdmCmd(
            Builtins.sformat(
              "-m node -I %3 -T %1 -p %2 --login",
              Ops.get_string(target, "target", ""),
              Ops.get_string(target, "portal", ""),
              Ops.get_string(target, "iface", "")
            )
          )
        ),
        :from => "any",
        :to   => "map <string, any>"
      )
      Builtins.y2internal("output %1", output)
      # if (output["exit"]:-1==0){
      # set startup status to auto by default (bnc#400610)
      setStartupStatus("onboot") if !Mode.autoinst
      true
      # } else {
      # 	y2error("Error while Log-on into target : %1", output);
      # 	return false;
      # 	}
    end

### - (`Object`) main

    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
    # File '../../src/modules/IscsiClientLib.rb', line 28

    def main
      textdomain "iscsi-client"

      Yast.import "Service"
      Yast.import "Popup"
      Yast.import "Hostname"
      Yast.import "Stage"
      Yast.import "ModuleLoading"
      Yast.import "Mode"
      Yast.import "String"
      Yast.import "Arch"

      @sessions = []
      @discovered = []
      @targets = []
      @currentRecord = []
      @iface_file = {}
      @iface_eth = []

      # status of rciscsid service
      @serviceStatus = false
      # main configuration file (/etc/iscsi/iscsid.conf)
      @config = {}
      # iBFT (iSCSI Boot Firmware Table)
      @ibft = nil
      # InitiatorName file (/etc/iscsi/initiatorname.iscsi)
      @initiatorname = ""
      # map used for autoYaST
      @ay_settings = nil
      # interface type for hardware offloading
      @offload_card = "default"

      @offboard_script = "iscsi_offload"

      @offload = [
        ["default", "default" + " " + _("(Software)"), [], []],
        ["all", "all", [], []],
        ["bnx2", "bnx2/bnx2i/bnx2x", ["bnx2", "bnx2i", "bnx2x"], ["bnx2i"]],
        ["cxgb3", "cxgb3/cxgb3i", ["cxgb3", "cxgb3i"], ["cxgb3i"]],
        ["enic", "enic/cnic/fnic", ["enic", "fnic"], ["fnic"]],
        [
          "qla4xxx",
          "qla3xxx/qla4xxx",
          ["qla4xxx", "qla3xxx", "qlcnic"],
          ["qla4xxx"]
        ],
        ["be2net", "be2net/be2iscsi", ["be2net", "be2iscsi"], ["be2iscsi"]]
      ]

      @offload_valid = nil
    end

### - (`Object`) oldConfig

write temporary changed old config

    210
    211
    212
    213
    214
    215
    216
    # File '../../src/modules/IscsiClientLib.rb', line 210

    def oldConfig
      Builtins.y2milestone("Store temporary config %1", @config)
      SCR.Write(path(".etc.iscsid.all"), @config)
      SCR.Write(path(".etc.iscsid"), nil)

      nil
    end

### - (`Object`) Overview

    964
    965
    966
    967
    968
    969
    970
    971
    972
    973
    974
    975
    976
    977
    978
    979
    980
    981
    982
    983
    984
    985
    986
    987
    988
    989
    990
    991
    992
    993
    994
    995
    996
    997
    998
    999
    1000
    1001
    1002
    1003
    1004
    1005
    1006
    1007
    1008
    1009
    1010
    1011
    1012
    1013
    1014
    # File '../../src/modules/IscsiClientLib.rb', line 964

    def Overview
      overview = _("Configuration summary...")
      if Ops.greater_than(Builtins.size(@ay_settings), 0)
        overview = ""
        if Ops.greater_than(
            Builtins.size(Ops.get_string(@ay_settings, "initiatorname", "")),
            0
          )
          overview = Ops.add(
            Ops.add(
              Ops.add(overview, "<p><b>Initiatorname: </b>"),
              Ops.get_string(@ay_settings, "initiatorname", "")
            ),
            "</p>"
          )
        end
        if Ops.greater_than(
            Builtins.size(Ops.get_list(@ay_settings, "targets", [])),
            0
          )
          Builtins.foreach(Ops.get_list(@ay_settings, "targets", [])) do |target|
            overview = Ops.add(
              Ops.add(
                Ops.add(
                  Ops.add(
                    Ops.add(
                      Ops.add(
                        Ops.add(
                          Ops.add(
                            Ops.add(overview, "<p>"),
                            Ops.get_string(target, "portal", "")
                          ),
                          ", "
                        ),
                        Ops.get_string(target, "target", "")
                      ),
                      ", "
                    ),
                    Ops.get_string(target, "iface", "")
                  ),
                  ", "
                ),
                Ops.get_string(target, "startup", "")
              ),
              "</p>"
            )
          end
        end
      end
      overview
    end

### - (`Object`) readSessions

get all connected targets

    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    # File '../../src/modules/IscsiClientLib.rb', line 429

    def readSessions
      Builtins.y2milestone("reading current settings")
      retcode = Convert.convert(
        SCR.Execute(path(".target.bash_output"), GetAdmCmd("-m session -P 1")),
        :from => "any",
        :to   => "map <string, any>"
      )
      @sessions = ScanDiscovered(
        Builtins.splitstring(Ops.get_string(retcode, "stdout", ""), "\n")
      )
      Builtins.y2milestone(
        "Return list from iscsiadm -m session: %1",
        @sessions
      )
      true
    end

### - (`Object`) saveConfig(user_in, pass_in, user_out, pass_out)

temporary change config for discovery authentication

    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
    # File '../../src/modules/IscsiClientLib.rb', line 309

    def saveConfig(user_in, pass_in, user_out, pass_out)
      Builtins.y2milestone("Save config")
      tmp_conf = deep_copy(@config)
      tmp_val = Ops.get_list(tmp_conf, "value", [])

      if Ops.greater_than(Builtins.size(user_in), 0) &&
          Ops.greater_than(Builtins.size(pass_in), 0)
        tmp_val = setOrAdd(tmp_val, "node.session.auth.username", user_in)
        tmp_val = setOrAdd(tmp_val, "node.session.auth.password", pass_in)
      else
        tmp_val = delete(tmp_val, "node.session.auth.username")
        tmp_val = delete(tmp_val, "node.session.auth.password")
      end

      if Ops.greater_than(Builtins.size(user_out), 0) &&
          Ops.greater_than(Builtins.size(pass_out), 0)
        tmp_val = setOrAdd(
          tmp_val,
          "discovery.sendtargets.auth.authmethod",
          "CHAP"
        )
        tmp_val = setOrAdd(
          tmp_val,
          "discovery.sendtargets.auth.username",
          user_out
        )
        tmp_val = setOrAdd(
          tmp_val,
          "discovery.sendtargets.auth.password",
          pass_out
        )
      else
        tmp_val = delete(tmp_val, "discovery.sendtargets.auth.authmethod")
        tmp_val = delete(tmp_val, "discovery.sendtargets.auth.username")
        tmp_val = delete(tmp_val, "discovery.sendtargets.auth.password")
      end
      Ops.set(tmp_conf, "value", tmp_val)
      SCR.Write(path(".etc.iscsid.all"), tmp_conf)
      SCR.Write(path(".etc.iscsid"), nil)

      nil
    end

### - (`Object`) ScanDiscovered(data)

    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
    # File '../../src/modules/IscsiClientLib.rb', line 352

    def ScanDiscovered(data)
      data = deep_copy(data)
      ret = []
      target = ""
      portal = ""
      iface = ""
      Builtins.foreach(data) do |row|
        row = Builtins.substring(row, Builtins.findfirstnotof(row, "\t "), 999)
        if Builtins.search(row, "Target:") != nil
          target = Ops.get(Builtins.splitstring(row, " "), 1, "")
        elsif Builtins.search(row, "Portal:") != nil
          if Builtins.search(row, "Current Portal:") != nil
            portal = Ops.get(Builtins.splitstring(row, " "), 2, "")
          elsif Builtins.search(row, "Persistent Portal:") == nil
            portal = Ops.get(Builtins.splitstring(row, " "), 1, "")
          end
          pos = Builtins.search(portal, ",")
          portal = Builtins.substring(portal, 0, pos) if pos != nil
        elsif Builtins.search(row, "Iface Name:") != nil
          iface = Ops.get(Builtins.splitstring(row, " "), 2, "")
          iface = Ops.get(@iface_file, iface, iface)
          if Builtins.findfirstof(portal, "[]") == nil
            ret = Builtins.add(
              ret,
              Ops.add(
                Ops.add(Ops.add(Ops.add(portal, " "), target), " "),
                iface
              )
            )
          end
        end
      end
      Builtins.y2milestone("ScanDiscovered ret:%1", ret)
      deep_copy(ret)
    end

### - (`Object`) setConfig(new_config)

    189
    190
    191
    192
    193
    194
    # File '../../src/modules/IscsiClientLib.rb', line 189

    def setConfig(new_config)
      new_config = deep_copy(new_config)
      Ops.set(@config, "value", new_config)

      nil
    end

### - (`Object`) SetOffloadCard(new_card)

    84
    85
    86
    87
    88
    89
    90
    91
    92
    # File '../../src/modules/IscsiClientLib.rb', line 84

    def SetOffloadCard(new_card)
      Builtins.y2milestone("SetOffloadCard:%1 cur:%2", new_card, @offload_card)
      if new_card != @offload_card
        @offload_card = new_card
        CallConfigScript() if new_card != "default"
      end

      nil
    end

### - (`Object`) setOrAdd(old_list, key, value)

add or modify given map

    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    # File '../../src/modules/IscsiClientLib.rb', line 275

    def setOrAdd(old_list, key, value)
      old_list = deep_copy(old_list)
      new_list = []
      found = false
      Builtins.foreach(old_list) do |row|
        if Ops.get_string(row, "name", "") == key
          found = true
          Ops.set(row, "value", value)
        end
        new_list = Builtins.add(new_list, row)
      end
      if !found
        new_list = Builtins.add(
          new_list,
          createMap({ "KEY" => key, "VALUE" => value }, [])
        )
      end
      deep_copy(new_list)
    end

### - (`Object`) setServiceStatus

set startup status of iscsid

    882
    883
    884
    885
    886
    887
    888
    889
    890
    891
    892
    893
    894
    895
    # File '../../src/modules/IscsiClientLib.rb', line 882

    def setServiceStatus
      ret = true
      # if disabled and no connected targets - stop it
      # otherwise keep it running
      if !GetStartService()
        readSessions
        if Builtins.size(@sessions) == 0
          Builtins.y2milestone("No active sessions - stopping service")
          Service.Stop("iscsid")
        end
      end
      Builtins.y2milestone("Status service for iscsid: %1", ret)
      ret
    end

### - (`Object`) SetStartService(status)

set accessor for service status

    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    # File '../../src/modules/IscsiClientLib.rb', line 161

    def SetStartService(status)
      Builtins.y2milestone("Set status of iscsid to %1", status)
      if status == true
        Service.Enable("boot.iscsid-early")
        Service.Enable("iscsid")
      else
        Service.Disable("boot.iscsid-early")
        Service.Disable("iscsid")
      end

      nil
    end

### - (`Object`) setStartupStatus(status)

change startup status (manual/onboot) for target

    741
    742
    743
    744
    745
    746
    747
    748
    749
    750
    751
    752
    753
    754
    755
    756
    757
    758
    759
    760
    761
    762
    763
    764
    765
    766
    767
    768
    769
    770
    771
    772
    773
    774
    775
    776
    777
    778
    779
    780
    781
    782
    783
    784
    785
    786
    787
    788
    789
    790
    # File '../../src/modules/IscsiClientLib.rb', line 741

    def setStartupStatus(status)
      Builtins.y2milestone(
        "Set startup status for %1 to %2",
        @currentRecord,
        status
      )
      ret = true
      retcode = Convert.convert(
        SCR.Execute(
          path(".target.bash_output"),
          GetAdmCmd(
            Builtins.sformat(
              "-m node -I%3 -T %1 -p %2 --op=update --name=node.conn[0].startup --value=%4",
              Ops.get(@currentRecord, 1, ""),
              Ops.get(@currentRecord, 0, ""),
              Ops.get(@currentRecord, 2, "default"),
              status
            )
          )
        ),
        :from => "any",
        :to   => "map <string, any>"
      )
      if Ops.greater_than(
          Builtins.size(Ops.get_string(retcode, "stderr", "")),
          0
        )
        return false
      else
        retcode = Convert.convert(
          SCR.Execute(
            path(".target.bash_output"),
            GetAdmCmd(
              Builtins.sformat(
                "-m node -I %3 -T %1 -p %2 --op=update --name=node.startup --value=%4",
                Ops.get(@currentRecord, 1, ""),
                Ops.get(@currentRecord, 0, ""),
                Ops.get(@currentRecord, 2, "default"),
                status
              )
            )
          ),
          :from => "any",
          :to   => "map <string, any>"
        )
      end

      Builtins.y2internal("retcode %1", retcode)
      ret
    end

### - (`Object`) setValue(name, value)

update authentication value

    679
    680
    681
    682
    683
    684
    685
    686
    687
    688
    689
    690
    691
    692
    693
    694
    695
    696
    697
    698
    699
    700
    701
    702
    703
    704
    705
    706
    # File '../../src/modules/IscsiClientLib.rb', line 679

    def setValue(name, value)
      Builtins.y2milestone("set %1  for record %2", name, @currentRecord)
      command = GetAdmCmd(
        Builtins.sformat(
          "-m node -I %3 -T %1 -p %2 --op=update --name=%4 --value=%5",
          Ops.get(@currentRecord, 1, ""),
          Ops.get(@currentRecord, 0, ""),
          Ops.get(@currentRecord, 2, "default"),
          name,
          value
        )
      )
      ret = true
      retcode = Convert.convert(
        SCR.Execute(path(".target.bash_output"), command),
        :from => "any",
        :to   => "map <string, any>"
      )
      if Ops.greater_than(
          Builtins.size(Ops.get_string(retcode, "stderr", "")),
          0
        )
        Builtins.y2error("%1", Ops.get_string(retcode, "stderr", ""))
        ret = false
      end
      Builtins.y2milestone("return value %1", ret)
      ret
    end

### - (`Object`) startIScsid

    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    # File '../../src/modules/IscsiClientLib.rb', line 405

    def startIScsid
      SCR.Execute(path(".target.bash"), "pgrep iscsid || iscsid")
      Builtins.foreach([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) do |i|
        Builtins.sleep(1 * 1000)
        cmd = Convert.convert(
          SCR.Execute(path(".target.bash_output"), GetAdmCmd("-m session")),
          :from => "any",
          :to   => "map <string, any>"
        )
        Builtins.y2internal(
          "iteration %1, retcode %2",
          i,
          Ops.get_integer(cmd, "exit", -1)
        )
        if Ops.get_integer(cmd, "exit", -1) == 0
          Builtins.y2internal("Good response from daemon, exit.")
          raise Break
        end
      end

      nil
    end

### - (`Object`) useISNS

do we use iSNS for targets?

    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    # File '../../src/modules/IscsiClientLib.rb', line 197

    def useISNS
      use = false
      Builtins.foreach(getConfig) do |row|
        if Ops.get_string(row, "name", "") == "isns.address" ||
            Ops.get_string(row, "name", "") == "isns.port"
          use = true
        end
      end
      use
    end

### - (`Object`) writeInitiatorName(new_value)

write InitiatorName, create backup from previous if needed

    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
    # File '../../src/modules/IscsiClientLib.rb', line 447

    def writeInitiatorName(new_value)
      ret = true
      file = "/etc/iscsi/initiatorname.iscsi"
      dir = "/etc/iscsi"
      if Convert.to_map(SCR.Read(path(".target.stat"), dir)) == {}
        SCR.Execute(path(".target.mkdir"), dir)
        Builtins.y2milestone(
          "writeInitiatorName dir:%1",
          SCR.Read(path(".target.stat"), dir)
        )
      end
      if Ops.greater_than(
          Ops.get_integer(
            Convert.convert(
              SCR.Read(path(".target.lstat"), file),
              :from => "any",
              :to   => "map <string, any>"
            ),
            "size",
            0
          ),
          0
        )
        Builtins.y2milestone("%1 file exists, create backup", file)
        SCR.Execute(
          path(".target.bash"),
          Builtins.sformat("mv %1 /etc/iscsi/initiatorname.yastbackup", file)
        )
      end
      ret = SCR.Write(
        path(".target.string"),
        [file, 384],
        Builtins.sformat("InitiatorName=%1\n", new_value)
      )
      if ret
        @initiatorname = new_value
        Builtins.y2milestone("Initiatorname %1 written", @initiatorname)
      end
      # reload service when initiatorname is changed to re-read new value (bnc#482429)
      Service.Reload("iscsid")
      ret
    end