Class: Yast::MultipathClass

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

Instance Method Summary (collapse)

Instance Method Details

- (Boolean) Abort

Abort function

Returns:

  • (Boolean)

    return true if abort



69
70
71
72
# File '../../src/modules/Multipath.rb', line 69

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

- (Object) main



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

def main
  Yast.import "UI"
  textdomain "multipath"

  Yast.import "Progress"
  Yast.import "Report"
  Yast.import "Summary"
  Yast.import "Message"
  Yast.import "Label"
  Yast.import "Popup"
  Yast.import "Wizard"
  Yast.import "Confirm"
  Yast.import "PackageSystem"
  Yast.import "Mode"
  Yast.import "Stage"
  Yast.import "Storage"

  @config_modified = false


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

  # work around a bug in compiling ybc with UI as Y2Namespace
  #  #299258
  @dummy = UI.GetDisplayInfo

  Yast.include self, "multipath/helps.rb"
  Yast.include self, "multipath/complex.rb"
end

- (Object) Modified



73
74
75
# File '../../src/modules/Multipath.rb', line 73

def Modified
  @config_modified
end

- (Object) Read

Read all multipath settings

Returns:

  • true on success



141
142
143
144
145
146
147
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
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
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
# File '../../src/modules/Multipath.rb', line 141

def Read
  ret = false

  # Multipath read dialog caption
  caption = _("Initializing Multipath Configuration")

  steps = 4

  sl = 100
  Builtins.sleep(sl)

  # We do not set help text here, because it was set outside
  Progress.New(
    caption,
    " ",
    steps,
    [
      # Progress stage 1/3
      _("Read configurations"),
      # Progress stage 2/3
      _("Read service status"),
      # Progress stage 3/3
      _("Detect the devices")
    ],
    [
      # Progress step 1/3
      _("Reading the configurations..."),
      # Progress step 2/3
      _("Reading the service status..."),
      # Progress step 3/3
      _("Detecting the devices..."),
      # Progress finished
      _("Finished")
    ],
    ""
  )

  # BNC #418703
  # Checking and Installing packages only if needed (possible)
  required_pack_list = ["multipath-tools", "device-mapper"]
  if Mode.normal && Stage.normal
    ret = PackageSystem.CheckAndInstallPackagesInteractive(
      required_pack_list
    )
    if ret == false
      Report.Error(_("Cannot install required packages."))
      return false
    end
  else
    Yast.import "PackagesProposal"
    proposal_ID = "multipath_proposal"
    PackagesProposal.SetResolvables(
      proposal_ID,
      :package,
      required_pack_list
    )
    Builtins.y2milestone("Not checking installed packages")
  end

  ret = Read_Configures()
  return ret if ret == false

  Progress.NextStage
  Builtins.sleep(sl)

  # read multipath service status
  if Mode.normal && Stage.normal
    @service_status = Convert.to_integer(
      SCR.Execute(path(".target.bash"), "/etc/init.d/multipathd status")
    )
    @service_status = 1 if Ops.greater_than(@service_status, 0)
  else
    @service_status = Convert.to_integer(
      SCR.Execute(
        path(".target.bash"),
        "/bin/ps -A -o comm | grep -q multipathd"
      )
    )
    @service_status = 1 if @service_status != 0
  end
  Progress.NextStep
  Builtins.sleep(sl)

  # read current settings
  Progress.NextStage
  # Error message
  Report.Error(Message.CannotReadCurrentSettings) if false
  Builtins.sleep(sl)

  # detect devices
  Progress.NextStage
  # Error message
  Report.Warning(_("Cannot detect devices.")) if false
  Builtins.sleep(sl)

  # Progress finished
  Progress.NextStage
  Builtins.sleep(sl)

  @config_modified = false
  true
end

- (Object) Read_Configures



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
106
107
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
# File '../../src/modules/Multipath.rb', line 78

def Read_Configures
  ret = false

  @config_modified = false
  @defaults_items = {}
  @devices_items = []
  @multipaths_items = []
  @blacklist_items = []
  @blacklist_exception_items = []


  # prepare for loading built-in configurations
  SCR.Execute(
    path(".target.bash"),
    Ops.add("/sbin/multipath -t > ", @builtin_multipath_conf_path)
  )

  ret = Read_MultipathConfig()
  if ret == false
    Report.Error(
      _("Cannot read multipath section in multipath configuration.")
    )
    return false
  end

  ret = Read_DefaultsConfig()
  if ret == false
    Report.Error(
      _("Cannot read defaults section in multipath configuration.")
    )
    return false
  end

  ret = Read_BlacklistConfig()
  if ret == false
    Report.Error(
      _("Cannot read blacklist section in multipath configuration.")
    )
    return false
  end

  ret = Read_BlacklistException_Config()
  if ret == false
    Report.Error(
      _(
        "Cannot read blacklist_exceptions section in multipath configuration."
      )
    )
    return false
  end

  ret = Read_DeviceConfig()
  if ret == false
    Report.Error(
      _("Cannot read devices section in multipath configuration.")
    )
    return false
  end
  true
