Module: Yast::IscsiClientWidgetsInclude

Defined in:
../../src/include/iscsi-client/widgets.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) checkAuthEntry

validation for authentication dialog entry



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
# File '../../src/include/iscsi-client/widgets.rb', line 108

def checkAuthEntry
  Builtins.y2milestone("Check entries for authentication")
  ret = true
  auth_none = Convert.to_boolean(UI.QueryWidget(Id(:auth_none), :Value))
  auth_in = Convert.to_boolean(UI.QueryWidget(Id(:auth_in), :Value))
  auth_out = Convert.to_boolean(UI.QueryWidget(Id(:auth_out), :Value))
  user_in = Builtins.tostring(UI.QueryWidget(Id(:user_in), :Value))
  pass_in = Builtins.tostring(UI.QueryWidget(Id(:pass_in), :Value))
  user_out = Builtins.tostring(UI.QueryWidget(Id(:user_out), :Value))
  pass_out = Builtins.tostring(UI.QueryWidget(Id(:pass_out), :Value))
  if auth_none
    return true
  else
    if auth_in
      if Builtins.size(user_in) == 0
        Popup.Error(_("Insert the username."))
        UI.SetFocus(Id(:user_in))
        return false
      end
      if Builtins.size(pass_in) == 0
        Popup.Error(_("Insert the password."))
        UI.SetFocus(Id(:pass_in))
        return false
      end
    end
    if auth_out
      if Builtins.size(user_out) == 0
        Popup.Error(_("Insert the username."))
        UI.SetFocus(Id(:user_out))
        return false
      end
      if Builtins.size(pass_out) == 0
        Popup.Error(_("Insert the password."))
        UI.SetFocus(Id(:pass_out))
        return false
      end
    end
  end
  ret
end

- (Object) handleConnectedTable(key, event)

handle for table of connected sessions



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
# File '../../src/include/iscsi-client/widgets.rb', line 199

def handleConnectedTable(key, event)
  event = deep_copy(event)
  if Ops.get_string(event, "EventReason", "") == "Activated"
    record = []
    case Ops.get_symbol(event, "ID")
      when :add
        # add a new target, discovery
        # goto DiscAuthDialog("client")) ()
        Builtins.y2milestone("Goto dicovered authentication dialog")
        return :add
      when :del
        # delete (logout from) connected target
        record = setRecord
        if Ops.greater_than(Builtins.size(record), 0)
          if Popup.ContinueCancel(
              _("Really log out from the selected target?")
            )
            if !IscsiClientLib.deleteRecord
              Popup.Error(
                _(
                  "Error occurred while logging out from the selected target."
                )
              )
            else
              Builtins.y2milestone("Delete record %1", record)
              initConnectedTable("")
            end
          end
        else
          Popup.Error(_("No record found."))
        end
      when :edit
        record = setRecord
        return :edit
      when :toggle
        # change manual/onboot status of connected target
        # don't use automatic anymore (replaced by onboot) (bnc#449108)
        record = setRecord
        if Ops.greater_than(Builtins.size(record), 0)
          Builtins.y2milestone("toggle record %1", record)
          startup = IscsiClientLib.getStartupStatus
          if Ops.greater_than(Builtins.size(startup), 0)
            # toggle all 3 possible values (bnc#457252)
            options = ["manual", "onboot", "automatic"]
            pos = 0
            Builtins.foreach(options) do |option|
              if startup == option
                startup = Ops.get(
                  options,
                  Ops.greater_than(Builtins.size(options), Ops.add(pos, 1)) ?
                    Ops.add(pos, 1) :
                    0,
                  ""
                )
                Builtins.y2milestone(
                  "Changing state from %1 to %2",
                  option,
                  startup
                )
                IscsiClientLib.setStartupStatus(startup)
                raise Break
              end
              pos = Ops.add(pos, 1)
            end
            initConnectedTable("")
          end
        else
          Popup.Error(_("No record found."))
        end
    end
  end
  # if nothing selected - disable some buttons, otherwise enable them
  if setRecord == []
    UI.ChangeWidget(Id(:del), :Enabled, false)
    UI.ChangeWidget(Id(:edit), :Enabled, false)
  else
    UI.ChangeWidget(Id(:del), :Enabled, true)
    UI.ChangeWidget(Id(:edit), :Enabled, true)
  end
  nil
