From 35e8aaa830fc1f8a791821a4bf7330c02f9a3d6c Mon Sep 17 00:00:00 2001 From: Leos Stejskal Date: Mon, 17 Jun 2024 15:26:55 +0200 Subject: [PATCH] Fixes #37566 - Libvirt - UEFI & SecureBoot support Co-authored-by: Ewoud Kohl van Wijngaarden --- app/helpers/compute_resources_helper.rb | 13 +++++++ .../foreman/model/libvirt.rb | 36 +++++++++++++++++-- .../form/libvirt/_base.html.erb | 4 +++ 3 files changed, 51 insertions(+), 2 deletions(-) diff --git a/app/helpers/compute_resources_helper.rb b/app/helpers/compute_resources_helper.rb index 66e05db1bc4..a4d31a976f5 100644 --- a/app/helpers/compute_resources_helper.rb +++ b/app/helpers/compute_resources_helper.rb @@ -116,4 +116,17 @@ def http_proxy_field(f) { :label => _("HTTP Proxy") } ) end + + def os_firmware_field(f) + types = Foreman::Model::Libvirt.firmware_types + select_f(f, :os_firmware, types, :first, :last, {}, { :label => _("Firmware"), :label_size => "col-md-2" }) + end + + def os_loader_attrs_fields(f) + attrs = f.object.os_loader_attrs + + f.fields_for :os_loader_attrs do |lf| + checkbox_f(lf, :secure, { checked: attrs[:secure] == 'yes', label: _("Secure Boot") }, 'yes', 'no') + end + end end diff --git a/app/models/compute_resources/foreman/model/libvirt.rb b/app/models/compute_resources/foreman/model/libvirt.rb index ee2cbc38fec..812e78b9745 100644 --- a/app/models/compute_resources/foreman/model/libvirt.rb +++ b/app/models/compute_resources/foreman/model/libvirt.rb @@ -14,7 +14,35 @@ 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 self.os_loader_defaults + { + secure: "no", + }.freeze + end + + def os_firmware + attrs[:os_firmware].presence || "efi" + end + + def os_firmware=(firmware) + attrs[:os_firmware] = firmware + end + + def os_loader_attrs + attrs[:os_loader_attrs].presence || os_loader_defaults + end + + def os_loader_attrs=(attrs) + attrs[:os_loader_attrs].merge!(attrs) + end + def display_type attrs[:display].presence || 'vnc' end @@ -291,7 +319,11 @@ 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_loader_attrs => { + secure: "no", + } ) end diff --git a/app/views/compute_resources_vms/form/libvirt/_base.html.erb b/app/views/compute_resources_vms/form/libvirt/_base.html.erb index d6378df16b1..2171ff533df 100644 --- a/app/views/compute_resources_vms/form/libvirt/_base.html.erb +++ b/app/views/compute_resources_vms/form/libvirt/_base.html.erb @@ -24,3 +24,7 @@ <%= compute_specific_js(compute_resource, "nic_info") %> + +<%= os_firmware_field(f) %> +<%= os_loader_attrs_fields(f) %> +