Class: Yast::IscsiServerClass

Inherits:
Module
  • Object
show all
Defined in:
../../src/modules/IscsiServer.rb

Instance Method Summary (collapse)

Instance Method Details

- (Boolean) Abort

Abort function

Returns:

  • (Boolean)

    return true if abort



76
77
78
79
# File '../../src/modules/IscsiServer.rb', line 76

def Abort
  return @AbortFunction.call == true if @AbortFunction != nil
  false
end

- (Object) authIn(config)



618
619
620
621
622
623
624
625
# File '../../src/modules/IscsiServer.rb', line 618

def authIn(config)
  config = deep_copy(config)
  ret = false
  Builtins.foreach(config) do |row|
    ret = true if Ops.get_string(row, "KEY", "") == "IncomingUser"
  end
  ret
end

- (Object) authOut(config)



627
628
629
630
631
632
633
634
# File '../../src/modules/IscsiServer.rb', line 627

def authOut(config)
  config = deep_copy(config)
  ret = false
  Builtins.foreach(config) do |row|
    ret = true if Ops.get_string(row, "KEY", "") == "OutgoingUser"
  end
  ret
end

- (Hash) AutoPackages

Return packages needed to be installed and removed during Autoinstallation to insure module has all needed software installed.

Returns:

  • (Hash)

    with 2 lists.



731
732
733
734
# File '../../src/modules/IscsiServer.rb', line 731

def AutoPackages
  # TODO FIXME: your code here...
  { "install" => [], "remove" => [] }
end

- (Hash) Export

Dump the iscsi-server settings to a single map (For use by autoinstallation.)

Returns:

  • (Hash)

    Dumped settings (later acceptable by Import ())



590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
# File '../../src/modules/IscsiServer.rb', line 590

def Export
  targets = []
  Builtins.foreach(IscsiServerFunctions.getTargets) do |k, v|
    targets = Builtins.add(targets, v)
  end

  result = {
    "version" => "1.0",
    "service" => @serviceStatus,
    "auth"    => Ops.get_list(IscsiServerFunctions.getConfig, "auth", []),
    "targets" => targets
  }
  @configured = true
  deep_copy(result)
end

- (Object) getLun(config)



636
637
638
639
640
641
642
643
644
645
# File '../../src/modules/IscsiServer.rb', line 636

def getLun(config)
  config = deep_copy(config)
  ret = ""
  Builtins.foreach(config) do |row|
    if Ops.get_string(row, "KEY", "") == "Lun"
      ret = Ops.get_string(row, "VALUE", "")
    end
  end
  ret
end

- (Object) getServiceStatus

check status of iscsitarget service if not enabled, start it manually



185
186
187
188
189
190
191
192
193
194
# File '../../src/modules/IscsiServer.rb', line 185

def getServiceStatus
  ret = true
  if Service.Status("iscsitarget") == 0
    @statusOnStart = true
    @serviceStatus = true
  end
  Builtins.y2milestone("Service status = %1", @statusOnStart)
  Service.Start("iscsitarget") if !@statusOnStart
  ret
end

- (Object) GetStartService

get/set service accessors for CWMService component



738
739
740
741
742
# File '../../src/modules/IscsiServer.rb', line 738

def GetStartService
  status = Service.Enabled("iscsitarget")
  Builtins.y2milestone("iscsitarget service status %1", status)
  status
end

- (Boolean) Import(settings)

Get all iscsi-server settings from the first parameter (For use by autoinstallation.)

Parameters:

  • settings (Hash)

    The YCP structure to be imported.

Returns:

  • (Boolean)

    True on success



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