end

- (Object) handleDiscAuth(key, event)

handle for enable/disable widgets in authentication dialog



555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
# File '../../src/include/iscsi-client/widgets.rb', line 555

def handleDiscAuth(key, event)
  event = deep_copy(event)
  if Ops.get_string(event, "EventReason", "") == "ValueChanged"
    status = false
    case Ops.get_symbol(event, "ID")
      when :auth_none
        status = Convert.to_boolean(UI.QueryWidget(Id(:auth_none), :Value))
      when :auth_in
        status = Convert.to_boolean(UI.QueryWidget(Id(:auth_in), :Value))
      when :auth_out
        status = Convert.to_boolean(UI.QueryWidget(Id(:auth_out), :Value))
    end
  end
  nil
end

- (Object) handleDiscoveredTable(key, event)

handling widget with discovered targets



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
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
# File '../../src/include/iscsi-client/widgets.rb', line 748

def handleDiscoveredTable(key, event)
  event = deep_copy(event)
  params = []
  selected = UI.QueryWidget(:discovered, :CurrentItem)
  if selected != nil
    params = Builtins.splitstring(
      Ops.get(IscsiClientLib.discovered, Builtins.tointeger(selected), ""),
      " "
    )
  else
    params = []
  end
  IscsiClientLib.currentRecord = [
    Ops.get(Builtins.splitstring(Ops.get(params, 0, ""), ","), 0, ""),
    Ops.get(params, 1, ""),
    Ops.get(params, 2, "default")
  ]
  #    params = curr_rec;
  if Ops.get_string(event, "EventReason", "") == "Activated"
    # connect new target
    if Ops.get(event, "ID") == :connect
      # check if not already connected
      if IscsiClientLib.connected(false) == true
        if !Popup.AnyQuestion(
            Label.WarningMsg,
            _(
              "The target with this TargetName is already connected. Make sure that multipathing is enabled to prevent data corruption."
            ),
            _("Continue"),
            _("Cancel"),
            :focus_yes
          )
          return nil
        end
      end

      # goto ConnAuthDialog("discovered") (initDiscAuth)
      return :conn
    end
    # discovery target ConnAuthDialog("client") (initDiscAuth)
    return :disc if Ops.get(event, "ID") == :discovery
    # delete connected item
    if Ops.get(event, "ID") == :delete
      if params == [] || !IscsiClientLib.connected(true)
        cmd = IscsiClientLib.GetAdmCmd(
          Builtins.sformat(
            "-m node -T %1 -p %2 -I %3 --op=delete",
            Ops.get(params, 1, ""),
            Ops.get(params, 0, ""),
            Ops.get(params, 2, "")
          )
        )
        Builtins.y2milestone(
          "%1",
          SCR.Execute(path(".target.bash_output"), cmd, {})
        )
        IscsiClientLib.readSessions
        initDiscoveredTable("")
        if selected != nil
          params = Builtins.splitstring(
            Ops.get(
              IscsiClientLib.discovered,
              Builtins.tointeger(selected),
              ""
            ),
            " "
          )
        else
          params = []
        end
      end
    end
  end
  setDiscoveredButtons
  nil
end

- (Object) handleOffload(key, event)



468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
# File '../../src/include/iscsi-client/widgets.rb', line 468

def handleOffload(key, event)
  event = deep_copy(event)
  if event["EventReason"] || "" == "ValueChanged" &&
      event["ID"] || :none == :offload_card
    if Convert.to_string(UI.QueryWidget(:offload_card, :Value)) !=
        IscsiClientLib.GetOffloadCard
      IscsiClientLib.SetOffloadCard(
        Convert.to_string(UI.QueryWidget(:offload_card, :Value))
      )
      Builtins.y2milestone(
        "handleOffload OffloadCard %1",
        IscsiClientLib.GetOffloadCard
      )
    end
  end
  nil
