Module: Yast::GeoClusterDialogsInclude

Defined in:
../../src/include/geo-cluster/dialogs.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) authentification_layout(authfile)



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
151
152
153
154
155
156
157
158
159
160
161
162
# File '../../src/include/geo-cluster/dialogs.rb', line 116

def authentification_layout(authfile)
  VBox(
    VSpacing(1),
    CheckBoxFrame(
      Id(:secauth),
      Opt(:hstretch, :notify),
      _("Enable Security Auth"),
      true,
      VBox(
        InputField(
          Id(:authfilename),
          Opt(:hstretch),
          _("Authentification file"),
          authfile
        ),
        Label(
          _(
            "A relative path will be saved in /etc/booth, or using absolute path directly."
          )
        ),
        Label(
          _(
            "For a newly created geo cluster, push the button below to generate /etc/booth/<key>."
          )
        ),
        Label(
          _(
            "To join a existing geo cluster, please copy /etc/booth/<key> from other node manually."
          )
        ),
        PushButton(Id(:genf), Opt(:notify), _("Generate Authentification Key File"))
      )
    ),
    VStretch(),
    HSpacing(2),
    VBox(
      Right(
        HBox(
          PushButton(Id(:basic), _("Basic")),
          HSpacing(2),
          PushButton(Id(:cancel_inner), _("Ca&ncel")),
          PushButton(Id(:ok), _("OK"))
        )
      )
    )
  )
end

- (Object) ChooseConfigureDialog

Dialog for geo-cluster Choose config file dialog

Returns:

  • dialog result



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
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
# File '../../src/include/geo-cluster/dialogs.rb', line 793

def ChooseConfigureDialog
  # GeoCluster choose configure dialog caption
  caption = _("GeoCluster Configuration Select")

  # Wizard::SetContentsButtons(caption, contents, HELPS["c2"]:"",
  # 	    Label::BackButton(), Label::NextButton());

  config_box = VBox(
      SelectionBox(Id(:conf_box), _("Choose configuration file:")),
      Right(
        HBox(
            PushButton(Id(:conf_add), _("Add")),
            PushButton(Id(:conf_edit), _("Edit")),
            PushButton(Id(:conf_del), _("Delete"))
        )
      )
  )

  ret = nil
  current = 0
  conf_list = []
  caption = _("Geo Cluster Configuration")

  while true
    Wizard.SelectTreeItem("choose_conf")

    # FIXME ugly work. Better use alias and function, see yast2 drbd.
    Wizard.SetContents(
      caption,
      config_box,
      Ops.get_string(@HELPS, "confs", ""),
      true,
      true
    )

    conf_list = fill_conf_entries
    ret = UI.UserInput

    if ret == :conf_add
      ret = ConfigureDialog("")
      next if ret == :cancel
      next
    end

    if ret == :conf_edit
      current = UI.QueryWidget(:conf_box, :CurrentItem).to_i
      ret = ConfigureDialog(conf_list[current])
      next if ret == :cancel
      next
    end

    if ret == :conf_del
      current = UI.QueryWidget(:conf_box, :CurrentItem).to_i

      GeoCluster.global_del_confs.push(conf_list[current])
      GeoCluster.global_files.delete(conf_list[current])
      next
    end

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

    # abort?
    if ret == :abort || ret == :cancel || ret == :back
      if ReallyAbort()
        break
      else
        next
      end
    elsif ret == :next
      break
    elsif Builtins.contains(@DIALOG, Convert.to_string(ret))
      ret = Builtins.symbolof(Builtins.toterm(ret))
      break
    else
      Builtins.y2error("unexpected retcode: %1", ret)
      next
    end
  end

  deep_copy(ret)
end

- (Object) cluster_configure_layout(conf, transport, port)



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
106
107
108
109
110
111
112
113
114
# File '../../src/include/geo-cluster/dialogs.rb', line 45