def Import(settings)
  settings = deep_copy(settings)
  Builtins.foreach(
    Convert.convert(settings, :from => "map", :to => "map <string, any>")
  ) do |key, value|
    case key
      when "service"
        @serviceStatus = Convert.to_boolean(value)
      when "auth"
        @incom = []
        @outgoin = ""
        Builtins.foreach(
          Convert.convert(
            value,
            :from => "any",
            :to   => "list <map <string, any>>"
          )
        ) do |row|
          if Ops.get_string(row, "KEY", "") == "IncomingUser"
            @incom = Builtins.add(@incom, Ops.get_string(row, "VALUE", ""))
          else
            @outgoin = Ops.get_string(row, "VALUE", "")
          end
        end
        IscsiServerFunctions.setAuth(@incom, @outgoin)
      when "targets"
        @name = ""
        @lun = []
        @inc = []
        @out = ""
        Builtins.foreach(
          Convert.convert(
            value,
            :from => "any",
            :to   => "list <list <map <string, any>>>"
          )
        ) do |val|
          @name = ""
          @lun = []
          @inc = []
          @out = ""
          Builtins.foreach(val) do |row|
            case Ops.get_string(row, "KEY", "")
              when "Target"
                @name = Ops.get_string(row, "VALUE", "")
              when "Lun"
                @lun = Builtins.add(@lun, row)
              when "IncomingUser"
                @inc = Builtins.add(@inc, Ops.get_string(row, "VALUE", ""))
              when "OutgoingUser"
                @out = Ops.get_string(row, "VALUE", "")
            end
          end
          IscsiServerFunctions.addNewTarget(@name, @lun)
          IscsiServerFunctions.setTargetAuth(@name, @inc, @out)
        end
    end
  end

  @configured = true
  true
end

- (Object) installed_packages

test if required package (“iscsitarget”) is installed



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File '../../src/modules/IscsiServer.rb', line 153

def installed_packages
  if !PackageSystem.PackageInstalled("iscsitarget")
    Builtins.y2milestone("Not installed, will install")
    confirm = Popup.AnyQuestionRichText(
      "",
      _("Cannot continue without installing iscsitarget package."),
      40,
      10,
      Label.InstallButton,
      Label.CancelButton,
      :focus_yes
    )

    if confirm
      service = "tgtd"
      Service.Stop(service) if Service.Status(service) == 0
      Service.Disable(service)
      PackageSystem.DoInstall(["iscsitarget"])
      if PackageSystem.PackageInstalled("iscsitarget")
        return true
      else
        return false
      end
    end
    return false
  else
    return true
  end
end

- (Object) main



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

def main
  textdomain "iscsi-server"

  Yast.import "Progress"
  Yast.import "Report"
  Yast.import "Summary"
  Yast.import "Message"
  Yast.import "Service"
  Yast.import "Package"
  Yast.import "Popup"
  Yast.import "SuSEFirewall"
  Yast.import "Confirm"
  Yast.import "IscsiServerFunctions"
  Yast.import "Mode"
  Yast.import "NetworkService"
  Yast.import "PackageSystem"
  Yast.import "Label"

  @serviceStatus = false
  @statusOnStart = false

  # Data was modified?
  @modified = false
  @configured = false


  @proposal_valid = false

  # Write only, used during autoinstallation.
  # Don't run services and SuSEconfig, it's all done at one place.
  @write_only = false

  # Abort function
  # return boolean return true if abort
  @AbortFunction = fun_ref(method(:Modified), "boolean ()")
end

- (Object) Modified

Data was modified?

Returns:

  • true if modified



83
84
85
86
# File '../../src/modules/IscsiServer.rb', line 83

def Modified
  Builtins.y2debug("modified=%1", @modified)
  @modified
end

- (Object) noAuth(config)



606
607
608
609
610
611
612
613
614
615
616
# File '../../src/modules/IscsiServer.rb', line 606

def noAuth(config)
  config = deep_copy(config)
  ret = true
  Builtins.foreach(config) do |row|
    if Ops.get_string(row, "KEY", "") == "IncomingUser" ||
        Ops.get_string(row, "KEY", "") == "OutgoingUser"
      ret = false
    end
  end
  ret
end

- (Object) Overview

Create an overview table with all configured cards

Returns:

  • table items



722
723
724
725
# File '../../src/modules/IscsiServer.rb', line 722

def Overview
  # TODO FIXME: your code here...
  []
end

- (Object) Read

Read all iscsi-server settings

Returns:

  • true on success



378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
# File '../../src/modules/IscsiServer.rb', line 378

