Module: Yast::PartitioningEpHdInclude

Defined in:
../../src/include/partitioning/ep-hd.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) CreateHdDiskDevicesTab(user_data)



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
# File '../../src/include/partitioning/ep-hd.rb', line 551

def CreateHdDiskDevicesTab(user_data)
  user_data = deep_copy(user_data)
  part_device = Convert.to_string(user_data)

  _Predicate = lambda do |disk, partition|
    disk = deep_copy(disk)
    partition = deep_copy(partition)
    StorageFields.PredicateUsedByDevice(disk, partition, [part_device])
  end

  fields = StorageSettings.FilterTable(
    [
      :device,
      :udev_path,
      :udev_id,
      :size,
      :format,
      :encrypted,
      :type,
      :used_by
    ]
  )

  target_map = Storage.GetTargetMap

  table_header = StorageFields.TableHeader(fields)
  table_contents = StorageFields.TableContents(
    fields,
    target_map,
    fun_ref(_Predicate, "symbol (map, map)")
  )

  UI.ReplaceWidget(
    :tab_panel,
    VBox(
      Table(
        Id(:table),
        Opt(:keepSorting, :notify),
        table_header,
        table_contents
      )
    )
  )

  # helptext
  helptext = _(
    "<p>This view shows all devices used by the\n" +
      "selected hard disk. The view is only available for BIOS RAIDs, partitioned\n" +
      "software RAIDs and multipath disks.</p>\n"
  )

  Wizard.RestoreHelp(Ops.add(helptext, StorageFields.TableHelptext(fields)))

  nil
end

- (Object) CreateHdDiskOverviewTab(user_data)



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
# File '../../src/include/partitioning/ep-hd.rb', line 257

def CreateHdDiskOverviewTab(user_data)
  user_data = deep_copy(user_data)
  device = Convert.to_string(user_data)

  target_map = Storage.GetTargetMap

  ctype = Ops.get_symbol(target_map, [device, "type"], :CT_DISK)

  fields = [
    :heading_device,
    :device,
    :size,
    :udev_path,
    :udev_id,
    :used_by,
    :heading_hd,
    :vendor,
    :model,
    :num_cyl,
    :cyl_size,
    :bus,
    :bios_id,
    :sector_size,
    :disk_label
  ]

  if Builtins.contains([:CT_MDPART], ctype)
    fields = Convert.convert(
      Builtins.merge(
        fields,
        [:heading_md, :raid_type, :chunk_size, :parity_algorithm]
      ),
      :from => "list",
      :to   => "list <symbol>"
    )
  end

  if Builtins.contains([:CT_DISK], ctype) &&
      (Ops.get_symbol(target_map, [device, "transport"], :unknown) == :fc ||
        Ops.get_symbol(target_map, [device, "transport"], :unknown) == :fcoe)
    fields = Convert.convert(
      Builtins.merge(
        fields,
        [:heading_fc, :fc_wwpn, :fc_port_id, :fc_fcp_lun]
      ),
      :from => "list",
      :to   => "list <symbol>"
    )
  end

  fields = StorageSettings.FilterOverview(fields)

  buttons = HBox()

  if Ops.greater_than(
      Convert.to_integer(
        SCR.Read(path(".target.size"), "/usr/sbin/smartctl")
      ),
      0
    )
    # push button text (do not translate 'SMART', it is the name of the tool)
    buttons = Builtins.add(
      buttons,
      PushButton(Id(:smart), _("Health Test (SMART)..."))
    )
  end

  if Ops.greater_than(
      Convert.to_integer(SCR.Read(path(".target.size"), "/sbin/hdparm")),
      0
    )
    # push button text (do not translate 'hdparm', it is the name of the tool)
    buttons = Builtins.add(
      buttons,
      PushButton(Id(:hdparm), _("Properties (hdparm)..."))
    )
  end

  UI.ReplaceWidget(
    :tab_panel,
    VBox(
      HStretch(),
      StorageFields.Overview(fields, target_map, device),
      Builtins.add(buttons, HStretch())
    )
  )

  # helptext
  helptext = _(
    "<p>This view shows detailed information about the\nselected hard disk.</p>"
  )

  Wizard.RestoreHelp(
    Ops.add(helptext, StorageFields.OverviewHelptext(fields))
  )

  nil