def cluster_configure_layout(conf, transport, port)
  VBox(
    HBox(
      InputField(
        Id(:confname),
        Opt(:hstretch),
        _("configuration file"),
        conf
      ),
      HSpacing(1),
      ComboBox(
        Id(:transport),
        Opt(:hstretch, :notify),
        _("transport"),
        [transport]
      ),
      HSpacing(1),
      InputField(
        Id(:port),
        Opt(:hstretch),
        _("port"),
        port
      )
    ),
    HBox(
      VBox(
        SelectionBox(Id(:arbitrator_box), _("arbitrator")),
        Left(
          HBox(
            PushButton(Id(:arbitrator_add), _("Add")),
            PushButton(Id(:arbitrator_edit), _("Edit")),
            PushButton(Id(:arbitrator_del), _("Delete"))
          )
        )
      ),
      HSpacing(2),
      VBox(
        SelectionBox(Id(:site_box), _("site")),
        Right(
          HBox(
            PushButton(Id(:site_add), _("Add")),
            PushButton(Id(:site_edit), _("Edit")),
            PushButton(Id(:site_del), _("Delete"))
          )
        )
      ),
    ),
    VBox(
      Left(Label(_("ticket"))),
      Table(Id(:ticket_box), Header("ticket", "timeout", "retries", "weights", "expire", "acquire-after", "before-acquire-handler"), []),
      Left(
        HBox(
          PushButton(Id(:ticket_add), "Add"),
          PushButton(Id(:ticket_edit), "Edit"),
          PushButton(Id(:ticket_del), "Delete"))
      )
    ),
    VSpacing(1),
    VBox(
      Right(
        HBox(
          PushButton(Id(:authentification), _("Authentification")),
          HSpacing(2),
          PushButton(Id(:cancel_inner), _("Ca&ncel")),
          PushButton(Id(:ok), _("OK"))
        )
      )
    )
  )
end

- (Object) ConfigureDialog(conf)

Dialog for geo-cluster Configure2 dialog

Returns:

  • dialog result



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
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
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
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
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
# File '../../src/include/geo-cluster/dialogs.rb', line 463

