Skip to content

Commit

Permalink
Optimize secure boot support and firmware handling
Browse files Browse the repository at this point in the history
  • Loading branch information
nofaralfasi committed Jul 21, 2024
1 parent 97a27f0 commit 66d312b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 6 additions & 0 deletions lib/fog/vsphere/compute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ module Shared
cpuHotAddEnabled: 'config.cpuHotAddEnabled',
memoryHotAddEnabled: 'config.memoryHotAddEnabled',
firmware: 'config.firmware',
secure_boot: 'config.bootOptions.efiSecureBootEnabled',
boot_order: 'config.bootOptions.bootOrder',
annotation: 'config.annotation',
extra_config: 'config.extraConfig'
Expand Down Expand Up @@ -208,6 +209,11 @@ def props_to_attr_hash(vm_mob_ref, props)
# finished cloning.
attrs['boot_order'] = parse_boot_order(attrs['boot_order'])

# Foreman expects the firmware to be 'uefi_sb' if SB is enabled
if attrs['secure_boot'] && attrs['firmware'] == 'efi'
attrs['firmware'] = 'uefi_sb'
end

Check failure on line 216 in lib/fog/vsphere/compute.rb

View workflow job for this annotation

GitHub Actions / rubocop

Style/IfUnlessModifier: Favor modifier `if` usage when having a single-line body. Another good alternative is the usage of control flow `&&`/`||`.
if attrs['hypervisor'].is_a?(RbVmomi::VIM::HostSystem)
host = attrs['hypervisor']

Expand Down
8 changes: 3 additions & 5 deletions lib/fog/vsphere/requests/compute/create_vm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def create_vm(attributes = {})
vm_cfg[:cpuHotAddEnabled] = attributes[:cpuHotAddEnabled] if attributes.key?(:cpuHotAddEnabled)
vm_cfg[:memoryHotAddEnabled] = attributes[:memoryHotAddEnabled] if attributes.key?(:memoryHotAddEnabled)
vm_cfg[:firmware] = attributes[:firmware] if attributes.key?(:firmware)
vm_cfg[:bootOptions] = boot_options(attributes, vm_cfg) if attributes.key?(:boot_order) || attributes.key?(:boot_retry)
vm_cfg[:bootOptions] = boot_options(attributes, vm_cfg)
resource_pool = if attributes[:resource_pool] && attributes[:resource_pool] != 'Resources'
get_raw_resource_pool(attributes[:resource_pool], attributes[:cluster], attributes[:datacenter])
else
Expand Down Expand Up @@ -150,7 +150,7 @@ def device_change(attributes)
devices << cdroms.map { |cdrom| create_cdrom(cdrom, cdroms.index(cdrom)) }
end

devices << create_virtual_tpm if attributes[:virtual_tpm]
devices << create_virtual_tpm if ActiveRecord::Type::Boolean.new.cast(attributes[:virtual_tpm])

devices.flatten
end
Expand All @@ -169,9 +169,7 @@ def boot_options(attributes, vm_cfg)
options[:bootRetryDelay] = attributes[:boot_retry]
end

if attributes[:secure_boot]
options[:efiSecureBootEnabled] = true
end
options[:efiSecureBootEnabled] = attributes[:secure_boot] if attributes.key?(:secure_boot)

options.empty? ? nil : RbVmomi::VIM::VirtualMachineBootOptions.new(options)
end
Expand Down

0 comments on commit 66d312b

Please sign in to comment.