end

- (Object) CreateHdDiskPanel(user_data)



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
# File '../../src/include/partitioning/ep-hd.rb', line 608

def CreateHdDiskPanel(user_data)
  user_data = deep_copy(user_data)
  device = Convert.to_string(user_data)

  target_map = Storage.GetTargetMap

  data = {
    :overview   => {
      :create    => fun_ref(method(:CreateHdDiskOverviewTab), "void (any)"),
      :handle    => fun_ref(
        method(:HandleHdDiskOverviewTab),
        "void (any, map)"
      ),
      :user_data => user_data
    },
    :partitions => {
      :create    => fun_ref(
        method(:CreateHdDiskPartitionsTab),
        "void (any)"
      ),
      :handle    => fun_ref(
        method(:HandleHdDiskPartitionsTab),
        "void (any, map)"
      ),
      :user_data => user_data
    },
    :devices    => {
      :create    => fun_ref(method(:CreateHdDiskDevicesTab), "void (any)"),
      :user_data => user_data
    }
  }

  ctype = Ops.get_symbol(target_map, [device, "type"], :CT_DISK)

  tabs = [
    # tab heading
    Item(Id(:overview), _("&Overview")),
    # tab heading
    Item(Id(:partitions), _("&Partitions"))
  ]

  if Builtins.contains([:CT_DMRAID, :CT_DMMULTIPATH, :CT_MDPART], ctype)
    # tab heading
    tabs = Builtins.add(tabs, Item(Id(:devices), _("&Used Devices")))
  end

  UI.ReplaceWidget(
    :tree_panel,
    Greasemonkey.Transform(
      VBox(
        # heading
        term(
          :IconAndHeading,
          Builtins.sformat(_("Hard Disk: %1"), device),
          StorageIcons.hd_icon
        ),
        DumbTab(
          Id(:tab),
          tabs,
          ReplacePoint(Id(:tab_panel), TabPanel.empty_panel)
        )
      )
    )
  )

  TabPanel.Init(data, :partitions)

  nil
end

- (Object) CreateHdDiskPartitionsTab(user_data)



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
# File '../../src/include/partitioning/ep-hd.rb', line 413

def CreateHdDiskPartitionsTab(user_data)
  user_data = deep_copy(user_data)
  device = Convert.to_string(user_data)

  _Predicate = lambda do |disk, partition|
    disk = deep_copy(disk)
    partition = deep_copy(partition)
    StorageFields.PredicateDiskDevice(disk, partition, [device])
  end

  fields = StorageSettings.FilterTable(
    [
      :device,
      :udev_path,
      :udev_id,
      :size,
      :format,
      :encrypted,
      :type,
      :fs_type,
      :label,
      :mount_point,
      :mount_by,
      :start_cyl,
      :end_cyl,
      :used_by
    ]
  )

  target_map = Storage.GetTargetMap

  table_header = StorageFields.TableHeader(fields)
  table_contents = StorageFields.TableContents(
    fields,
    target_map,
    fun_ref(_Predicate, "symbol (map, map)")
  )

  expert_cmds = []

  expert_cmds = Builtins.add(
    expert_cmds,
    Item(
      Id(:create_partition_table),
      # menu entry text
      _("Create New Partition Table")
    )
  )

  expert_cmds = Builtins.add(
    expert_cmds,
    Item(
      Id(:clone_disk),
      # menu entry text
      _("Clone this Disk")
    )
  )

  if String.StartsWith(device, "/dev/dasd")
    expert_cmds = Builtins.add(
      expert_cmds,
      Item(
        Id(:dasdfmt),
        # menu entry text
        _("Execute dasd&fmt on the DASD Device")
      )
    )
  end

  UI.ReplaceWidget(
    :tab_panel,
    VBox(
      DiskBarGraph(device),
      Table(
        Id(:table),
        Opt(:keepSorting, :notify, :notifyContextMenu),
        table_header,
        table_contents
      ),
      HBox(
        ArrangeButtons(
          Builtins.flatten(
            [
              [PushButton(Id(:add), Opt(:key_F3), _("Add..."))], # push button text
              HdButtons(),
              [
                HStretch(),
                # menu button text
                MenuButton(Opt(:key_F7), _("Expert..."), expert_cmds)
              ]
            ]
          )
        )
      )
    )
  )

  # helptext
  helptext = _(
    "<p>This view shows all partitions of the selected\n" +
      "hard disk. If the hard disk is used by e.g. BIOS RAID or multipath, no\n" +
      "partitions are shown here.</p>\n"
  )

  Wizard.RestoreHelp(Ops.add(helptext, StorageFields.TableHelptext(fields)))

  nil
