Class: Yast::IsnsServerClass

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

Instance Method Summary (collapse)

Instance Method Details

- (Boolean) Abort

Abort function

Returns:

  • (Boolean)

    return true if abort



53
54
55
56
# File '../../src/modules/IsnsServer.rb', line 53

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

- (Object) addDD(address, name)



416
417
418
419
420
421
422
423
424
425
# File '../../src/modules/IsnsServer.rb', line 416

def addDD(address, name)
  Builtins.y2milestone("addDD")
  command = Builtins.sformat(
    "isnsadm -a %1 -t -r dd -n '%2'",
    address,
    name
  )
  SCR.Execute(path(".target.bash_output"), command, {})
  true
end

- (Object) addDDMember(address, dd_id, iqn)



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

def addDDMember(address, dd_id, iqn)
  Builtins.y2milestone("addDDMember")
  command = Builtins.sformat(
    "isnsadm -a %1 -t -r ddmember -n %2 -m %3",
    address,
    dd_id,
    iqn
  )
  SCR.Execute(path(".target.bash_output"), command, {})
  true
end

- (Object) addDDS(address, name)



381
382
383
384
385
386
387
388
389
390
# File '../../src/modules/IsnsServer.rb', line 381

def addDDS(address, name)
  Builtins.y2milestone("addDDS")
  command = Builtins.sformat(
    "isnsadm -a %1 -t -r dds -n '%2'",
    address,
    name
  )
  SCR.Execute(path(".target.bash_output"), command, {})
  true
end

- (Object) addDDSMember(address, dds_id, dd_id)



404
405
406
407
408
409
410
411
412
413
414
# File '../../src/modules/IsnsServer.rb', line 404

def addDDSMember(address, dds_id, dd_id)
  Builtins.y2milestone("addDDSMember")
  command = Builtins.sformat(
    "isnsadm -a %1 -t -r ddsmember -n %2 -m %3",
    address,
    dds_id,
    dd_id
  )
  SCR.Execute(path(".target.bash_output"), command, {})
  true
end

- (Object) addISCSI(address, name, entityid)



369
370
371
372
373
374
375
376
377
378
379
# File '../../src/modules/IsnsServer.rb', line 369

def addISCSI(address, name, entityid)
  Builtins.y2milestone("addDDS")
  command = Builtins.sformat(
    "isnsadm -a %1 -t -r iscsi -n '%2' -m '%3'",
    address,
    name,
    entityid
  )
  SCR.Execute(path(".target.bash_output"), command, {})
  true
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.



630
631
632
633
# File '../../src/modules/IsnsServer.rb', line 630

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

- (Object) deleteDD(address, id)



473
474
475
476
477
478
479
# File '../../src/modules/IsnsServer.rb', line 473

def deleteDD(address, id)
  Builtins.y2milestone("deleteDDS")
  command = Builtins.sformat("isnsadm -a %1 -t -d dd -n '%2'", address, id)
  SCR.Execute(path(".target.bash_output"), command, {})

  true
end

- (Object) deleteDDMember(address, dd_id, iqn)



447
448
449
450
451
452
453
454
455
456
457
458
# File '../../src/modules/IsnsServer.rb', line 447

def deleteDDMember(address, dd_id, iqn)
  Builtins.y2milestone("deleteDDSMember:%1", iqn)
  command = Builtins.sformat(
    "isnsadm -a %1 -t -d ddmember -n %2 -m %3",
    address,
    dd_id,
    iqn
  )
  SCR.Execute(path(".target.bash_output"), command, {})

  true
end

- (Object) deleteDDS(address, id)



439
440
441
442
443
444
445
# File '../../src/modules/IsnsServer.rb', line 439

def deleteDDS(address, id)
  Builtins.y2milestone("deleteDDS")
  command = Builtins.sformat("isnsadm -a %1 -t -d dds -n '%2'", address, id)
  SCR.Execute(path(".target.bash_output"), command, {})

  true
end

