Skip to content

Commit

Permalink
Fixes #37566 - Libvirt - UEFI & SecureBoot support
Browse files Browse the repository at this point in the history
  • Loading branch information
stejskalleos committed Jun 17, 2024
1 parent cab3f08 commit 4754942
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
13 changes: 13 additions & 0 deletions app/helpers/compute_resources_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
36 changes: 34 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,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
Expand Down Expand Up @@ -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

Expand Down
4 changes: 4 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,7 @@
</div>

<%= compute_specific_js(compute_resource, "nic_info") %>
<%= os_firmware_field(f) %>
<%= os_loader_attrs_fields(f) %>

0 comments on commit 4754942

Please sign in to comment.