|
31 | 31 | ) |
32 | 32 | %> |
33 | 33 |
|
34 | | - <% disks = @server.lsblk.fetch("blockdevices").select { |disk| disk['type'] == "disk" } %> |
| 34 | + <% disks = @server.lsblk.fetch("blockdevices").select { |disk| disk.fetch("type") == "disk" } %> |
| 35 | + <% |
| 36 | + bootstrap_disk_options = disks |
| 37 | + .map do |disk| |
| 38 | + partitions = disk.fetch("children", []).select { it.fetch("type").start_with?("part") } |
| 39 | + raid = disk.fetch("children", []).find { it.fetch("type").start_with?("raid") }&.fetch("name") |
| 40 | + suffix = raid ? "[RAID /dev/#{raid}]" : "[#{partitions.length} existing partition#{'s' if partitions.length != 1}]" |
| 41 | + label = "/dev/#{disk['name']} (#{number_to_human_size(disk['size'])}) #{suffix}" |
| 42 | + value = disk.fetch("wwn") |
| 43 | + |
| 44 | + [label, value] |
| 45 | + end |
| 46 | + .sort_by(&:first) |
| 47 | + %> |
35 | 48 | <%= |
36 | 49 | f.select( |
37 | 50 | :bootstrap_disk_wwid, |
38 | | - disks |
39 | | - .filter_map do |disk| |
40 | | - partitions = disk.fetch("children", []).select { |it| it.fetch("type").start_with?("part") } |
41 | | - partitions_suffix = "[#{partitions.length} existing partition#{'s' if partitions.length != 1}]" |
42 | | - label = "/dev/#{disk['name']} (#{number_to_human_size(disk['size'])}) #{partitions_suffix}" |
43 | | - value = disk.fetch("wwn") |
44 | | - |
45 | | - [label, value] |
46 | | - end |
47 | | - .sort_by(&:first), |
| 51 | + bootstrap_disk_options, |
48 | 52 | { |
49 | 53 | prompt: "Select a disk to bootstrap", |
50 | 54 | # the first non raided disk should be selected by default |
51 | | - selected: disks |
52 | | - .reject { |disk| disk.fetch("children", []).any? { it.fetch("type").start_with?("raid") } } |
53 | | - .first&.fetch("wwn"), |
54 | | - disabled: disks |
55 | | - .select do |disk| |
56 | | - disk.fetch("children", []).any? { it.fetch("type").start_with?("raid") } |
57 | | - end |
58 | | - .map { it.fetch("wwn") }, |
| 55 | + selected: disk_options.find { |label, _| label.exclude?("RAID") }&.last, |
| 56 | + # raided disks should be disabled |
| 57 | + disabled: disk_options.select { |label, _| label.include?("RAID") }.map(&:last), |
59 | 58 | }, |
60 | 59 | onchange: " |
61 | 60 | if(!this.value || parseInt(this.selectedOptions[0].innerText.split('[')[1][0]) == 0) |
|
72 | 71 | <strong>Warning:</strong> Existing partitions on the selected disk will be wiped. |
73 | 72 | </p> |
74 | 73 |
|
75 | | - <script> |
76 | | - // Trigger change event to show/hide the warning based on the initially selected disk |
77 | | - document.getElementById("bootstrap_disk_wwid").dispatchEvent(new Event("change")) |
78 | | - </script> |
| 74 | + <%# Trigger change event to show/hide the warning based on the initially selected disk %> |
| 75 | + <script>document.getElementById("bootstrap_disk_wwid").dispatchEvent(new Event("change"))</script> |
79 | 76 |
|
80 | 77 | <%= f.submit "Bootstrap!" %> |
81 | 78 | <% end %> |
|
0 commit comments