- (Object) deleteDDSMember(address, dds_id, dd_id)



460
461
462
463
464
465
466
467
468
469
470
471
# File '../../src/modules/IsnsServer.rb', line 460

def deleteDDSMember(address, dds_id, dd_id)
  Builtins.y2milestone("deleteDDSMember")
  command = Builtins.sformat(
    "isnsadm -a %1 -t -d ddsmember -n %2 -m %3",
    address,
    dds_id,
    dd_id
  )
  SCR.Execute(path(".target.bash_output"), command, {})

  true
end

- (Object) deleteISCSI(address, id)



427
428
429
430
431
432
433
434
435
436
437
# File '../../src/modules/IsnsServer.rb', line 427

def deleteISCSI(address, id)
  Builtins.y2milestone("deleteISCSI")
  command = Builtins.sformat(
    "isnsadm -a %1 -t -d iscsi -n '%2'",
    address,
    id
  )
  SCR.Execute(path(".target.bash_output"), command, {})

  true
end

- (Object) getServiceStatus

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



121
122
123
124
125
126
127
128
129
130
# File '../../src/modules/IsnsServer.rb', line 121

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

- (Object) GetStartService

get/set service accessors for CWMService component



637
638
639
640
641
# File '../../src/modules/IsnsServer.rb', line 637

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

- (Object) installed_packages

test if required package (“isns”) is installed



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File '../../src/modules/IsnsServer.rb', line 101

def installed_packages
  ret = false
  Builtins.y2milestone("Check if isns is installed")
  if !Package.InstallMsg(
      "isns",
      _(
        "<p>To configure the isns service, the <b>%1</b> package must be installed.</p>"
      ) +
        _("<p>Install it now?</p>")
    )
    Popup.Error(Message.CannotContinueWithoutPackagesInstalled)
  else
    ret = true
  end

  ret
end

- (Object) main



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File '../../src/modules/IsnsServer.rb', line 16

def main
  textdomain "isns"

  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 "Mode"
  Yast.import "String"
  Yast.import "Map"

  @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



60
61
62
63
# File '../../src/modules/IsnsServer.rb', line 60

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

- (Object) Read

Read all iscsi-server settings

Returns:

  • true on success



484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
# File '../../src/modules/IsnsServer.rb', line 484