def ConfigureDialog(conf)
  # GeoCluster configure2 dialog caption
  caption = _("Geo Cluster Configuration")

  # Wizard::SetContentsButtons(caption, contents, HELPS["c2"]:"",
  # 	    Label::BackButton(), Label::NextButton());

  ret = nil
  cur_page = :basic
  add_new_conf = false
  authfile_postfix = ".key"
  booth_dir = "/etc/booth/"

  current = 0
  authfile = ""
  temp_site = []
  temp_arbitrator = []
  temp_ticket = []

  transport = Ops.get(GeoCluster.global_files[conf], "transport", "UDP")
  port = Ops.get(GeoCluster.global_files[conf], "port", "")

  Wizard.SetContents(
    caption,
    cluster_configure_layout(conf, transport, port),
    Ops.get_string(@HELPS, "booth", ""),
    false,
    false
  )

  if conf != ""
    if GeoCluster.global_files[conf]["arbitrator"]
      temp_arbitrator = deep_copy(GeoCluster.global_files[conf]["arbitrator"])
    end

    if GeoCluster.global_files[conf]["site"]
      temp_site = deep_copy(GeoCluster.global_files[conf]["site"])
    end

    if GeoCluster.global_files[conf]["ticket"]
      GeoCluster.global_files[conf]["ticket"].each do |tname, value|
        temp_ticket.push({tname => deep_copy(value)})
      end
    end

    if GeoCluster.global_files[conf]["authfile"] != ""
      authfile = GeoCluster.global_files[conf]["authfile"]
    end
  else
    add_new_conf = true
  end

  while true
    fill_arbitrators_entries(temp_arbitrator)
    fill_sites_entries(temp_site)
    fill_ticket_entries(temp_ticket)

    if conf != "" && add_new_conf == false
      UI.ChangeWidget(Id(:confname), :Enabled, false)
    elsif conf == "" && GeoCluster.global_files.empty?
      UI.ChangeWidget(Id(:confname), :Value, "booth")
    end

    if temp_arbitrator.size == 0
      UI.ChangeWidget(Id(:arbitrator_edit), :Enabled, false)
      UI.ChangeWidget(Id(:arbitrator_del), :Enabled, false)
    else
      UI.ChangeWidget(Id(:arbitrator_edit), :Enabled, true)
      UI.ChangeWidget(Id(:arbitrator_del), :Enabled, true)
    end

    if temp_site.size == 0
      UI.ChangeWidget(Id(:site_edit), :Enabled, false)
      UI.ChangeWidget(Id(:site_del), :Enabled, false)
    else
      UI.ChangeWidget(Id(:site_edit), :Enabled, true)
      UI.ChangeWidget(Id(:site_del), :Enabled, true)
    end

    if temp_ticket.size == 0
      UI.ChangeWidget(Id(:ticket_edit), :Enabled, false)
      UI.ChangeWidget(Id(:ticket_del), :Enabled, false)
    else
      UI.ChangeWidget(Id(:ticket_edit), :Enabled, true)
      UI.ChangeWidget(Id(:ticket_del), :Enabled, true)
    end

    ret = UI.UserInput

    if ret == :arbitrator_add
      ret = ip_address_input_dialog(
        _("Enter an IP address of your arbitrator"),
        ""
      )
      next if ret == :cancel
      temp_arbitrator.push(ret.to_s)
      next
    end

    if ret == :arbitrator_edit
      current = UI.QueryWidget(:arbitrator_box, :CurrentItem).to_i
      ret = ip_address_input_dialog(
        _("Edit IP address of your arbitrator"),
        temp_arbitrator[current]
      )
      next if ret == :cancel
      temp_arbitrator[current] = ret.to_s
      next
    end

    if ret == :arbitrator_del
      current = UI.QueryWidget(:arbitrator_box, :CurrentItem).to_i
      temp_arbitrator.delete_at(current)
      next
    end

    if ret == :site_add
      ret = ip_address_input_dialog(
        _("Enter an IP address of your site"),
        ""
      )
      next if ret == :cancel
      temp_site.push(ret.to_s)
      next
    end

    if ret == :site_edit
      current = UI.QueryWidget(:site_box, :CurrentItem).to_i
      ret = ip_address_input_dialog(
        _("Edit IP address of your site"),
        temp_site[current]
      )
      next if ret == :cancel
      temp_site[current] = ret.to_s
      next
    end

    if ret == :site_del
      current = UI.QueryWidget(:site_box, :CurrentItem).to_i
      temp_site.delete_at(current)
      next
    end

    if ret == :ticket_add
      ret = ticket_input_dialog({})
      next if ret == :cancel

      dup_name = false
      ret.each_key do |tname|
        temp_ticket.each do |ticket|
          if ticket.include?(tname)
            Popup.Message(_("Ticket name already exist!"))
            dup_name = true
            break
          end
        end
      end
      next if dup_name

      temp_ticket.push(ret)
      next
    end

    if ret == :ticket_edit
      current = UI.QueryWidget(:ticket_box, :CurrentItem).to_i

      ret = ticket_input_dialog(temp_ticket[current])
      next if ret == :cancel
      temp_ticket[current] = ret
      next
    end

    if ret == :ticket_del
      current = UI.QueryWidget(:ticket_box, :CurrentItem).to_i
      temp_ticket.delete_at(current)
      next
    end

    if ret == :authentification || ret == :ok && cur_page == :basic
      #Validation check before switch to authentification
      #Still fall to :authentification or :ok
      conf = UI.QueryWidget(:confname, :Value).to_s
      if conf == ""
        Popup.Message(_("Configuration name can not be empty."))
        next
      elsif add_new_conf && GeoCluster.global_files.include?(conf)
        Popup.Message(_("Configuration name can not be duplicated."))
        next
      end

      port = UI.QueryWidget(:port, :Value).to_s
      num_port = Builtins.tointeger(port)
      #"5405d4" will show like "5405"
      if num_port == nil || num_port <= 0 || num_port > 65535
        Popup.Message(_("port is invalid!"))
        next
      end

      transport = UI.QueryWidget(:transport, :Value).to_s
      if transport == ""
        Popup.Message(_("transport have to be filled!"))
        next
      end

      #Same to UI.QueryWidget(:arbitrator_box, :Value).to_s == ""
      if temp_arbitrator.size == 0
        Popup.Message(_("arbitrator have to be filled!"))
        next
      end

      if temp_site.size == 0
        Popup.Message(_("site have to be filled!"))
        next
      end

      if temp_ticket.size == 0
        Popup.Message(_("ticket have to be filled!"))
        next
      end
    end

    if ret == :authentification
      cur_page = :authentification

      Wizard.SetContents(
        Ops.get_string(@NAME, "authentification_conf", ""),
        authentification_layout(authfile),
        Ops.get_string(@HELPS, "authentification", ""),
        false,
        false
      )

      if authfile == ""
        UI.ChangeWidget(Id(:secauth), :Value, false)
        UI.ChangeWidget(Id(:authfilename), :Value, conf+authfile_postfix)
      end
    end

    if ret == :basic || ret == :ok && cur_page == :authentification
      #Validation check before switch to basic
      #Still fall to :basic or :ok
      if UI.QueryWidget(Id(:secauth), :Value)
        authfile = UI.QueryWidget(Id(:authfilename), :Value)
      else
        authfile = ""
      end
    end

    if ret == :basic
      cur_page = :basic

      Wizard.SetContents(
        caption,
        cluster_configure_layout(conf, transport, port),
        Ops.get_string(@HELPS, "booth", ""),
        false,
        false
      )
    end

    if ret == :genf
      temp_authfile = UI.QueryWidget(Id(:authfilename), :Value).to_s
      if !temp_authfile.include?("/")
        temp_authfile = booth_dir+temp_authfile
      end

      if SCR.Execute(
          path(".target.bash"),
          "/usr/sbin/booth-keygen " + temp_authfile
        ) != 0
        Popup.Message(_("Failed to create authentification file ") + temp_authfile +
           "\nNeed to check the directory and remove the exist key file.")
      else
        Popup.Message(_("Succeed to created authentification file ") + temp_authfile)
      end
    end

    if ret == :wizardTree
      Wizard.SelectTreeItem("choose_conf")
      next
      #ret = Convert.to_string(UI.QueryWidget(Id(:wizardTree), :CurrentItem))
    end

    next if Builtins.contains(@DIALOG, Convert.to_string(ret))

    # abort?
    if ret == :abort || ret == :back
      if ReallyAbort()
        break
      else
        next
      end

    elsif ret == :ok
      GeoCluster.global_files[conf] = {}

      GeoCluster.global_files[conf]["port"] = port
      GeoCluster.global_files[conf]["transport"] = transport

      #Authenitification file. Disable when authfile is ""
      GeoCluster.global_files[conf]["authfile"] = authfile

      GeoCluster.global_files[conf]["arbitrator"] = temp_arbitrator
      GeoCluster.global_files[conf]["site"] = temp_site

      GeoCluster.global_files[conf]["ticket"] = {}
      temp_ticket.each do |ticket|
        GeoCluster.global_files[conf]["ticket"] = GeoCluster.global_files[conf]["ticket"].merge(ticket)
      end

      if add_new_conf && GeoCluster.global_del_confs.include?(conf)
        GeoCluster.global_del_confs.delete(conf)
      end
      break

    elsif ret == :cancel_inner
      break

    else
      Builtins.y2error("unexpected retcode: %1", ret)
      next
    end
  end

  deep_copy(ret)