end

- (Object) handleTargetTable(key, event)

handle dialog for all targets from portal (connected/disconnected) - only connect button ;)



852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
# File '../../src/include/iscsi-client/widgets.rb', line 852

def handleTargetTable(key, event)
  event = deep_copy(event)
  #enable/disable connect button according target is or not already connected
  items = Convert.convert(
    UI.QueryWidget(:targets, :Items),
    :from => "any",
    :to   => "list <term>"
  )
  if Ops.get_string(
      Ops.get(
        items,
        Convert.to_integer(UI.QueryWidget(:targets, :CurrentItem))
      ),
      3,
      ""
    ) ==
      _("True")
    UI.ChangeWidget(:connect, :Enabled, false)
  else
    UI.ChangeWidget(:connect, :Enabled, true)
  end


  if Ops.get_string(event, "EventReason", "") == "Activated"
    if Ops.get(event, "ID") == :connect
      # check if is not already connected
      IscsiClientLib.currentRecord = Builtins.splitstring(
        Ops.get(
          IscsiClientLib.targets,
          Convert.to_integer(UI.QueryWidget(:targets, :CurrentItem)),
          ""
        ),
        " "
      )
      if IscsiClientLib.connected(true) == true
        Popup.Error(_("The target is already connected."))
      else
        # check if not already connected
        if IscsiClientLib.connected(false) == true
          if !Popup.AnyQuestion(
              Label.WarningMsg,
              _(
                "The target with this TargetName is already connected. Make sure that multipathing is enabled to prevent data corruption."
              ),
              _("Continue"),
              _("Cancel"),
              :focus_yes
            )
            return nil
          end
        end

        # goto ConnAuthDialog("discovered") (initDiscAuth())
        return :conn_auth
      end
    end
  end
  nil
end

- (Object) initConnAuth(key)



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
# File '../../src/include/iscsi-client/widgets.rb', line 519

def initConnAuth(key)
  # setAuthIn(false);
  # setAuthOut(false);
  auth = IscsiClientLib.getNode
  if Ops.greater_than(Builtins.size(auth), 0)
    UI.ChangeWidget(
      Id(:user_in),
      :Value,
      Ops.get_string(auth, "username_in", "")
    )
    UI.ChangeWidget(
      Id(:pass_in),
      :Value,
      Ops.get_string(auth, "password_in", "")
    )
    #   if ((size(auth["username_in"]:"")>0)&&(size(auth["password_in"]:"")>0)) setAuthOut(true);
    UI.ChangeWidget(
      Id(:user_out),
      :Value,
      Ops.get_string(auth, "username", "")
    )
    UI.ChangeWidget(
      Id(:pass_out),
      :Value,
      Ops.get_string(auth, "password", "")
    ) 
    #   if ((size(auth["username"]:"")>0)&&(size(auth["password"]:"")>0)) setAuthOut(true);
  end
  startup = IscsiClientLib.getStartupStatus
  if Ops.greater_than(Builtins.size(startup), 0)
    UI.ChangeWidget(Id("startup"), :Value, startup)
  end

  nil
end

- (Object) initConnectedTable(key)

init table of connected sessions



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
# File '../../src/include/iscsi-client/widgets.rb', line 150

def initConnectedTable(key)
  if IscsiClientLib.readSessions == false
    Popup.Error(_("Error While Connecting iscsid"))
  end
  row_current = Convert.to_integer(UI.QueryWidget(:connected, :CurrentItem))
  items = []
  row = 0
  Builtins.foreach(IscsiClientLib.sessions) do |s|
    IscsiClientLib.currentRecord = Builtins.splitstring(s, " ")
    items = Builtins.add(
      items,
      Item(
        Id(row),
        Ops.get(IscsiClientLib.currentRecord, 2, ""),
        Ops.get(IscsiClientLib.currentRecord, 0, ""),
        Ops.get(IscsiClientLib.currentRecord, 1, ""),
        IscsiClientLib.getStartupStatus
      )
    )
    row = Ops.add(row, 1)
  end
  UI.ChangeWidget(Id(:connected), :Items, items)
  UI.ChangeWidget(:connected, :CurrentItem, row_current)
  UI.SetFocus(Id(:connected))

  nil