def Read
  # IscsiServer read dialog caption
  caption = _("Initializing iSCSI Target Configuration")

  # TODO FIXME Set the right number of stages
  steps = 4

  sl = 500
  Builtins.sleep(sl)

  # TODO FIXME Names of real stages
  # We do not set help text here, because it was set outside
  Progress.New(
    caption,
    " ",
    steps,
    [
      # Progress stage 1/3
      _("Read the database"),
      # Progress stage 2/3
      _("Read the previous settings"),
      # Progress stage 3/3
      _("Detect the devices")
    ],
    [
      # Progress step 1/3
      _("Reading the database..."),
      # Progress step 2/3
      _("Reading the previous settings..."),
      # Progress step 3/3
      _("Detecting the devices..."),
      # Progress finished
      _("Finished")
    ],
    ""
  )

  # check if user is root
  return false if !Confirm.MustBeRoot
  return false if !NetworkService.RunningNetworkPopup
  Progress.NextStage
  # check if required packages ("iscsitarget") are installed
  return false if !installed_packages
  Builtins.sleep(sl)

  return false if Abort()
  Progress.NextStep
  # get status of iscsitarget init script
  return false if !getServiceStatus
  Builtins.sleep(sl)

  return false if Abort()
  Progress.NextStage
  # read configuration (ietd.conf)
  if !readConfig
    Report.Error(Message.CannotReadCurrentSettings)
    return false
  end
  Builtins.sleep(sl)

  # detect devices
  Progress.set(false)
  SuSEFirewall.Read
  Progress.set(true)

  Progress.NextStage
  # Error message
  return false if false
  Builtins.sleep(sl)

  return false if Abort()
  # Progress finished
  Progress.NextStage
  Builtins.sleep(sl)

  return false if Abort()
  @modified = false
  @configured = true
  true
end

- (Object) readConfig

read configuration file ietd.conf



104
105
106
107
108
109
110
111
112
# File '../../src/modules/IscsiServer.rb', line 104

def readConfig
  read_values = Convert.convert(
    SCR.Read(path(".etc.ietd.all")),
    :from => "any",
    :to   => "map <string, any>"
  )
  IscsiServerFunctions.parseConfig(read_values)
  true
end

- (Object) reloadServer

157643 - reload server



213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
# File '../../src/modules/IscsiServer.rb', line 213