end

- (Object) fill_arbitrators_entries(arbitrators)

fill arbitrator_box with global_arbitrators



319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
# File '../../src/include/geo-cluster/dialogs.rb', line 319

def fill_arbitrators_entries(arbitrators)
  i = 0
  ret = 0
  current = 0
  items = []
  arbitrators.each do |arbitrator|
    items = items.push(Item(Id(i), arbitrator))
    i += 1
  end
  current = UI.QueryWidget(:arbitrator_box, :CurrentItem).to_i
  current = i-1 if current >= i
  UI.ChangeWidget(:arbitrator_box, :Items, items)
  UI.ChangeWidget(:arbitrator_box, :CurrentItem, current)

  nil
end

- (Object) fill_conf_entries

fill confs with global_files



384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
# File '../../src/include/geo-cluster/dialogs.rb', line 384

def fill_conf_entries
  i = 0
  ret = 0
  current = 0
  items = []
  conf_list = []
  GeoCluster.global_files.each_key do |conf|
    conf_list.push(conf)
    items = items.push(Item(Id(i), conf))
    i += 1
  end
  current = UI.QueryWidget(:conf_box, :CurrentItem).to_i
  current = i-1 if current >= i

  UI.ChangeWidget(:conf_box, :Items, items)
  UI.ChangeWidget(:conf_box, :CurrentItem, current)

  deep_copy(conf_list)
end

- (Object) fill_sites_entries(sites)

fill site_box with global_site



337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
# File '../../src/include/geo-cluster/dialogs.rb', line 337