end

- (Object) initDiscAuth(key)

disable both incoming and outgoing



515
516
517
# File '../../src/include/iscsi-client/widgets.rb', line 515

def initDiscAuth(key)
  nil
end

- (Object) initDiscoveredTable(key)

initialize widget with discovered targets



722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
# File '../../src/include/iscsi-client/widgets.rb', line 722

def initDiscoveredTable(key)
  items = []
  row = 0
  Builtins.foreach(IscsiClientLib.getDiscovered) do |s|
    IscsiClientLib.currentRecord = Builtins.splitstring(s, " ")
    #        string record = deletechars(row_in_string[0]:"", "[]");
    items = Builtins.add(
      items,
      Item(
        Id(row),
        Ops.get(IscsiClientLib.currentRecord, 2, ""),
        Ops.get(IscsiClientLib.currentRecord, 0, ""),
        Ops.get(IscsiClientLib.currentRecord, 1, ""),
        IscsiClientLib.connected(true) ? _("True") : _("False")
      )
    )
    row = Ops.add(row, 1)
  end
  UI.ChangeWidget(Id(:discovered), :Items, items)
  UI.SetFocus(Id(:discovered))
  setDiscoveredButtons

  nil
end

- (Object) initialize_iscsi_client_widgets(include_target)



34
35
36
37
38
39
40
41
# File '../../src/include/iscsi-client/widgets.rb', line 34

def initialize_iscsi_client_widgets(include_target)
  textdomain "iscsi-client"
  Yast.import "IP"

  @stat = false
  @curr_rec = []
  @bg_finish = false
end

- (Object) initiBFT(key)

***************** iBFT table **************************



487
488
489
490
491
492
493
494
495
# File '../../src/include/iscsi-client/widgets.rb', line 487

def initiBFT(key)
  items = []
  Builtins.foreach(IscsiClientLib.hidePassword(IscsiClientLib.getiBFT)) do |key2, value|
    items = Builtins.add(items, Item(Id(Builtins.size(items)), key2, value))
  end
  UI.ChangeWidget(:bios, :Items, items)

  nil
end

- (Object) initInitName(key)



379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
# File '../../src/include/iscsi-client/widgets.rb', line 379

def initInitName(key)
  Builtins.y2milestone("initiatorname %1", IscsiClientLib.initiatorname)
  UI.ChangeWidget(:initiator_name, :Value, IscsiClientLib.initiatorname)
  UI.ChangeWidget(:offload_card, :Items, IscsiClientLib.GetOffloadItems)
  UI.ChangeWidget(:offload_card, :Value, IscsiClientLib.GetOffloadCard)
  Builtins.y2milestone("OffloadCard %1", IscsiClientLib.GetOffloadCard)
  if Ops.greater_than(
      Builtins.size(
        Ops.get_string(IscsiClientLib.getiBFT, "iSCSI_INITIATOR_NAME", "")
      ),
      0
    )
    UI.ChangeWidget(:initiator_name, :Enabled, false)
    UI.ChangeWidget(:write, :Enabled, false)
  end

  nil
end

- (Object) initISNS(key)



281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
# File '../../src/include/iscsi-client/widgets.rb', line 281

def initISNS(key)
  Builtins.foreach(IscsiClientLib.getConfig) do |row|
    if Ops.get_string(row, "name", "") == "isns.address"
      UI.ChangeWidget(
        :isns_address,
        :Value,
        Ops.get_string(row, "value", "")
      )
    end
    if Ops.get_string(row, "name", "") == "isns.port"
      UI.ChangeWidget(:isns_port, :Value, Ops.get_string(row, "value", ""))
    end
  end
  UI.ChangeWidget(:isns_port, :ValidChars, "0123456789")

  nil
end

- (Object) initServerLocation(key)

*******************Server Location ***********************



