Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #37009 - Implement EFI for libvirt #9965

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion app/models/compute_resources/foreman/model/libvirt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ def self.available?
Fog::Compute.providers.include?(:libvirt)
end

def firmware_types
{
"automatic" => N_("Automatic"),
"bios" => N_("BIOS"),
"efi" => N_("EFI"),
}
end

# Some getters/setters for the attrs Hash
def display_type
attrs[:display].presence || 'vnc'
Expand Down Expand Up @@ -146,11 +154,28 @@ def new_vm(attr = { })
opts[collection] = nested_attributes_for(collection, nested_attrs) if nested_attrs
end

opts.reject! { |k, v| v.nil? }
opts.compact!

opts[:boot_order] = %w[hd]
opts[:boot_order].unshift 'network' unless attr[:image_id]

# Named firmware for consistency with VMware
opts[:os_firmware] = opts.delete(:firmware)

firmware_type = opts.delete(:firmware_type)
if opts[:os_firmware] == 'automatic'
# See PxeLoaderSupport.firmware_type for possible values
case firmware_type
when :uefi
# TODO opts[:os_loader] = 'secure' for secure boot
opts[:os_firmware] = 'efi'
when :bios
opts[:os_firmware] = 'bios'
else
opts.delete(:os_firmware)
end
end

vm = client.servers.new opts
vm.memory = opts[:memory] if opts[:memory]
vm
Expand Down Expand Up @@ -285,6 +310,7 @@ def client

def vm_instance_defaults
super.merge(
:firmware => 'automatic',
:memory => 2048.megabytes,
:nics => [new_nic],
:volumes => [new_volume].compact,
Expand Down
2 changes: 1 addition & 1 deletion app/models/compute_resources/foreman/model/vmware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ def parse_args(args)
firmware_type = args.delete(:firmware_type)
args[:firmware] = firmware_mapping(firmware_type) if args[:firmware] == 'automatic'

args.reject! { |k, v| v.nil? }
args.compact!
args
end

Expand Down
5 changes: 5 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 @@ -5,6 +5,11 @@
</div>
<%= select_f f, :cpu_mode, Foreman::Model::Libvirt::CPU_MODES, :to_s, :to_s, { }, :label => _("CPU mode"), :label_size => "col-md-2" %>
<%= byte_size_f(f, :memory, disabled: !new_vm, label: _('Memory'), recommended_max_value: compute_resource.max_memory.to_i) %>
<%= field(f, :firmware, :disabled => !new_vm, :label => _('Firmware'), :label_size => "col-md-2") do
compute_resource.firmware_types.collect do |type, name|
radio_button_f f, :firmware, {:disabled => !new_vm, :value => type, :text => _(name)}
Comment on lines +8 to +10
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be:

Suggested change
<%= field(f, :firmware, :disabled => !new_vm, :label => _('Firmware'), :label_size => "col-md-2") do
compute_resource.firmware_types.collect do |type, name|
radio_button_f f, :firmware, {:disabled => !new_vm, :value => type, :text => _(name)}
<%= field(f, :os_firmware, :disabled => !new_vm, :label => _('Firmware'), :label_size => "col-md-2") do
compute_resource.firmware_types.collect do |type, name|
radio_button_f f, :os_firmware, {:disabled => !new_vm, :value => type, :text => _(name)}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the controller accepts firmware (just like the VMware side). The libvirt model then converts the option to what fog-libvirt accepts.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to consider VMware here? I don't see the necessity for VMware and Libvirt forms to have the same naming convention.
If we keep it as it is, we encounter the following error: Failure: undefined method firmware for <Fog::Libvirt::Compute::Server ...

end.join(' ').html_safe
end %>
<!--TODO # Move to a helper-->
<% checked = params[:host] && params[:host][:compute_attributes] && params[:host][:compute_attributes][:start] || '1' %>
<%= checkbox_f f, :start, { :checked => (checked == '1'), :help_inline => _("Power ON this machine"), :label => _('Start'), :label_size => "col-md-2"} if new_vm && controller_name != "compute_attributes" %>
Expand Down
2 changes: 1 addition & 1 deletion bundler.d/libvirt.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
group :libvirt do
gem 'fog-libvirt', '>= 0.9.0'
gem 'fog-libvirt', github: 'ekohl/fog-libvirt', branch: 'implement-efi'
gem 'ruby-libvirt', '~> 0.5', :require => 'libvirt'
end
Loading