Module: Yast::DrbdResourceConfInclude

Defined in:
../../src/include/drbd/resource_conf.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) del_empty_item(old_map)



493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
# File '../../src/include/drbd/resource_conf.rb', line 493

def del_empty_item(old_map)
  old_map = deep_copy(old_map)
  new_map = deep_copy(old_map)
  Builtins.foreach(
    Convert.convert(old_map, :from => "map", :to => "map <string, any>")
  ) do |key, val|
    if Ops.is_map?(val)
      Ops.set(new_map, key, del_empty_item(Convert.to_map(val)))
    else
      if Builtins.size(Convert.to_string(val)) == 0
        Ops.set(new_map, key, nil)
      end
    end
  end

  deep_copy(new_map)
end

- (Object) initialize_drbd_resource_conf(include_target)



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File '../../src/include/drbd/resource_conf.rb', line 5

def initialize_drbd_resource_conf(include_target)
  Yast.import "UI"

  textdomain "drbd"

  Yast.import "Popup"
  Yast.import "Sequencer"
  Yast.import "Report"
  Yast.import "Label"
  Yast.import "Wizard"
  Yast.import "Service"
  Yast.import "Drbd"

  Yast.include include_target, "drbd/helps.rb"
  Yast.include include_target, "drbd/common.rb"
end

- (Object) res_advance_config_get_dialog(res_config)



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
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
# File '../../src/include/drbd/resource_conf.rb', line 296

def res_advance_config_get_dialog(res_config)
  res_config = deep_copy(res_config)
  VBox(
    HBox(
      ComboBox(Id(:protocol), _("Protocol"), ["A", "B", "C"]),
      HSpacing()
    ),
    Frame(
      "Startup",
      HBox(
        TextEntry(
          Id(:wfc_timeout),
          "wfc-timeout",
          Ops.get_string(res_config, "wfc-timeout", "")
        ),
        TextEntry(
          Id(:degr_wfc_timeout),
          "degr-wfc-timeout",
          Ops.get_string(res_config, "degr-wfc-timeout", "")
        )
      )
    ),
    Frame(
      "Disk",
      HBox(
        ComboBox(
          Id(:on_io_error),
          "on-io-error",
          ["detach", "panic", "pass_on"]
        ),
        HSpacing(),
        TextEntry(
          Id(:size),
          "size",
          Ops.get_string(res_config, ["disk_s", "size"], "")
        )
      )
    ),
    Frame(
      "Net",
      VBox(
        HBox(
          TextEntry(
            Id(:sndbuf_size),
            "sndbuf-size",
            Ops.get_string(res_config, ["net", "sndbuf-size"], "")
          ),
          TextEntry(
            Id(:max_buffers),
            "max-buffers",
            Ops.get_string(res_config, ["net", "max-buffers"], "")
          )
        ),
        HBox(
          TextEntry(
            Id(:timeout),
            "timeout",
            Ops.get_string(res_config, ["net", "timeout"], "")
          ),
          TextEntry(
            Id(:connect_int),
            "connect-int",
            Ops.get_string(res_config, ["net", "connect-int"], "")
          ),
          TextEntry(
            Id(:ping_int),
            "ping-int",
            Ops.get_string(res_config, ["net", "ping-int"], "")
          )
        ),
        HBox(
          TextEntry(
            Id(:max_epoch_size),
            "max-epoch-size",
            Ops.get_string(res_config, ["net", "max-epoch-size"], "")
          ),
          TextEntry(
            Id(:ko_count),
            "ko-count",
            Ops.get_string(res_config, ["net", "ko-count"], "")
          )
        )
      )
    ),
    Frame(
      "Syncer",
      HBox(
        TextEntry(
          Id(:rate),
          "Rate",
          Ops.get_string(res_config, ["syncer", "rate"], "")
        ),
        TextEntry(
          Id(:al_extents),
          "Al-extents",
          Ops.get_string(res_config, ["syncer", "al-extents"], "")
        )
      )
    ),
    VStretch(),
    Bottom(
      HBox(
        PushButton(Id(:basic), "Basic Config"),
        PushButton(Id(:cancel_inner), "Cancel"),
        PushButton(Id(:ok), "OK")
      )
    )
  )