end

- (Object) ReadDialog

Read settings dialog @@return abort if aborted andnext otherwise



321
322
323
324
325
326
# File '../../src/modules/Multipath.rb', line 321

def ReadDialog
  Wizard.RestoreHelp(Ops.get_string(@HELPS, "read", ""))
  return :abort if !Confirm.MustBeRoot
  ret = Read()
  ret ? :next : :abort
end

- (Object) ReallyAbort



315
316
317
# File '../../src/modules/Multipath.rb', line 315

def ReallyAbort
  !Modified() || Popup.ReallyAbort(true)
end

- (Object) SummaryDialog

Summary dialog

Returns:

  • dialog result



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
376
377
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
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
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
# File '../../src/modules/Multipath.rb', line 339

def SummaryDialog
  Builtins.y2milestone("--------- in SummaryDialog --------------------")

  @has_dumbtab = UI.HasSpecialWidget(:DumbTab)

  Wizard.SetContentsButtons(
    @caption,
    @contents,
    Ops.get_string(@HELPS, "Status_help", ""),
    Label.BackButton,
    Label.FinishButton
  )
  Wizard.HideBackButton

  ret = nil
  current_tab = :status
  interval_millisec = 50

  # Disable configure tab during installation
  if !(Mode.normal && Stage.normal)
    UI.ChangeWidget(Id(_("Configure")), :Enabled, false) if !@has_dumbtab
  end

  while true
    ret = UI.TimeoutUserInput(interval_millisec)
    interval_millisec = 5000
    break if ret == :next

    if ret == :timeout && current_tab == :status
      Update_Service_Status()
      next
    end

    if ret == :abort || ret == :cancel || ret == :back
      if ReallyAbort()
        break
      else
        next
      end
    elsif ret == _("Status")
      Wizard.SetContentsButtons(
        @caption,
        @contents,
        Ops.get_string(@HELPS, "Status_help", ""),
        Label.BackButton,
        Label.FinishButton
      )
      Wizard.HideBackButton
      UI.ChangeWidget(Id(:tabs), :CurrentItem, _("Status")) if @has_dumbtab
      UI.ReplaceWidget(Id(:tab_replace_id), @tab_status)
      Update_Service_Status()
      current_tab = :status
      next
    elsif ret == _("Configure")
      if !(Mode.normal && Stage.normal)
        Popup.Message(
          "Can't change configuration of multipath during installation"
        )
        if @has_dumbtab
          UI.ChangeWidget(Id(:tabs), :CurrentItem, _("Status"))
        end
        next
      end
      Wizard.SetContentsButtons(
        @caption,
        @contents,
        Ops.get_string(@HELPS, "Configure_help", ""),
        Label.BackButton,
        Label.FinishButton
      )
      Wizard.HideBackButton
      if @has_dumbtab
        UI.ChangeWidget(Id(:tabs), :CurrentItem, _("Configure"))
      end
      UI.ReplaceWidget(Id(:tab_replace_id), @tab_config)
      UI.ChangeWidget(
        Id(:multipaths_table_id),
        :Items,
        Build_MultipathsTable()
      )
      current_tab = :configure
      next
    elsif ret == :start_multipath
      if Modified() == true &&
          Popup.YesNo(_("Ignore your modification?")) == false
        Update_Service_Status()
        next
      end
      Start_Service()
      Read_Configures()
      next
    elsif ret == :stop_multipath
      if Modified() == true &&
          Popup.YesNo(_("Ignore your modification?")) == false
        Update_Service_Status()
        next
      end
      Stop_Service()
      Read_Configures()
      next
    elsif ret == :blacklist_config_id
      ret = Blacklist_Dialog()

      if ret == :cancel || ret == :abort
        break if ReallyAbort()
      elsif ret == :next || ret == :back
        Wizard.SetContentsButtons(
          @caption,
          @contents,
          Ops.get_string(@HELPS, "Configure_help", ""),
          Label.BackButton,
          Label.FinishButton
        )
        Wizard.HideBackButton
        UI.ReplaceWidget(Id(:contents_replace_id), @Tabs)
        if @has_dumbtab
          UI.ChangeWidget(Id(:tabs), :CurrentItem, _("Configure"))
        end
        UI.ReplaceWidget(Id(:tab_replace_id), @tab_config)
        UI.ChangeWidget(
          Id(:multipaths_table_id),
          :Items,
          Build_MultipathsTable()
        )
        next
      end
    elsif ret == :blacklist_exception_config_id
      ret = Blacklist_Exception_Dialog()

      if ret == :cancel || ret == :abort
        break if ReallyAbort()
      elsif ret == :next || ret == :back
        Wizard.SetContentsButtons(
          @caption,
          @contents,
          Ops.get_string(@HELPS, "Configure_help", ""),
          Label.BackButton,
          Label.FinishButton
        )
        Wizard.HideBackButton
        UI.ReplaceWidget(Id(:contents_replace_id), @Tabs)
        if @has_dumbtab
          UI.ChangeWidget(Id(:tabs), :CurrentItem, _("Configure"))
        end
        UI.ReplaceWidget(Id(:tab_replace_id), @tab_config)
        UI.ChangeWidget(
          Id(:multipaths_table_id),
          :Items,
          Build_MultipathsTable()
        )
        next
      end
    elsif ret == :defaults_config_id
      ret = Defaults_Dialog()
      if ret == :cancel || ret == :abort
        break if ReallyAbort()
      elsif ret == :next || ret == :back
        Wizard.SetContentsButtons(
          @caption,
          @contents,
          Ops.get_string(@HELPS, "Configure_help", ""),
          Label.BackButton,
          Label.FinishButton
        )
        Wizard.HideBackButton
        UI.ReplaceWidget(Id(:contents_replace_id), @Tabs)
        if @has_dumbtab
          UI.ChangeWidget(Id(:tabs), :CurrentItem, _("Configure"))
        end
        UI.ReplaceWidget(Id(:tab_replace_id), @tab_config)
        UI.ChangeWidget(
          Id(:multipaths_table_id),
          :Items,
          Build_MultipathsTable()
        )
        next
      end
    elsif ret == :device_config_id
      ret = Devices_Dialog()
      if ret == :cancel || ret == :abort
        break if ReallyAbort()
      elsif ret == :next || ret == :back
        Wizard.SetContentsButtons(
          @caption,
          @contents,
          Ops.get_string(@HELPS, "Configure_help", ""),
          Label.BackButton,
          Label.FinishButton
        )
        Wizard.HideBackButton
        UI.ReplaceWidget(Id(:contents_replace_id), @Tabs)
        if @has_dumbtab
          UI.ChangeWidget(Id(:tabs), :CurrentItem, _("Configure"))
        end
        UI.ReplaceWidget(Id(:tab_replace_id), @tab_config)
        UI.ChangeWidget(
          Id(:multipaths_table_id),
          :Items,
          Build_MultipathsTable()
        )
        next
      end
    elsif ret == :multipaths_del_id || ret == :multipaths_edit_id ||
        ret == :multipaths_table_id ||
        ret == :multipaths_add_id
      Multipath_Dialog(Convert.to_symbol(ret))
      next
    end
  end

  deep_copy(ret)