end

- (Object) CreateHdMainPanel(user_data)



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
# File '../../src/include/partitioning/ep-hd.rb', line 165

def CreateHdMainPanel(user_data)
  user_data = deep_copy(user_data)
  _Predicate = lambda do |disk, partition|
    disk = deep_copy(disk)
    partition = deep_copy(partition)
    StorageFields.PredicateDiskType(
      disk,
      partition,
      [:CT_DMRAID, :CT_DMMULTIPATH, :CT_MDPART, :CT_DISK]
    )
  end

  fields = StorageSettings.FilterTable(
    [
      :device,
      :udev_path,
      :udev_id,
      :size,
      :format,
      :encrypted,
      :type,
      :fs_type,
      :label,
      :mount_point,
      :mount_by,
      :start_cyl,
      :end_cyl,
      :used_by
    ]
  )

  target_map = Storage.GetTargetMap

  table_header = StorageFields.TableHeader(fields)
  table_contents = StorageFields.TableContents(
    fields,
    target_map,
    fun_ref(_Predicate, "symbol (map, map)")
  )

  UI.ReplaceWidget(
    :tree_panel,
    Greasemonkey.Transform(
      VBox(
        # heading
        term(:IconAndHeading, _("Hard Disks"), StorageIcons.hd_icon),
        Table(
          Id(:table),
          Opt(:keepSorting, :notify, :notifyContextMenu),
          table_header,
          table_contents
        ),
        ArrangeButtons(
          Builtins.flatten(
            [
              [PushButton(Id(:add), Opt(:key_F3), _("Add Partition..."))], # push button text
              HdButtons(),
              [HStretch()]
            ]
          )
        )
      )
    )
  )

  # helptext
  helptext = _(
    "<p>This view shows all hard disks including\niSCSI disks, BIOS RAIDs and multipath disks and their partitions.</p>\n"
  )

  Wizard.RestoreHelp(Ops.add(helptext, StorageFields.TableHelptext(fields)))

  nil
end

- (Object) CreateHdPartitionPanel(user_data)



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
# File '../../src/include/partitioning/ep-hd.rb', line 688

def CreateHdPartitionPanel(user_data)
  user_data = deep_copy(user_data)
  device = Convert.to_string(user_data)

  target_map = Storage.GetTargetMap

  fields = StorageSettings.FilterOverview(
    [
      :heading_device,
      :device,
      :size,
      :encrypted,
      :udev_path,
      :udev_id,
      :used_by,
      :fs_id,
      :heading_filesystem,
      :fs_type,
      :mount_point,
      :mount_by,
      :uuid,
      :label
    ]
  )

  UI.ReplaceWidget(
    :tree_panel,
    Greasemonkey.Transform(
      VBox(
        HStretch(),
        # heading
        term(
          :IconAndHeading,
          Builtins.sformat(_("Partition: %1"), device),
          StorageIcons.hd_part_icon
        ),
        StorageFields.Overview(fields, target_map, device),
        ArrangeButtons(Builtins.flatten([HdButtons(), [HStretch()]]))
      )
    )
  )

  # helptext
  helptext = _(
    "<p>This view shows detailed information about the\nselected partition.</p>"
  )

  Wizard.RestoreHelp(
    Ops.add(helptext, StorageFields.OverviewHelptext(fields))
  )

  nil