end

- (Object) res_basic_config_get_dialog(res_config)



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
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
243
# File '../../src/include/drbd/resource_conf.rb', line 123

def res_basic_config_get_dialog(res_config)
  res_config = deep_copy(res_config)
  node_name = []

  Builtins.foreach(Ops.get_map(res_config, "on", {})) do |name, val|
    node_name = Builtins.add(node_name, name)
  end

  VBox(
    TextEntry(
      Id(:resname),
      _("Resource Name"),
      Ops.get_string(res_config, "resname", "")
    ),
    Frame(
      "Nodes Configurations",
      HBox(
        MarginBox(
          1,
          1,
          Frame(
            "Node 1",
            VBox(
              TextEntry(Id(:n1_name), "Name", Ops.get(node_name, 0, "")),
              TextEntry(
                Id(:n1_addr),
                "Address:Port",
                Ops.get_string(
                  res_config,
                  ["on", Ops.get(node_name, 0, ""), "address"],
                  ""
                )
              ),
              TextEntry(
                Id(:n1_devc),
                "Device",
                Ops.get_string(
                  res_config,
                  ["on", Ops.get(node_name, 0, ""), "device"],
                  ""
                )
              ),
              TextEntry(
                Id(:n1_disk),
                "Disk",
                Ops.get_string(
                  res_config,
                  ["on", Ops.get(node_name, 0, ""), "disk"],
                  ""
                )
              ),
              TextEntry(
                Id(:n1_meta),
                "Meta-disk",
                Ops.get_string(
                  res_config,
                  ["on", Ops.get(node_name, 0, ""), "meta-disk"],
                  "internal"
                )
              )
            )
          )
        ),
        MarginBox(
          1,
          1,
          Frame(
            "Node 2",
            VBox(
              TextEntry(Id(:n2_name), "Name", Ops.get(node_name, 1, "")),
              TextEntry(
                Id(:n2_addr),
                "Address:Port",
                Ops.get_string(
                  res_config,
                  ["on", Ops.get(node_name, 1, ""), "address"],
                  ""
                )
              ),
              TextEntry(
                Id(:n2_devc),
                "Device",
                Ops.get_string(
                  res_config,
                  ["on", Ops.get(node_name, 1, ""), "device"],
                  ""
                )
              ),
              TextEntry(
                Id(:n2_disk),
                "Disk",
                Ops.get_string(
                  res_config,
                  ["on", Ops.get(node_name, 1, ""), "disk"],
                  ""
                )
              ),
              TextEntry(
                Id(:n2_meta),
                "Meta-disk",
                Ops.get_string(
                  res_config,
                  ["on", Ops.get(node_name, 1, ""), "meta-disk"],
                  "internal"
                )
              )
            )
          )
        )
      )
    ),
    VStretch(),
    Bottom(
      HBox(
        PushButton(Id(:advance), "Advanced Config"),
        PushButton(Id(:cancel_inner), "Cancel"),
        PushButton(Id(:ok), "OK")
      )
    )
  )
end

- (Object) res_list_get_dialog



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
50
51
52
53
54
55
56
57
58
59
60
# File '../../src/include/drbd/resource_conf.rb', line 22

def res_list_get_dialog
  table_items = []

  Builtins.foreach(
    Convert.convert(
      Drbd.resource_config,
      :from => "map",
      :to   => "map <string, map <string, any>>"
    )
  ) do |resname, resconfig|
    next if Ops.get(Drbd.resource_config, resname) == nil
    items = Item(Id(resname))
    items = Builtins.add(items, resname)
    Builtins.foreach(Ops.get_map(resconfig, "on", {})) do |nodename, nodeconfig|
      items = Builtins.add(items, nodename)
    end
    table_items = Builtins.add(table_items, items)
    0
  end

  VBox(
    Opt(:hvstretch),
    VBox(
      Opt(:hvstretch),
      Table(
        Id(:res_list_table),
        Header("Resource      ", "Node-1       ", "Node-2       "),
        table_items
      )
    ),
    Left(
      HBox(
        PushButton(Id(:add), "Add"),
        PushButton(Id(:edit), "Edit"),
        PushButton(Id(:delete), "Delete")
      )
    )
  )
