From 4de65fc5e62d7fdaf3c6d6bf6dcfc0bc9475add0 Mon Sep 17 00:00:00 2001 From: nofaralfasi Date: Wed, 17 Jul 2024 19:40:03 +0300 Subject: [PATCH] Optimize secure boot support and firmware handling --- lib/fog/vsphere/compute.rb | 2 ++ lib/fog/vsphere/requests/compute/create_vm.rb | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/fog/vsphere/compute.rb b/lib/fog/vsphere/compute.rb index d0fd3bb..175f85a 100644 --- a/lib/fog/vsphere/compute.rb +++ b/lib/fog/vsphere/compute.rb @@ -156,6 +156,7 @@ module Shared parent: 'parent', hostname: 'summary.guest.hostName', operatingsystem: 'summary.guest.guestFullName', + virtual_tpm: 'summary.config.tpmPresent', ipaddress: 'guest.ipAddress', power_state: 'runtime.powerState', connection_state: 'runtime.connectionState', @@ -173,6 +174,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' diff --git a/lib/fog/vsphere/requests/compute/create_vm.rb b/lib/fog/vsphere/requests/compute/create_vm.rb index 1198b3a..f25c9fa 100644 --- a/lib/fog/vsphere/requests/compute/create_vm.rb +++ b/lib/fog/vsphere/requests/compute/create_vm.rb @@ -1,6 +1,7 @@ module Fog module Vsphere class Compute + # rubocop:disable Metrics/ClassLength class Real def create_vm(attributes = {}) # build up vm configuration @@ -22,7 +23,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 @@ -173,9 +174,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 @@ -353,6 +352,7 @@ def extra_config(attributes) end end + # rubocop:enable Metrics/ClassLength class Mock def create_vm(attributes = {}) id = SecureRandom.uuid