577
578
579
580
581
582
583
584
585
586
# File '../../src/include/iscsi-client/widgets.rb', line 577

def initServerLocation(key)
  isns_info = IscsiClientLib.useISNS()
  Builtins.y2milestone("is iSNS %1", isns_info["use"])
  if isns_info["use"]
    UI.ChangeWidget(:hostname, :Enabled, false)
    UI.ChangeWidget(:port, :Enabled, false)
  end

  nil
end

- (Object) initTargetTable(key)

initialize dialog for all targets from portal (connected/disconnected)



828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
# File '../../src/include/iscsi-client/widgets.rb', line 828

def initTargetTable(key)
  items = []
  row = 0
  Builtins.foreach(IscsiClientLib.targets) do |s|
    IscsiClientLib.currentRecord = Builtins.splitstring(s, " ")
    items = Builtins.add(
      items,
      Item(
        Id(row),
        Ops.get(IscsiClientLib.currentRecord, 2, ""),
        Ops.get(IscsiClientLib.currentRecord, 0, ""),
        Ops.get(IscsiClientLib.currentRecord, 1, ""),
        IscsiClientLib.connected(true) ? _("True") : _("False")
      )
    )
    row = Ops.add(row, 1)
  end
  UI.ChangeWidget(Id(:targets), :Items, items)
  UI.SetFocus(Id(:targets))

  nil
end

- (Object) runInBg(command)

string initiatorname=“”; function for run command in background



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
# File '../../src/include/iscsi-client/widgets.rb', line 45

def runInBg(command)
  @bg_finish = false
  Builtins.y2milestone("Start command %1 in background", command)
  stdout = []
  return_code = nil
  started = Convert.to_boolean(
    SCR.Execute(path(".background.run_output_err"), command)
  )
  if !started
    Builtins.y2error("Cannot run command")
    @stat = false
    return []
  end
  time_spent = 0
  cont_loop = true
  script_time_out = 10000
  sleep_step = 20
  while cont_loop &&
      Convert.to_boolean(SCR.Read(path(".background.output_open")))
    if Ops.greater_or_equal(time_spent, script_time_out)
      Popup.Error(_("Command timed out"))
      cont_loop = false
    end
    time_spent = Ops.add(time_spent, sleep_step)
    Builtins.sleep(sleep_step)
  end
  Builtins.y2milestone("Time spent: %1 msec", time_spent)
  stdout = Convert.convert(
    SCR.Read(path(".background.newout")),
    :from => "any",
    :to   => "list <string>"
  )
  Builtins.y2milestone("Output: %1", stdout)
  if cont_loop
    return_code = Convert.to_integer(SCR.Read(path(".background.status")))
    Builtins.y2milestone("Return: %1", return_code)
    if return_code != 0
      @stat = false
      error = Ops.get(
                      Convert.convert(
                                      SCR.Read(path(".background.newerr")),
                                      :from => "any",
                                      :to   => "list <string>"
                                      ),
                      0,
                      ""
                      )
      Builtins.y2error("Error: %1", error)
      Popup.Error(error)
    else
      @stat = true
    end
  else
    # killing the process if it still runs
    if Convert.to_boolean(SCR.Read(path(".background.output_open")))
      SCR.Execute(path(".background.kill"), "")
    end
  end
  @bg_finish = true
  deep_copy(stdout)
end

- (Object) setDiscoveredButtons

enable [ connect, delete ] buttons only for not connected items



694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
# File '../../src/include/iscsi-client/widgets.rb', line 694

def setDiscoveredButtons
  params = []
  selected = UI.QueryWidget(:discovered, :CurrentItem)
  if selected != nil
    params = Builtins.splitstring(
      Ops.get(IscsiClientLib.discovered, Builtins.tointeger(selected), ""),
      " "
    )
  else
    params = []
  end
  IscsiClientLib.currentRecord = [
    Ops.get(Builtins.splitstring(Ops.get(params, 0, ""), ","), 0, ""),
    Ops.get(params, 1, ""),
    Ops.get(params, 2, "")
  ]
  if params == [] || IscsiClientLib.connected(true)
    UI.ChangeWidget(Id(:connect), :Enabled, false)
    UI.ChangeWidget(Id(:delete), :Enabled, false)
  else
    UI.ChangeWidget(Id(:connect), :Enabled, true)
    UI.ChangeWidget(Id(:delete), :Enabled, true)
  end

  nil