end

- (Object) Write

Write all multipath settings

Returns:

  • true on success



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

def Write
  # Multipath read dialog caption
  caption = _("Saving Multipath Configuration")

  steps = 2

  sl = 100
  Builtins.sleep(sl)

  return true if @config_modified == false

  # We do not set help text here, because it was set outside
  Progress.New(
    caption,
    " ",
    steps,
    [
      # Progress stage 1/3
      _("Write the settings"),
      # Progress stage 2/3
      _("Restart multipathd")
    ],
    [
      # Progress step 1/2
      _("Writing the settings..."),
      # Progress step 2/2
      _("Restarting multipathd..."),
      # Progress finished
      _("Finished")
    ],
    ""
  )

  # write settings
  Progress.NextStage
  configurations = Build_Multipath_Conf()
  return false if configurations == nil
  if false == SCR.Write(path(".etc.multipath.all"), configurations)
    Report.Error(_("Can not write settings."))
    return false
  end
  SCR.Write(path(".etc.multipath"), nil)

  # restart multipathd
  Progress.NextStage

  if @service_status == 1
    if Mode.normal && Stage.normal
      if 0 !=
          SCR.Execute(
            path(".target.bash"),
            "/etc/init.d/multipathd restart"
          )
        Report.Error(_("Restarting multipathd failed."))
        return false
      end
    else
      Storage.ActivateMultipath(false)
      Storage.ActivateMultipath(true)
    end
    Builtins.sleep(sl)
  end

  # Progress finished
  Progress.NextStage
  Builtins.sleep(sl)

  true
end

- (Object) WriteDialog

Write settings dialog @@return abort if aborted andnext otherwise



330
331
332
333
334
# File '../../src/modules/Multipath.rb', line 330

def WriteDialog
  Wizard.RestoreHelp(Ops.get_string(@HELPS, "write", ""))
  ret = Write()
  ret ? :next : :abort
end