def fill_sites_entries(sites)
  i = 0
  ret = 0
  current = 0
  items = []
  sites.each do |site|
    items = items.push(Item(Id(i), site))
    i += 1
  end
  current = UI.QueryWidget(:site_box, :CurrentItem).to_i
  current = i-1 if current >= i
  UI.ChangeWidget(:site_box, :Items, items)
  UI.ChangeWidget(:site_box, :CurrentItem, current)

  nil
end

- (Object) fill_ticket_entries(tickets)

fill ticket_box with global_ticket



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
# File '../../src/include/geo-cluster/dialogs.rb', line 355

def fill_ticket_entries(tickets)
  i = 0
  ret = 0
  current = 0
  items = []

  tickets.each do |ticket_hash|
    ticket_hash.each do |tname, value|

      acquireafter = Ops.get_string(value,"acquire-after","")
      timeout = Ops.get_string(value,"timeout","")
      retries = Ops.get_string(value,"retries","")
      weights = Ops.get_string(value,"weights","")
      expire = Ops.get_string(value,"expire","")
      beforeah = Ops.get_string(value,"before-acquire-handler","")

      items = items.push(Item(Id(i), tname, timeout, retries, weights, expire, acquireafter, beforeah))
      i += 1
    end
  end
  current = UI.QueryWidget(:ticket_box, :CurrentItem).to_i
  current = i-1 if current >= i
  UI.ChangeWidget(:ticket_box, :Items, items)
  UI.ChangeWidget(:ticket_box, :CurrentItem, current)

  nil
end

- (Object) initialize_geo_cluster_dialogs(include_target)



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File '../../src/include/geo-cluster/dialogs.rb', line 30

def initialize_geo_cluster_dialogs(include_target)
  Yast.import "UI"

  textdomain "geo-cluster"

  Yast.import "Label"
  Yast.import "Wizard"
  Yast.import "GeoCluster"
  Yast.import "Popup"
  Yast.import "IP"
  Yast.import "CWMFirewallInterfaces"

  Yast.include include_target, "geo-cluster/helps.rb"
end

- (Object) ip_address_input_dialog(title, value)

