Skip to content

Commit 436e320

Browse files
committed
WIP
1 parent b26778f commit 436e320

File tree

1 file changed

+20
-23
lines changed

1 file changed

+20
-23
lines changed

app/views/servers/prepare_bootstrap.html.erb

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,31 +31,30 @@
3131
)
3232
%>
3333

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+
%>
3548
<%=
3649
f.select(
3750
: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,
4852
{
4953
prompt: "Select a disk to bootstrap",
5054
# 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),
5958
},
6059
onchange: "
6160
if(!this.value || parseInt(this.selectedOptions[0].innerText.split('[')[1][0]) == 0)
@@ -72,10 +71,8 @@
7271
<strong>Warning:</strong> Existing partitions on the selected disk will be wiped.
7372
</p>
7473

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>
7976

8077
<%= f.submit "Bootstrap!" %>
8178
<% end %>

0 commit comments

Comments
 (0)