def reloadServer
  # ask user whether reload or restart server
  # #180205 - gettext problem - string wasn't marked to translate
  if Popup.YesNo(
      _(
        "If changes have been made, the iSCSI target is not able\n" +
          "to reload the current configuration. It can only restart.\n" +
          "When restarting, all sessions are aborted.\n" +
          "Restart the iscsitarget service?\n"
      )
    )
    Service.Restart("iscsitarget")
  else
    # get changes from perl module
    changes = IscsiServerFunctions.getChanges
    connected = IscsiServerFunctions.getConnected
    # plus add there all targets except with active sessions (it means delete and create as new each target)
    #          foreach(string key,any value, IscsiServerFunctions::getTargets(), {
    # 	 if ((!contains(connected, key))&&(!contains(changes["add"]:[], key))&&(!contains(changes["del"]:[], key))){
    # 	   changes["del"] = add (changes["del"]:[], key);
    # 	   changes["add"] = add (changes["add"]:[], key);
    #            y2milestone("modified key %1", key);
    # 	  }
    #          });
    # delete targets
    Builtins.foreach(Ops.get_list(changes, "del", [])) do |row|
      if !Builtins.contains(connected, row)
        Builtins.y2milestone("row to delete %1", row)
        target = Ops.get_string(
          Convert.convert(
            SCR.Execute(
              path(".target.bash_output"),
              # get TID number for target
              "cat /proc/net/iet/volume|grep $TARGET",
              { "TARGET" => row }
            ),
            :from => "any",
            :to   => "map <string, any>"
          ),
          "stdout",
          ""
        )
        to_delete = Ops.get(
          Builtins.splitstring(
            Ops.get(Builtins.splitstring(target, " "), 0, ""),
            ":"
          ),
          1,
          ""
        )
        Builtins.y2milestone("to delete %1", to_delete)
        # delete record with that TID
        SCR.Execute(
          path(".target.bash_output"),
          "ietadm --op delete --tid=$TID",
          { "TID" => to_delete }
        )
      else
        Builtins.y2error("Cannot remove target %1 - already connected", row)
      end
    end

    # add a new target
    Builtins.foreach(Ops.get_list(changes, "add", [])) do |row|
      Builtins.y2milestone("row to add %1", row)
      # create new target
      SCR.Execute(
        path(".target.bash_output"),
        "ietadm --op new --tid=0 --params Name=$NAME",
        { "NAME" => row }
      )
      target = Ops.get_string(
        Convert.convert(
          SCR.Execute(
            path(".target.bash_output"),
            "cat /proc/net/iet/volume|grep $TARGET",
            { "TARGET" => row }
          ),
          :from => "any",
          :to   => "map <string, any>"
        ),
        "stdout",
        ""
      )
      # get TID of that target
      to_add = Ops.get(
        Builtins.splitstring(
          Ops.get(Builtins.splitstring(target, " "), 0, ""),
          ":"
        ),
        1,
        ""
      )
      Builtins.y2milestone("to add %1", to_add)
      lun = []
      secret = []
      # add authentication to target
      Builtins.foreach(
        Ops.get_list(IscsiServerFunctions.getConfig, row, [])
      ) do |conf_row|
        case Ops.get_string(conf_row, "KEY", "")
          when "Lun"
            lun = Builtins.splitstring(
              Ops.get_string(conf_row, "VALUE", ""),
              " "
            )
          when "IncomingUser"
            secret = Builtins.splitstring(
              Ops.get_string(conf_row, "VALUE", ""),
              " "
            )
            Builtins.y2milestone(
              "params %1 %2 %3",
              to_add,
              Ops.get(secret, 0, ""),
              Ops.get(secret, 1, "")
            )
            SCR.Execute(
              path(".target.bash_output"),
              "ietadm --op new --tid=$TID --user --params=IncomingUser=$US,Password=$PASS",
              {
                "TID"  => to_add,
                "US"   => Ops.get(secret, 0, ""),
                "PASS" => Ops.get(secret, 1, "")
              }
            )
          when "OutgoingUser"
            secret = Builtins.splitstring(
              Ops.get_string(conf_row, "VALUE", ""),
              " "
            )
            SCR.Execute(
              path(".target.bash_output"),
              "ietadm --op new --tid=$TID --user --params=OutgoingUser=$US,Password=$PASS",
              {
                "TID"  => to_add,
                "US"   => Ops.get(secret, 0, ""),
                "PASS" => Ops.get(secret, 1, "")
              }
            )
        end
      end
      lun_num = Ops.get(lun, 0, "")
      lun_path = Ops.get(
        Builtins.splitstring(Ops.get(lun, 1, ""), ","),
        0,
        ""
      )
      # add LUN for target
      command = Builtins.sformat(
        "ietadm --op new --tid=%1 --lun=%2 --params %3",
        to_add,
        lun_num,
        lun_path
      )
      SCR.Execute(path(".target.bash_output"), command, {})
      Builtins.y2milestone("lun %1,%2", lun_num, lun_path)
    end
  end
  true
end

- (Object) setServiceStatus

set service status



197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File '../../src/modules/IscsiServer.rb', line 197

def setServiceStatus
  start = true
  start = @statusOnStart if !@serviceStatus

  if !start
    Builtins.y2milestone("Stop iscsitarget service")
    Service.Stop("iscsitarget")
  else
    Builtins.y2milestone("Start iscsitarget service")
    @serviceStatus = true
    Service.Start("iscsitarget")
  end
  true
end

- (Object) SetStartService(status)



744
745
746
747
748
749
750
751
752
753
754
# File '../../src/modules/IscsiServer.rb', line 744

def SetStartService(status)
  Builtins.y2milestone("Set service status %1", status)
  @serviceStatus = status
  if status == true
    Service.Enable("iscsitarget")
  else
    Service.Disable("iscsitarget")
  end

  nil
end

- (Object) Summary

Create a textual summary and a list of unconfigured cards

Returns:

  • summary of the current configuration



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
689
690
691
692
693
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
# File '../../src/modules/IscsiServer.rb', line 649

