Skip to content

Commit c18d340

Browse files
committed
Cloud servers don't have disks with WWIDs
1 parent 44c97fb commit c18d340

File tree

2 files changed

+54
-41
lines changed

2 files changed

+54
-41
lines changed

app/controllers/servers_controller.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,15 @@ def bootstrap
3939

4040
talos_version = params.expect(:talos_version)
4141
talos_image_factory_schematic_id = params[:talos_image_factory_schematic_id]
42-
bootstrap_disk_wwid = params.expect(:bootstrap_disk_wwid)
43-
bootstrap_disk_name = server.lsblk.fetch("blockdevices").find { it.fetch("wwn") == bootstrap_disk_wwid }.fetch("name")
42+
43+
if server.is_a?(Server::HetznerDedicated)
44+
bootstrap_disk_wwid = params.expect(:bootstrap_disk_wwid)
45+
bootstrap_disk_name = server.lsblk.fetch("blockdevices").find { it.fetch("wwn") == bootstrap_disk_wwid }.fetch("name")
46+
elsif server.is_a?(Server::HetznerCloud)
47+
# Cloud servers only have one disk so we don't need to select one
48+
bootstrap_disk_wwid = nil
49+
bootstrap_disk_name = server.lsblk.fetch("blockdevices").find { it.fetch("type") == "disk" }.fetch("name")
50+
end
4451

4552
# pretend it's not accessible while bootstrapping to hide bootstrap button
4653
server.update!(

app/views/servers/prepare_bootstrap.html.erb

Lines changed: 45 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -31,48 +31,54 @@
3131
)
3232
%>
3333

34-
<% disks = @server.lsblk.fetch("blockdevices").select { |disk| disk.fetch("type") == "disk" } %>
35-
<%
36-
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")
34+
<% if @server.is_a?(Server::HetznerDedicated) %>
35+
<% disks = @server.lsblk.fetch("blockdevices").select { |disk| disk.fetch("type") == "disk" } %>
36+
<%
37+
disk_options = disks
38+
.map do |disk|
39+
partitions = disk.fetch("children", []).select { it.fetch("type").start_with?("part") }
40+
raid = disk.fetch("children", []).find { it.fetch("type").start_with?("raid") }&.fetch("name")
41+
suffix = raid ? "[RAID /dev/#{raid}]" : "[#{partitions.length} existing partition#{'s' if partitions.length != 1}]"
42+
label = "/dev/#{disk['name']} (#{number_to_human_size(disk['size'])}) #{suffix}"
43+
value = disk.fetch("wwn")
4344

44-
[label, value]
45-
end
46-
.sort_by(&:first)
47-
%>
48-
<%=
49-
f.select(
50-
:bootstrap_disk_wwid,
51-
disk_options,
52-
{
53-
prompt: "Select a disk to bootstrap",
54-
# the first non raided disk should be selected by default
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),
58-
},
59-
onchange: "
60-
if(!this.value || parseInt(this.selectedOptions[0].innerText.split('[')[1][0]) == 0)
61-
document.getElementById('bootstrap-warning').classList.add('hidden')
62-
else
63-
document.getElementById('bootstrap-warning').classList.remove('hidden')
64-
",
65-
required: true,
66-
label: "Bootstrap disk",
67-
)
68-
%>
45+
[label, value]
46+
end
47+
.sort_by(&:first)
48+
%>
49+
<%=
50+
f.select(
51+
:bootstrap_disk_wwid,
52+
disk_options,
53+
{
54+
prompt: "Select a disk to bootstrap",
55+
# the first non raided disk should be selected by default
56+
selected: disk_options.find { |label, _| label.exclude?("RAID") }&.last,
57+
# raided disks should be disabled
58+
disabled: disk_options.select { |label, _| label.include?("RAID") }.map(&:last),
59+
},
60+
onchange: "
61+
if(!this.value || parseInt(this.selectedOptions[0].innerText.split('[')[1][0]) == 0)
62+
document.getElementById('bootstrap-warning').classList.add('hidden')
63+
else
64+
document.getElementById('bootstrap-warning').classList.remove('hidden')
65+
",
66+
required: true,
67+
label: "Bootstrap disk",
68+
)
69+
%>
6970

70-
<p id="bootstrap-warning" class="bg-yellow-100 text-yellow-800 p-4 rounded mb-4 hidden border border-yellow-200">
71-
<strong>Warning:</strong> Existing partitions on the selected disk will be wiped.
72-
</p>
71+
<p id="bootstrap-warning" class="bg-yellow-100 text-yellow-800 p-4 rounded mb-4 hidden border border-yellow-200">
72+
<strong>Warning:</strong> Existing partitions on the selected disk will be wiped.
73+
</p>
7374

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>
75+
<%# Trigger change event to show/hide the warning based on the initially selected disk %>
76+
<script>document.getElementById("bootstrap_disk_wwid").dispatchEvent(new Event("change"))</script>
77+
<% else %>
78+
<p class="bg-blue-100 text-blue-800 p-4 rounded mb-4 border border-blue-200">
79+
<strong>Note:</strong> Talos will be installed to /dev/sda. Any existing partitions will be wiped.
80+
</p>
81+
<% end %>
7682

7783
<%= f.submit "Bootstrap!" %>
7884
<% end %>

0 commit comments

Comments
 (0)