def Read
  # IsnsServer read dialog caption
  caption = _("Initializing isns daemon 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
  Progress.NextStage
  # check if required packages ("isns") is installed
  return false if !installed_packages
  Builtins.sleep(sl)

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

  return false if Abort()
  Progress.NextStage
  # read configuration (/etc/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 /etc/ietd.conf



66
67
68
69
70
71
72
73
74
75
# File '../../src/modules/IsnsServer.rb', line 66

def readConfig
  read_values = Convert.convert(
    SCR.Read(path(".etc.isns.all")),
    :from => "any",
    :to   => "map <string, any>"
  )
  # IsnsServerFunctions::parseConfig( read_values );
  Builtins.y2milestone("isns readConfig")
  true
end

- (Object) readDD(address)



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

def readDD(address)
  values = []
  ddid = ""

  Builtins.y2milestone("readDD")
  command = Builtins.sformat("isnsadm -a %1 -t -q dd", address)
  result = Convert.convert(
    SCR.Execute(path(".target.bash_output"), command, {}),
    :from => "any",
    :to   => "map <string, any>"
  )
  Builtins.foreach(
    Builtins.splitstring(Ops.get_string(result, "stdout", ""), "\n")
  ) do |row|
    pos = Builtins.findfirstof(row, ":")
    key = ""
    val = ""
    if pos != nil && Ops.greater_than(pos, 0)
      key = Builtins.substring(row, 0, pos)
      val = Builtins.substring(row, Ops.add(pos, 2))
    end
    if key == "DD ID  "
      values = Builtins.add(values, val)
    elsif key == "DD Sym Name "
      values = Builtins.add(values, val)
    end
  end

  deep_copy(values)
end

- (Object) readDDMembers(address, id)



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

def readDDMembers(address, id)
  values = []
  temp = {}
  ddid = ""

  Builtins.y2milestone("readDDSMembers %1 %2", address, id)
  command = Builtins.sformat("isnsadm -a %1 -t -q dd -n %2", address, id)
  result = Convert.convert(
    SCR.Execute(path(".target.bash_output"), command, {}),
    :from => "any",
    :to   => "map <string, any>"
  )
  Builtins.foreach(
    Builtins.splitstring(Ops.get_string(result, "stdout", ""), "\n")
  ) do |row|
    pos = Builtins.findfirstof(row, ":")
    key = ""
    val = ""
    Builtins.y2milestone("results: %1", row)
    if pos != nil && Ops.greater_than(pos, 0)
      key = Builtins.substring(row, 0, pos)
      val = Builtins.substring(row, Ops.add(pos, 2))
    end
    Ops.set(temp, "NODE", val) if key == "   DD iSCSI Member "
    if key == "   DD iSCSI Member Index  "
      Ops.set(temp, "TYPE", readISCSI_type(address, val))
      values = Builtins.add(values, temp)
    end
  end

  deep_copy(values)
end

- (Object) readDDS(address)



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

def readDDS(address)
  values = []
  ddid = ""

  Builtins.y2milestone("readDDS %1", address)
  command = Builtins.sformat("isnsadm -a %1 -t -q dds", address)
  result = Convert.convert(
    SCR.Execute(path(".target.bash_output"), command, {}),
    :from => "any",
    :to   => "map <string, any>"
  )
  Builtins.foreach(
    Builtins.splitstring(Ops.get_string(result, "stdout", ""), "\n")
  ) do |row|
    pos = Builtins.findfirstof(row, ":")
    key = ""
    val = ""
    if pos != nil && Ops.greater_than(pos, 0)
      key = Builtins.substring(row, 0, pos)
      val = Builtins.substring(row, Ops.add(pos, 2))
    end
    if key == "DDS ID  "
      values = Builtins.add(values, val)
    elsif key == "DDS Sym Name "
      values = Builtins.add(values, val)
    end
  end

  deep_copy(values)
end

- (Object) readDDSMembers(address, id)



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

def readDDSMembers(address, id)
  values = []
  ddid = ""

  Builtins.y2milestone("readDDSMembers %1 %2", address, id)
  command = Builtins.sformat("isnsadm -a %1 -t -q dds -n %2", address, id)
  result = Convert.convert(
    SCR.Execute(path(".target.bash_output"), command, {}),
    :from => "any",
    :to   => "map <string, any>"
  )
  Builtins.foreach(
    Builtins.splitstring(Ops.get_string(result, "stdout", ""), "\n")
  ) do |row|
    pos = Builtins.findfirstof(row, ":")
    key = ""
    val = ""
    Builtins.y2milestone("results: %1", row)
    if pos != nil && Ops.greater_than(pos, 0)
      key = Builtins.substring(row, 0, pos)
      val = Builtins.substring(row, Ops.add(pos, 2))
    end
    if key == "   DD ID "
      values = Builtins.add(values, val)
    elsif key == "   DD Sym Name "
      values = Builtins.add(values, val)
    end
  end

  deep_copy(values)
end

- (Object) readISCSI(address)



173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File '../../src/modules/IsnsServer.rb', line 173

def readISCSI(address)
  values = []
  temp = {}

  command = Builtins.sformat("isnsadm -a %1 -t -q iscsi", address)
  result = Convert.convert(
    SCR.Execute(path(".target.bash_output"), command, {}),
    :from => "any",
    :to   => "map <string, any>"
  )
  Builtins.foreach(
    Builtins.splitstring(Ops.get_string(result, "stdout", ""), "\n")
  ) do |row|
    pos = Builtins.findfirstof(row, ":")
    key = ""
    val = ""
    if pos != nil && Ops.greater_than(pos, 0)
      key = Builtins.substring(row, 0, pos)
    end
    if key == "iSCSI ID  "
      val = Builtins.substring(row, Ops.add(pos, 2))
      Ops.set(temp, "NODE", val)
    end
    if key == "Type"
      val = Builtins.substring(row, Ops.add(pos, 6))
      Ops.set(temp, "TYPE", val)
      values = Builtins.add(values, temp)
    end
  end

  deep_copy(values)
end

- (Object) readISCSI_type(address, index)



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

def readISCSI_type(address, index)
  temp = ""

  Builtins.y2milestone("iSCSIRead_type index:%1", index)

  command = Builtins.sformat(
    "isnsadm -a %1 -t -q iscsi -n %2",
    address,
    index
  )
  result = Convert.convert(
    SCR.Execute(path(".target.bash_output"), command, {}),
    :from => "any",
    :to   => "map <string, any>"
  )
  Builtins.foreach(
    Builtins.splitstring(Ops.get_string(result, "stdout", ""), "\n")
  ) do |row|
    pos = Builtins.findfirstof(row, ":")
    key = ""
    val = ""
    if pos != nil && Ops.greater_than(pos, 0)
      key = Builtins.substring(row, 0, pos)
      val = Builtins.substring(row, Ops.add(pos, 6))
    end
    Builtins.y2milestone("iSCSIRead_type %1", key)
    if key == "Type"
      Builtins.y2milestone("iSCSIRead_type return value is %1", val)
      temp = val
    end
  end

  temp
end

- (Object) setServiceStatus

set service status



133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File '../../src/modules/IsnsServer.rb', line 133

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

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

- (Object) SetStartService(status)



643
644
645
646
647
648
649
650
651
652
653
# File '../../src/modules/IsnsServer.rb', line 643

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

  nil
end

- (Object) testISNSAccess(address)



148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File '../../src/modules/IsnsServer.rb', line 148

def testISNSAccess(address)
  value = "OK"
  temp = {}

  command = Builtins.sformat("isnsadm -a %1 -t -q iscsi", address)
  result = Convert.convert(
    SCR.Execute(path(".target.bash_output"), command, {}),
    :from => "any",
    :to   => "map <string, any>"
  )
  Builtins.foreach(
    Builtins.splitstring(Ops.get_string(result, "stdout", ""), "\n")
  ) do |row|
    if row == "TCP error on connection"
      Builtins.y2milestone("TCP error: %1 ", row)
      value = "ERROR"
    end
    if row == "Error Sending TCP request."
      Builtins.y2milestone("Failed to resolve host error: %1 ", row)
      value = "ERROR"
    end
  end

  value
end

- (Object) Write

Write all iscsi-server settings

Returns:

  • true on success



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
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
# File '../../src/modules/IsnsServer.rb', line 566

def Write
  # IsnsServer write dialog caption
  caption = _("Saving isns 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 (/etc/isns.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
  #    if ( (serviceStatus) || (statusOnStart) )
  #	if (!reloadServer()) return false;
  #    sleep(sl);

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

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

- (Object) writeConfig

write configuration file /etc/ietd.conf



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File '../../src/modules/IsnsServer.rb', line 78

def writeConfig
  # prepare map, because perl->ycp lost information about data types (integers in this case)
  # map <string, any> config_file = IsnsServerFunctions::writeConfig();
  # config_file["type"]=tointeger(config_file["type"]:"1");
  # config_file["file"]=tointeger(config_file["file"]:"1");
  # list <map<string, any> > value = [];
  # foreach(map<string, any> row, config_file["value"]:[], {
  #  row["type"]=tointeger(row["type"]:"1");
  #  row["file"]=tointeger(row["file"]:"1");
  #  value = add(value, row);
  # });
  #
  # config_file["value"] = value;
  # y2milestone("config_file to write %1", config_file);
  # // write it
  # SCR::Write(.etc.ietd.all, config_file);
  # SCR::Write(.etc.ietd, nil);
  true
end