end

- (Object) ResAddDialog



661
662
663
664
665
# File '../../src/include/drbd/resource_conf.rb', line 661

def ResAddDialog
  ret = nil
  ret = ResDialog("")
  deep_copy(ret)
end

- (Object) ResDialog(resname)



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
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
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
# File '../../src/include/drbd/resource_conf.rb', line 512

def ResDialog(resname)
  ret = nil
  cur_page = :basic
  res_config = Ops.get_map(Drbd.resource_config, resname, {})
  Ops.set(res_config, "resname", resname)

  my_SetContents("basic_conf", res_basic_config_get_dialog(res_config))
  #Popup::Warning(resname);

  Wizard.DisableNextButton
  Wizard.DisableAbortButton

  while true
    Wizard.SelectTreeItem("resource_conf")
    ret = UI.UserInput

    Builtins.y2debug("in ResDialog(), UserInput ret=%1", ret)

    if ret == :help
      #myHelp("basic_conf");
      next
    end

    if ret == :wizardTree
      next
      ret = Convert.to_string(UI.QueryWidget(Id(:wizardTree), :CurrentItem))
    end

    next if Builtins.contains(@DIALOG, Builtins.tostring(ret))


    if ret == :advance || ret == :ok && cur_page == :basic
      if Convert.to_string(UI.QueryWidget(Id(:n1_name), :Value)) ==
          Convert.to_string(UI.QueryWidget(Id(:n2_name), :Value))
        Popup.Warning(_("Node names must be different."))
        ret = nil
        next
      end

      Drbd.modified = true

      Builtins.foreach(
        [
          :resname,
          :n1_addr,
          :n1_name,
          :n1_devc,
          :n1_disk,
          :n1_meta,
          :n2_name,
          :n2_addr,
          :n2_devc,
          :n2_disk,
          :n2_meta
        ]
      ) do |the_id|
        str = Convert.to_string(UI.QueryWidget(Id(the_id), :Value))
        if str == nil || Builtins.size(str) == 0
          Popup.Warning(_("Please fill out all fields."))
          ret = nil
          raise Break
        end
      end
      next if ret == nil
    end

    if ret == :advance
      cur_page = :advance

      res_config = save_basic_config(res_config)
      Builtins.y2debug("res_config = %1", res_config)

      my_SetContents(
        "advance_conf",
        res_advance_config_get_dialog(res_config)
      )

      UI.ChangeWidget(
        Id(:protocol),
        :Value,
        Ops.get_string(res_config, "protocol", "C")
      )
      UI.ChangeWidget(
        Id(:on_io_error),
        :Value,
        Ops.get_string(res_config, ["disk_s", "on-io-error"], "pass_on")
      )

      Wizard.DisableNextButton
      Wizard.DisableAbortButton

      next
    end

    if ret == :basic
      cur_page = :basic

      res_config = save_advance_config(res_config)
      my_SetContents("basic_conf", res_basic_config_get_dialog(res_config))

      Wizard.DisableNextButton
      Wizard.DisableAbortButton

      next
    end

    break if ret == :cancel_inner

    if ret == :ok
      res_config = save_basic_config(res_config)
      res_config = save_advance_config(res_config)

      Builtins.y2debug("res_config=%1", res_config)

      if Ops.greater_than(Builtins.size(resname), 0)
        Drbd.resource_config = Builtins.remove(
          Drbd.resource_config,
          resname
        )
        Ops.set(Drbd.resource_config, resname, nil)
        resname = Ops.get_string(res_config, "resname", "")
        Builtins.y2debug("resname=%1", resname)
        if Ops.greater_than(Builtins.size(resname), 0)
          res_config = Builtins.remove(res_config, "resname")
          Ops.set(Drbd.resource_config, resname, res_config)
          Builtins.y2debug("new resname = %1", resname)
          Builtins.y2debug(
            "mcdebug drbd::resource_config = %1",
            Drbd.resource_config
          )
        end
      else
        Builtins.y2debug("add new resouce")
        resname = Ops.get_string(res_config, "resname", "")
        if Ops.greater_than(Builtins.size(resname), 0)
          res_config = Builtins.remove(res_config, "resname")
          Ops.set(Drbd.resource_config, resname, res_config)
        end
      end
      break
    end
  end

  Wizard.EnableNextButton
  Wizard.EnableAbortButton
  deep_copy(ret)