end

- (Object) DiskMaySupportHdparm(disk_device)



373
374
375
376
377
378
379
380
381
382
# File '../../src/include/partitioning/ep-hd.rb', line 373

def DiskMaySupportHdparm(disk_device)
  return false if String.StartsWith(disk_device, "/dev/dasd")

  target_map = Storage.GetTargetMap
  disk = Ops.get(target_map, disk_device, {})

  return false if Ops.get_symbol(disk, "type", :CT_UNKNOWN) != :CT_DISK

  true
end

- (Object) DiskMaySupportSmart(disk_device)



357
358
359
360
361
362
363
364
365
366
367
368
369
370
# File '../../src/include/partitioning/ep-hd.rb', line 357

def DiskMaySupportSmart(disk_device)
  return false if String.StartsWith(disk_device, "/dev/dasd")

  target_map = Storage.GetTargetMap
  disk = Ops.get(target_map, disk_device, {})

  return false if Ops.get_symbol(disk, "type", :CT_UNKNOWN) != :CT_DISK

  if Builtins.contains(["3w-9xxx"], Ops.get_string(disk, "driver", ""))
    return false
  end

  true
end

- (Object) EpContextMenuHdDisk(device)



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File '../../src/include/partitioning/ep-hd.rb', line 35

def EpContextMenuHdDisk(device)
  widget = ContextMenu.Simple(
    [
      Item(
        Id(:add),
        term(:icon, StorageIcons.hd_part_icon),
        _("Add Partition")
      ),
      Item(Id(:delete), _("Delete"))
    ]
  )

  case widget
    when :add
      EpCreatePartition(device)
    when :delete
      EpDeleteDisk(device)
  end

  nil
end

- (Object) EpContextMenuHdPartition(device)



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File '../../src/include/partitioning/ep-hd.rb', line 58

def EpContextMenuHdPartition(device)
  widget = ContextMenu.Simple(
    [
      Item(Id(:edit), _("Edit")),
      Item(Id(:move), _("Move")),
      Item(Id(:resize), _("Resize")),
      Item(Id(:delete), _("Delete"))
    ]
  )

  case widget
    when :edit
      EpEditPartition(device)
    when :move
      EpMovePartition(device)
    when :resize
      EpResizePartition(device)
    when :delete
      EpDeletePartition(device, :table)
  end

  nil
end

- (Object) HandleHdButtons(user_data, device, event)



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
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/partitioning/ep-hd.rb', line 97

def HandleHdButtons(user_data, device, event)
  user_data = deep_copy(user_data)
  event = deep_copy(event)
  disk_device = ""
  is_disk = false

  if user_data == nil
    disk = nil
    part = nil

    target_map = Storage.GetTargetMap
    disk_ref = arg_ref(disk)
    part_ref = arg_ref(part)
    SplitDevice(target_map, device, disk_ref, part_ref)
    disk = disk_ref.value
    part = part_ref.value
    disk_device = Ops.get_string(disk, "device", "")
    is_disk = part == nil
  else
    disk_device = Convert.to_string(user_data)
  end

  case Event.IsWidgetActivated(event)
    when :add
      EpCreatePartition(disk_device)
    when :edit
      if is_disk
        TreePanel.SwitchToNew(disk_device)
      else
        EpEditPartition(device)
      end
    when :move
      if is_disk
        # error popup
        Popup.Error(
          _(
            "Hard disks, BIOS RAIDs and multipath\ndevices cannot be moved."
          )
        )
      else
        EpMovePartition(device)
      end
    when :resize
      if is_disk
        # error popup
        Popup.Error(
          _(
            "Hard disks, BIOS RAIDs and multipath\ndevices cannot be resized."
          )
        )
      else
        EpResizePartition(device)
      end
    when :delete
      if is_disk
        EpDeleteDisk(disk_device)
      else
        EpDeletePartition(
          device,
          UI.WidgetExists(Id(:table)) ? :table : :overview
        )
      end
  end

  nil
end

