Skip to content

Commit

Permalink
Fixes #37566 - Libvirt - UEFI & SecureBoot support
Browse files Browse the repository at this point in the history
Co-authored-by: Ewoud Kohl van Wijngaarden <ewoud@kohlvanwijngaarden.nl>
  • Loading branch information
stejskalleos and ekohl committed Jun 24, 2024
1 parent 49d4405 commit 7f55085
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
31 changes: 29 additions & 2 deletions app/models/compute_resources/foreman/model/libvirt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,29 @@ def self.available?
Fog::Compute.providers.include?(:libvirt)
end

# Some getters/setters for the attrs Hash
def self.firmware_types
{
"efi" => N_("EFI"),
"bios" => N_("BIOS"),
}.freeze
end

def os_firmware
attrs[:os_firmware].presence || "efi"
end

def os_firmware=(firmware)
attrs[:os_firmware] = firmware
end

def os_firmware_features
attrs[:os_firmware_features].presence || {}
end

def os_firmware_features=(attrs)
attrs[:os_firmware_features].merge attrs
end

def display_type
attrs[:display].presence || 'vnc'
end
Expand Down Expand Up @@ -291,7 +313,12 @@ def vm_instance_defaults
:display => { :type => display_type,
:listen => Setting[:libvirt_default_console_address],
:password => random_password(console_password_length(display_type)),
:port => '-1' }
:port => '-1' },
:os_firmware => 'efi',
:os_firmware_features => {
"secure-boot" => "no",
"enrolled-keys" => "no",
}
)
end

Expand Down
24 changes: 24 additions & 0 deletions app/views/compute_resources_vms/form/libvirt/_base.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,27 @@
</div>

<%= compute_specific_js(compute_resource, "nic_info") %>
<%= select_f f, :os_firmware,
Foreman::Model::Libvirt.firmware_types,
:first,
:last,
{},
{ :label => _("Firmware"),
:label_size => "col-md-2",
:onchange => "tfm.computeResource.libvirt.firmwareSelected(this);",
}
%>
<%
feature_attrs = ActiveSupport::HashWithIndifferentAccess.new(f.object.os_firmware_features)
is_bios = f.object.os_firmware == 'bios'
%>

<div id="os_firmware_features">
<%= f.fields_for :os_firmware_features do |ff|
secure_field = checkbox_f(ff, 'secure-boot', { checked: feature_attrs['secure-boot'] == 'yes', label: _("Secure Boot"), disabled: is_bios }, 'yes', 'no')
keys_field = checkbox_f(ff, 'enrolled-keys', { checked: feature_attrs['enrolled-keys'] == 'yes', label: _("Enrolled keys"), disabled: is_bios }, 'yes', 'no')
secure_field + keys_field
end
%>
</div>
7 changes: 7 additions & 0 deletions webpack/assets/javascripts/compute_resource/libvirt.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,10 @@ export function allocationSwitcher(element, action) {
$(element).button('toggle');
return false;
}

export function firmwareSelected(item) {
const selected = $(item).val();
const inputs = $("#os_firmware_features input[type='checkbox']");

inputs.attr('disabled', selected === 'bios');
}

0 comments on commit 7f55085

Please sign in to comment.