return `cancel or a string



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
# File '../../src/include/geo-cluster/dialogs.rb', line 165

def ip_address_input_dialog(title, value)
  ret = nil

  UI.OpenDialog(
    MarginBox(
      1,
      1,
      VBox(
        MinWidth(100, InputField(Id(:text), Opt(:hstretch), title, value)),
        VSpacing(1),
        Right(
          HBox(
            PushButton(Id(:ok), _("OK")),
            PushButton(Id(:cancel), _("Cancel"))
          )
        )
      )
    )
  )
  while true
    ret = UI.UserInput
    if ret == :ok
      val = Convert.to_string(UI.QueryWidget(:text, :Value))
      if IP.Check(val) == true
        ret = val
        break
      else
        Popup.Message(_("Please enter a valid ip address"))
      end
    end
    break if ret == :cancel
  end
  UI.CloseDialog
  deep_copy(ret)
end

- (Object) ServiceDialog



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
# File '../../src/include/geo-cluster/dialogs.rb', line 404

def ServiceDialog
  ret = nil
  event = {}
  caption = _("Firewall Configuration")
  firewall_widget = CWMFirewallInterfaces.CreateOpenFirewallWidget(
    {
      #servie:geo-cluster is the  name of /etc/sysconfig/SuSEfirewall2.d/services/geo-cluster
      "services"        => [
        "service:booth"
      ],
      "display_details" => true
    }
  )
  firewall_layout = Ops.get_term(firewall_widget, "custom_widget", VBox())
  contents = VBox(
    VSpacing(1),
    Frame("firewall settings", firewall_layout),
    VStretch()
  )
  Wizard.SetContents(
    caption,
    firewall_layout,
    Ops.get_string(@HELPS, "geo-cluster", ""),
    true,
    true
  )
  CWMFirewallInterfaces.OpenFirewallInit(firewall_widget, "")
  while true
    event = UI.WaitForEvent
    ret = Ops.get(event, "ID")
    if ret == :next
      CWMFirewallInterfaces.OpenFirewallStore(firewall_widget, "", event)
      break
    end

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

    if Builtins.contains(@DIALOG, Convert.to_string(ret))
      ret = Builtins.symbolof(Builtins.toterm(ret))
      break
    end

    if ret == :abort || ret == :cancel
      if ReallyAbort()
        return deep_copy(ret)
      else
        next
      end
    end
    break if ret == :back
    CWMFirewallInterfaces.OpenFirewallHandle(firewall_widget, "", event)
  end
  deep_copy(ret)
end

- (Object) ticket_input_dialog(ticket_hash)



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
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
# File '../../src/include/geo-cluster/dialogs.rb', line 201

def ticket_input_dialog(ticket_hash)
  ret = nil

  ticket = ""
  acquireafter = ""
  timeout = ""
  retries = ""
  weights = ""
  expire = ""
  beforeah = ""

  if ticket_hash != {}
    if ticket_hash.size != 1
      return {}
    end

    ticket_hash.each do |tname, value|
      ticket = tname
      acquireafter = Ops.get_string(value,"acquire-after","")
      timeout = Ops.get_string(value,"timeout","")
      retries = Ops.get_string(value,"retries","")
      weights = Ops.get_string(value,"weights","")
      expire = Ops.get_string(value,"expire","")
      beforeah = Ops.get_string(value,"before-acquire-handler","")
    end
  end

  UI.OpenDialog(
    MarginBox(
      1,
      1,
      VBox(
        Label(_("Enter ticket and timeout")),
        HBox(
          InputField(Id(:ticket), Opt(:hstretch), _("ticket"), ticket),
        ),
        VSpacing(1),
        HBox(
          InputField(Id(:timeout), Opt(:hstretch), _("timeout"), timeout),
          HSpacing(2),
          InputField(Id(:retries), Opt(:hstretch), _("retries"), retries),
          HSpacing(2),
          InputField(Id(:weights), Opt(:hstretch), _("weights"), weights),
          HSpacing(2),
          InputField(Id(:expire), Opt(:hstretch), _("expire"), expire),
          HSpacing(2),
          InputField(Id(:acquireafter), Opt(:hstretch), _("acquire-after"), acquireafter),
          HSpacing(2),
          InputField(Id(:beforeah), Opt(:hstretch), _("before-acquire-handler"), beforeah)
        ),
        VSpacing(1),
        Right(
          HBox(
            PushButton(Id(:ok), _("OK")),
            PushButton(Id(:cancel), _("Cancel"))
          )
        )
      )
    )
  )

  while true
    if ticket != ""
      UI.ChangeWidget(Id(:ticket), :Enabled, false)
    end

    ret = UI.UserInput

    if ret == :ok
      ticket = UI.QueryWidget(:ticket, :Value).to_s

      timeout = UI.QueryWidget(:timeout, :Value).to_s
      expire = UI.QueryWidget(:expire, :Value).to_s
      acquireafter = UI.QueryWidget(:acquireafter, :Value).to_s
      retries = UI.QueryWidget(:retries, :Value).to_s
      weights = UI.QueryWidget(:weights, :Value).to_s
      beforeah = UI.QueryWidget(:beforeah, :Value).to_s

      num_timeout = Builtins.tointeger(timeout)
      num_expire = Builtins.tointeger(expire)
      num_acquireafter = Builtins.tointeger(acquireafter)
      num_retries = Builtins.tointeger(retries)
      num_weights = Builtins.tointeger(weights)

      if num_timeout == nil && timeout != ""
        Popup.Message(_("timeout is invalid"))
      elsif num_expire == nil && expire != ""
        Popup.Message(_("expire is invalid"))
      elsif num_acquireafter == nil && acquireafter != ""
        Popup.Message(_("acquireafter is invalid"))
      elsif num_retries == nil && retries != ""
        Popup.Message(_("retries is invalid"))
      elsif retries != "" && num_retries < 3
        Popup.Message(_("retries values lower than 3 is illegal"))
      elsif num_weights == nil && weights != ""
        Popup.Message(_("weights is invalid"))
      elsif ticket == ""
        Popup.Message(_("ticket can not be empty"))
      else
        temp_ticket = {}
        temp_ticket["timeout"] = timeout
        temp_ticket["expire"] = expire
        temp_ticket["acquire-after"] = acquireafter
        temp_ticket["retries"] = retries
        temp_ticket["weights"] = weights
        temp_ticket["before-acquire-handler"] = beforeah

        ret = {ticket => deep_copy(temp_ticket)}
        break
      end
    end
    break if ret == :cancel
  end
  UI.CloseDialog
  deep_copy(ret)
end