end

- (Object) setRecord

get record identificator from selected row



179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File '../../src/include/iscsi-client/widgets.rb', line 179

def setRecord
  IscsiClientLib.currentRecord = []
  sel_item = UI.QueryWidget(Id(:connected), :CurrentItem)
  if sel_item != nil
    current = Builtins.tointeger(sel_item)
    IscsiClientLib.currentRecord = Builtins.splitstring(
      Ops.get(IscsiClientLib.sessions, current, ""),
      " "
    ) 
    #	 record = deletechars(record, "[]");
  elsif Ops.greater_than(Builtins.size(IscsiClientLib.sessions), 0)
    IscsiClientLib.currentRecord = Builtins.splitstring(
      Ops.get(IscsiClientLib.sessions, 0, ""),
      " "
    )
  end
  deep_copy(IscsiClientLib.currentRecord)
end

- (Object) storeInitName(key, event)



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
# File '../../src/include/iscsi-client/widgets.rb', line 440

def storeInitName(key, event)
  event = deep_copy(event)
  if Convert.to_string(UI.QueryWidget(:initiator_name, :Value)) !=
      IscsiClientLib.initiatorname
    # write initiatorname
    IscsiClientLib.writeInitiatorName(
      Convert.to_string(UI.QueryWidget(:initiator_name, :Value))
    )
    if Stage.initial
      IscsiClientLib.restart_iscsid_initial
    else
      Service.Restart("iscsid")
    end
    Builtins.y2milestone(
      "write initiatorname %1",
      IscsiClientLib.initiatorname
    )
  end
  if Convert.to_string(UI.QueryWidget(:offload_card, :Value)) !=
      IscsiClientLib.GetOffloadCard
    IscsiClientLib.SetOffloadCard(
      Convert.to_string(UI.QueryWidget(:offload_card, :Value))
    )
    Builtins.y2milestone("OffloadCard %1", IscsiClientLib.GetOffloadCard)
  end
  nil
end

- (Object) storeISNS(key, event)



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
# File '../../src/include/iscsi-client/widgets.rb', line 318

def storeISNS(key, event)
  event = deep_copy(event)
  address = Convert.to_string(UI.QueryWidget(:isns_address, :Value))
  port = Convert.to_string(UI.QueryWidget(:isns_port, :Value))
  found_addr = false
  found_port = false
  tmp_config = []

  Builtins.foreach(IscsiClientLib.getConfig) do |row|
    if Ops.get_string(row, "name", "") == "isns.address"
      Ops.set(row, "value", address)
      found_addr = true
    end
    if Ops.get_string(row, "name", "") == "isns.port"
      Ops.set(row, "value", port)
      found_port = true
    end
    if (Ops.get_string(row, "name", "") == "isns.address" ||
        Ops.get_string(row, "name", "") == "isns.port") &&
        Ops.greater_than(Builtins.size(address), 0) &&
          Ops.greater_than(Builtins.size(port), 0) ||
        Ops.get_string(row, "name", "") != "isns.address" &&
          Ops.get_string(row, "name", "") != "isns.port"
      tmp_config = Builtins.add(tmp_config, row)
    end
  end
  if Ops.greater_than(Builtins.size(address), 0) &&
      Ops.greater_than(Builtins.size(port), 0)
    if !found_addr
      tmp_config = Builtins.add(
        tmp_config,
        {
          "name"    => "isns.address",
          "value"   => address,
          "kind"    => "value",
          "type"    => 1,
          "comment" => ""
        }
      )
    end
    if !found_port
      tmp_config = Builtins.add(
        tmp_config,
        {
          "name"    => "isns.port",
          "value"   => port,
          "kind"    => "value",
          "type"    => 1,
          "comment" => ""
        }
      )
    end
  end

  IscsiClientLib.setConfig(tmp_config)
  IscsiClientLib.oldConfig
  nil