- (Object) HandleHdDiskOverviewTab(user_data, event)



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
# File '../../src/include/partitioning/ep-hd.rb', line 385

def HandleHdDiskOverviewTab(user_data, event)
  user_data = deep_copy(user_data)
  event = deep_copy(event)
  disk_device = Convert.to_string(user_data)

  case Event.IsWidgetActivated(event)
    when :smart
      if !DiskMaySupportSmart(disk_device)
        Popup.Error(_("SMART is not available for this disk."))
      else
        DisplayCommandOutput(
          Builtins.sformat("/usr/sbin/smartctl --health '%1'", disk_device)
        )
      end
    when :hdparm
      if !DiskMaySupportHdparm(disk_device)
        Popup.Error(_("hdparm is not available for this disk."))
      else
        DisplayCommandOutput(
          Builtins.sformat("/sbin/hdparm -aAgr '%1'", disk_device)
        )
      end
  end

  nil
end

- (Object) HandleHdDiskPanel(user_data, event)



679
680
681
682
683
684
685
# File '../../src/include/partitioning/ep-hd.rb', line 679

def HandleHdDiskPanel(user_data, event)
  user_data = deep_copy(user_data)
  event = deep_copy(event)
  TabPanel.Handle(event)

  nil
end

- (Object) HandleHdDiskPartitionsTab(user_data, event)



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
# File '../../src/include/partitioning/ep-hd.rb', line 523

def HandleHdDiskPartitionsTab(user_data, event)
  user_data = deep_copy(user_data)
  event = deep_copy(event)
  disk_device = Convert.to_string(user_data)
  part_device = Convert.to_string(UI.QueryWidget(Id(:table), :CurrentItem))

  HandleHdButtons(disk_device, part_device, event)

  case Event.IsMenu(event)
    when :create_partition_table
      EpCreatePartitionTable(disk_device)
    when :clone_disk
      EpCloneDisk(disk_device)
    when :dasdfmt
      EpDasdfmtDisk(disk_device)
  end

  case Event.IsWidgetContextMenuActivated(event)
    when :table
      EpContextMenuDevice(part_device)
  end

  UI.SetFocus(Id(:table))

  nil
end

- (Object) HandleHdMainPanel(user_data, event)



241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File '../../src/include/partitioning/ep-hd.rb', line 241

def HandleHdMainPanel(user_data, event)
  user_data = deep_copy(user_data)
  event = deep_copy(event)
  device = Convert.to_string(UI.QueryWidget(Id(:table), :CurrentItem))

  HandleHdButtons(user_data, device, event)

  case Event.IsWidgetContextMenuActivated(event)
    when :table
      EpContextMenuDevice(device)
  end

  nil
end

- (Object) HandleHdPartitionPanel(user_data, event)



743
744
745
746
747
748
749
750
751
752
# File '../../src/include/partitioning/ep-hd.rb', line 743

def HandleHdPartitionPanel(user_data, event)
  user_data = deep_copy(user_data)
  event = deep_copy(event)
  part_device = Convert.to_string(user_data)

  HandleHdButtons(nil, part_device, event)
  UI.SetFocus(Id(:text))

  nil
end

- (Object) HdButtons



83
84
85
86
87
88
89
90
91
92
93
94
# File '../../src/include/partitioning/ep-hd.rb', line 83

def HdButtons
  [
    # push button text
    PushButton(Id(:edit), Opt(:key_F4), _("Edit...")),
    # push button text
    PushButton(Id(:move), Opt(:key_F7), _("Move...")),
    # push button text
    PushButton(Id(:resize), Opt(:key_F6), _("Resize...")),
    # push button text
    PushButton(Id(:delete), Opt(:key_F5), _("Delete..."))
  ]
end

- (Object) initialize_partitioning_ep_hd(include_target)



28
29
30
31
32
33
# File '../../src/include/partitioning/ep-hd.rb', line 28

def initialize_partitioning_ep_hd(include_target)
  textdomain "storage"

  Yast.include include_target, "partitioning/ep-hd-dialogs.rb"
  Yast.include include_target, "partitioning/ep-hd-lib.rb"
end