end

- (Object) ResEditDialog



668
669
670
671
672
673
674
675
676
# File '../../src/include/drbd/resource_conf.rb', line 668

def ResEditDialog
  ret = nil
  resname = Convert.to_string(
    UI.QueryWidget(Id(:res_list_table), :CurrentItem)
  )
  ret = ResDialog(resname)

  deep_copy(ret)
end

- (Object) ResListDialog



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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File '../../src/include/drbd/resource_conf.rb', line 66

def ResListDialog
  my_SetContents("resource_conf", res_list_get_dialog)

  ret = nil
  while true
    Wizard.SelectTreeItem("resource_conf")

    ret = UI.UserInput

    Builtins.y2debug("on ResListDialog(), UserInput ret=%1", ret)

    if ret == :help
      myHelp("global_conf")
      next
    end

    if ret == :wizardTree
      ret = Convert.to_string(UI.QueryWidget(Id(:wizardTree), :CurrentItem))
    end

    if ret == "resource_conf" || ret == "DialogRefresh" ||
        ret == "MinorCount" ||
        ret == "DisableIpVerification"
      next
    end

    if ret == :delete
      resname = Convert.to_string(
        UI.QueryWidget(Id(:res_list_table), :CurrentItem)
      )
      Ops.set(Drbd.resource_config, Builtins.sformat("%1", resname), nil)
      ret = :list
      break
    end

    if ret == :abort || ret == :cancel
      if ReallyAbort()
        return deep_copy(ret)
      else
        next
      end
    end

    if ret == :next || ret == :back || ret == :edit || ret == :add ||
        Builtins.contains(@DIALOG, Builtins.tostring(ret))
      next if !resource_conf_Write

      if ret != :next && ret != :back && ret != :edit && ret != :add
        ret = Builtins.symbolof(Builtins.toterm(ret))
      end

      break
    end
  end
  deep_copy(ret)
end

- (Object) resource_conf_Write



62
63
64
# File '../../src/include/drbd/resource_conf.rb', line 62

def resource_conf_Write
  true
end

- (Object) ResourceSequence



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
# File '../../src/include/drbd/resource_conf.rb', line 679

def ResourceSequence
  aliases = { "list" => lambda { ResListDialog() }, "add" => lambda do
    ResAddDialog()
  end, "edit" => lambda(
  ) do
    ResEditDialog()
  end }

  sequence = {
    "ws_start" => "list",
    "list"     => {
      :startup_conf => :startup_conf,
      :global_conf  => :global_conf,
      :add          => "add",
      :edit         => "edit",
      :list         => "list",
      :abort        => :abort,
      :next         => :next
    },
    "add"      => {
      :abort        => :abort,
      :ok           => "list",
      :cancel_inner => "list"
    },
    "edit"     => {
      :ok           => "list",
      :abort        => :abort,
      :cancel_inner => "list"
    }
  }

  ret = Sequencer.Run(aliases, sequence)

  deep_copy(ret)
end

- (Object) save_advance_config(res_config)



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
# File '../../src/include/drbd/resource_conf.rb', line 406