end

- (Object) validateConnAuth(key, event)

login to target with authentication



915
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
# File '../../src/include/iscsi-client/widgets.rb', line 915

def validateConnAuth(key, event)
  event = deep_copy(event)
  auth_none = Convert.to_boolean(UI.QueryWidget(Id(:auth_none), :Value))
  user_in = Builtins.tostring(UI.QueryWidget(Id(:user_in), :Value))
  pass_in = Builtins.tostring(UI.QueryWidget(Id(:pass_in), :Value))
  user_out = Builtins.tostring(UI.QueryWidget(Id(:user_out), :Value))
  pass_out = Builtins.tostring(UI.QueryWidget(Id(:pass_out), :Value))

  target = {
    "target"      => Ops.get(IscsiClientLib.currentRecord, 1, ""),
    "portal"      => Ops.get(IscsiClientLib.currentRecord, 0, ""),
    "iface"       => Ops.get(IscsiClientLib.currentRecord, 2, "default"),
    "authmethod"  => auth_none ? "None" : "CHAP",
    "username"    => user_out,
    "password"    => pass_out,
    "username_in" => user_in,
    "password_in" => pass_in
  }
  if IscsiClientLib.connected(true) ||
      IscsiClientLib.loginIntoTarget(target)
    #		IscsiClientLib::currentRecord = [target["portal"]:"", target["target"]:"", target["iface"]:"default"];
    IscsiClientLib.setStartupStatus(
      Convert.to_string(UI.QueryWidget(Id("startup"), :Value))
    )
    IscsiClientLib.readSessions
    return true
  else
    return false
  end
end

- (Object) validateDiscAuth(key, event)



571
572
573
574
# File '../../src/include/iscsi-client/widgets.rb', line 571

def validateDiscAuth(key, event)
  event = deep_copy(event)
  checkAuthEntry
end

- (Object) validateInitName(key, event)



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
# File '../../src/include/iscsi-client/widgets.rb', line 398

def validateInitName(key, event)
  event = deep_copy(event)
  #  Targets definitions start with "Target" and the target name.
  #  The target name must be a globally unique name, the iSCSI
  #  standard defines the "iSCSI Qualified Name" as follows:
  #
  #  iqn.yyyy-mm.reversed domain name[:identifier]
  #
  #  "yyyy-mm" is the date at which the domain is valid and the identifier
  #  is freely selectable. For further details please check the iSCSI spec.

  i_name = Convert.to_string(UI.QueryWidget(:initiator_name, :Value))
  # regexp for "yyyy-mm."
  reg1 = "[[:digit:]]{4}-[[:digit:]]{2}."
  # regexp for "cz.suse" or just "suse", "cz.su-se"
  reg2 = "[[:alnum:].:-]*"

  correct = Builtins.regexpmatch(
    i_name,
    Builtins.sformat("^iqn.%1%2$", reg1, reg2)
  ) ||
    Builtins.regexpmatch(i_name, Builtins.sformat("^eui.%1%2$", reg1, reg2))

  if !correct
    continue = Popup.ContinueCancel(
      _(
        "Incorrect InitiatorName.\n" +
          "The correct syntax is\n" +
          "iqn.yyyy-mm.reversed.domain.name[:identifier]\n" +
          "or eui.yyyy-mm.reversed.domain.name[:identifier]\n" +
          "\n" +
          "Example:\n" +
          "iqn.2007-04.cz.server:storage.disk.sdb\n"
      )
    )
    return continue
  else
    return true
  end
end

- (Object) validateISNS(key, event)



299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
# File '../../src/include/iscsi-client/widgets.rb', line 299