def Summary
  summary = _("Configuration summary...")
  if @configured
    summary = Summary.AddHeader("", _("Global"))
    if @serviceStatus
      summary = Summary.AddLine(summary, _("When Booting"))
    else
      summary = Summary.AddLine(summary, _("Manually"))
    end
    if noAuth(Ops.get_list(IscsiServerFunctions.getConfig, "auth", []))
      summary = Summary.AddLine(summary, _("No Authentication"))
    else
      if authIn(Ops.get_list(IscsiServerFunctions.getConfig, "auth", []))
        summary = Summary.AddLine(summary, _("Incoming Authentication"))
      end
      if authOut(Ops.get_list(IscsiServerFunctions.getConfig, "auth", []))
        summary = Summary.AddLine(summary, _("Outgoing Authentication"))
      end
    end
    summary = Summary.AddHeader(summary, _("Targets"))
    summary = Summary.OpenList(summary)
    Builtins.foreach(IscsiServerFunctions.getTargets) do |key, value|
      summary = Summary.AddListItem(summary, key)
      summary = Summary.AddLine(
        summary,
        getLun(
          Convert.convert(
            value,
            :from => "any",
            :to   => "list <map <string, any>>"
          )
        )
      )
      if noAuth(
          Convert.convert(
            value,
            :from => "any",
            :to   => "list <map <string, any>>"
          )
        )
        summary = Summary.AddLine(summary, _("No Authentication"))
      else
        if authIn(
            Convert.convert(
              value,
              :from => "any",
              :to   => "list <map <string, any>>"
            )
          )
          summary = Summary.AddLine(summary, _("Incoming Authentication"))
        end
        if authOut(
            Convert.convert(
              value,
              :from => "any",
              :to   => "list <map <string, any>>"
            )
          )
          summary = Summary.AddLine(summary, _("Outgoing Authentication"))
        end
      end
    end
    summary = Summary.CloseList(summary)
  else
    summary = Summary.NotConfigured
  end
  # TODO FIXME: your code here...
  # Configuration summary text for autoyast
  [summary, []]
end

- (Object) Write

Write all iscsi-server settings

Returns:

  • true on success



461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
# File '../../src/modules/IscsiServer.rb', line 461

def Write
  # IscsiServer write dialog caption
  caption = _("Saving iSCSI Target Configuration")

  # TODO FIXME And set the right number of stages
  steps = 2

  sl = 500
  Builtins.sleep(sl)

  # TODO FIXME Names of real stages
  # We do not set help text here, because it was set outside
  Progress.New(
    caption,
    " ",
    steps,
    [
      # Progress stage 1/2
      _("Write the settings"),
      # Progress stage 2/2
      _("Run SuSEconfig")
    ],
    [
      # Progress step 1/2
      _("Writing the settings..."),
      # Progress step 2/2
      _("Running SuSEconfig..."),
      # Progress finished
      _("Finished")
    ],
    ""
  )


  Progress.set(false)
  SuSEFirewall.Write
  Progress.set(true)

  Progress.NextStage
  # write configuration (ietd.conf)
  Report.Error(_("Cannot write settings.")) if !writeConfig
  Builtins.sleep(sl)


  return false if Abort()
  Progress.NextStage
  #  ask user whether reload or restart server and do it
  return false if !reloadServer if @serviceStatus || @statusOnStart
  Builtins.sleep(sl)

  return false if Abort()
  Progress.NextStage
  Builtins.sleep(sl)

  # set iscsitarget initscript status
  return false if !setServiceStatus
  true
end

- (Object) writeConfig

write configuration file ietd.conf



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/IscsiServer.rb', line 116

def writeConfig
  # prepare map, because perl->ycp lost information about data types (integers in this case)
  config_file = IscsiServerFunctions.writeConfig
  Ops.set(
    config_file,
    "type",
    Builtins.tointeger(Ops.get_string(config_file, "type", "1"))
  )
  Ops.set(
    config_file,
    "file",
    Builtins.tointeger(Ops.get_string(config_file, "file", "1"))
  )
  value = []
  Builtins.foreach(Ops.get_list(config_file, "value", [])) do |row|
    Ops.set(
      row,
      "type",
      Builtins.tointeger(Ops.get_string(row, "type", "1"))
    )
    Ops.set(
      row,
      "file",
      Builtins.tointeger(Ops.get_string(row, "file", "1"))
    )
    value = Builtins.add(value, row)
  end

  Ops.set(config_file, "value", value)
  Builtins.y2milestone("config_file to write %1", config_file)
  # write it
  SCR.Write(path(".etc.ietd.all"), config_file)
  SCR.Write(path(".etc.ietd"), nil)
  true
end