def save_advance_config(res_config)
  res_config = deep_copy(res_config)
  if UI.QueryWidget(Id(:protocol), :Value) == nil
    if Ops.get(res_config, "protocol") == nil
      Ops.set(res_config, "protocol", "C")
    end
    if Ops.get(res_config, ["disk_s", "on-io-error"]) == nil
      Ops.set(res_config, "disk_s", { "on-io-error" => "pass_on" })
    end
    return deep_copy(res_config)
  end


  Ops.set(
    res_config,
    "protocol",
    Convert.to_string(UI.QueryWidget(Id(:protocol), :Value))
  )

  Ops.set(
    res_config,
    "startup",
    {
      "wfc-timeout"      => Convert.to_string(
        UI.QueryWidget(Id(:wfc_timeout), :Value)
      ),
      "degr-wfc-timeout" => Convert.to_string(
        UI.QueryWidget(Id(:degr_wfc_timeout), :Value)
      )
    }
  )

  Ops.set(
    res_config,
    "disk_s",
    {
      "on-io-error" => Convert.to_string(
        UI.QueryWidget(Id(:on_io_error), :Value)
      ),
      "size"        => Convert.to_string(UI.QueryWidget(Id(:size), :Value))
    }
  )

  Ops.set(
    res_config,
    "net",
    {
      "sndbuf-size"    => Convert.to_string(
        UI.QueryWidget(Id(:sndbuf_size), :Value)
      ),
      "timeout"        => Convert.to_string(
        UI.QueryWidget(Id(:timeout), :Value)
      ),
      "connect-int"    => Convert.to_string(
        UI.QueryWidget(Id(:connect_int), :Value)
      ),
      "ping-int"       => Convert.to_string(
        UI.QueryWidget(Id(:ping_int), :Value)
      ),
      "max-buffers"    => Convert.to_string(
        UI.QueryWidget(Id(:max_buffers), :Value)
      ),
      "max-epoch-size" => Convert.to_string(
        UI.QueryWidget(Id(:max_epoch_size), :Value)
      ),
      "ko-count"       => Convert.to_string(
        UI.QueryWidget(Id(:ko_count), :Value)
      )
    }
  )

  Ops.set(
    res_config,
    "syncer",
    {
      "al-extents" => Convert.to_string(
        UI.QueryWidget(Id(:al_extents), :Value)
      ),
      "rate"       => Convert.to_string(UI.QueryWidget(Id(:rate), :Value))
    }
  )

  Builtins.y2debug("ret = %1", res_config)
  deep_copy(res_config)
end

- (Object) save_basic_config(res_config)



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
# File '../../src/include/drbd/resource_conf.rb', line 246

def save_basic_config(res_config)
  res_config = deep_copy(res_config)
  if UI.QueryWidget(Id(:resname), :Value) == nil
    return deep_copy(res_config)
  end

  Ops.set(
    res_config,
    "resname",
    Convert.to_string(UI.QueryWidget(Id(:resname), :Value))
  )
  Ops.set(
    res_config,
    "on",
    {
      Convert.to_string(UI.QueryWidget(Id(:n1_name), :Value)) => {
        "address"   => Convert.to_string(
          UI.QueryWidget(Id(:n1_addr), :Value)
        ),
        "device"    => Convert.to_string(
          UI.QueryWidget(Id(:n1_devc), :Value)
        ),
        "disk"      => Convert.to_string(
          UI.QueryWidget(Id(:n1_disk), :Value)
        ),
        "meta-disk" => Convert.to_string(
          UI.QueryWidget(Id(:n1_meta), :Value)
        )
      },
      Convert.to_string(UI.QueryWidget(Id(:n2_name), :Value)) => {
        "address"   => Convert.to_string(
          UI.QueryWidget(Id(:n2_addr), :Value)
        ),
        "device"    => Convert.to_string(
          UI.QueryWidget(Id(:n2_devc), :Value)
        ),
        "disk"      => Convert.to_string(
          UI.QueryWidget(Id(:n2_disk), :Value)
        ),
        "meta-disk" => Convert.to_string(
          UI.QueryWidget(Id(:n2_meta), :Value)
        )
      }
    }
  )

  deep_copy(res_config)
end