def validateISNS(key, event)
  event = deep_copy(event)
  address = Convert.to_string(UI.QueryWidget(:isns_address, :Value))
  port = Convert.to_string(UI.QueryWidget(:isns_port, :Value))
  return true if Builtins.size(address) == 0 && Builtins.size(port) == 0
  if !IP.Check(address)
    Popup.Error(_("No valid IP address"))
    UI.SetFocus(:isns_address)
    return false
  end
  if Builtins.size(port) == 0
    Popup.Error(_("Port field cannot be empty"))
    UI.SetFocus(:isns_port)
    return false
  end
  true
end

- (Object) validateServerLocation(key, event)

do discovery to selected portal



589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
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
636
637
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
677
678
679
680
681
682
683
684
685
686
687
688
# File '../../src/include/iscsi-client/widgets.rb', line 589

def validateServerLocation(key, event)
  event = deep_copy(event)
  ret = true
  ip = Builtins.tostring(UI.QueryWidget(:hostname, :Value))
  ip.strip!
  port = Builtins.tostring(UI.QueryWidget(:port, :Value))
  # validate IP address
  isns_info = IscsiClientLib.useISNS()
  if !isns_info["use"]
    if Ops.greater_than(Builtins.size(ip), 0)
      if !IP.Check(ip)
        # check for valid host name (take only first line of 'host'
        # output because with IPv6 there might be several lines)
        output = Convert.convert(
          SCR.Execute(
            path(".target.bash_output"),
            "LC_ALL=POSIX host #{ip}|head -1|tr -d '\n'"
          ),
          :from => "any",
          :to   => "map <string, any>"
        )
        out = Builtins.splitstring(
          Ops.get_string(output, "stdout", ""),
          " "
        )
        ip = Ops.get(out, Ops.subtract(Builtins.size(out), 1), "")
        Builtins.y2internal("%1", out)
        if Ops.get_integer(output, "exit", -1) == 0

        else
          Popup.Error(Ops.get_string(output, "stdout", ""))
          UI.SetFocus(:hostname)
          return false
        end
      elsif IP.Check6(ip)
        ip = "[#{ip}]" # brackets needed around IPv6
      end
    else
      Popup.Error(_("Insert the IP address."))
      UI.SetFocus(:ip)
      return false
    end
    # validate port number
    if Builtins.size(port) == 0
      Popup.Error(_("Insert the port."))
      UI.SetFocus(:port)
      return false
    end
  end
  # store old config
  IscsiClientLib.getConfig

  auth_none = Convert.to_boolean(UI.QueryWidget(Id(:auth_none), :Value))
  user_in = Builtins.tostring(UI.QueryWidget(Id(:user_in), :Value))
  pass_in = Builtins.tostring(UI.QueryWidget(Id(:pass_in), :Value))
  user_out = Builtins.tostring(UI.QueryWidget(Id(:user_out), :Value))
  pass_out = Builtins.tostring(UI.QueryWidget(Id(:pass_out), :Value))
  auth_in = !auth_none && Ops.greater_than(Builtins.size(user_in), 0) &&
    Ops.greater_than(Builtins.size(pass_in), 0)
  auth_out = !auth_none && Ops.greater_than(Builtins.size(user_out), 0) &&
    Ops.greater_than(Builtins.size(pass_out), 0)

  if auth_none
    user_in = ""
    pass_in = ""
    user_out = ""
    pass_out = ""
  end
  if !auth_in
    user_in = ""
    pass_in = ""
  end
  if !auth_out
    user_out = ""
    pass_out = ""
  end

  # write authentication data
  IscsiClientLib.saveConfig(user_in, pass_in, user_out, pass_out)
  #y2internal("auth: %1/%2, %3/%4", user_in, pass_in, user_out, pass_out);
  @bg_finish = false
  # ` with authentication
  command = IscsiClientLib.GetDiscoveryCmd(ip, port, false)
  trg_list = runInBg(command)
  while !@bg_finish

  end
  if Builtins.size(trg_list) == 0
    command = IscsiClientLib.GetDiscoveryCmd(ip, port, true)
    trg_list = runInBg(command)
    while !@bg_finish

    end
  end
  IscsiClientLib.targets = IscsiClientLib.ScanDiscovered(trg_list)
  # restore old config
  IscsiClientLib.oldConfig

  @stat
end