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/models/compute/server.rb b/lib/fog/vsphere/models/compute/server.rb index acbefcb..83aba3b 100644 --- a/lib/fog/vsphere/models/compute/server.rb +++ b/lib/fog/vsphere/models/compute/server.rb @@ -53,6 +53,8 @@ class Server < Fog::Compute::Server # rubocop:disable Metrics/ClassLength attribute :cpuHotAddEnabled attribute :memoryHotAddEnabled attribute :firmware + attribute :secure_boot + attribute :virtual_tpm attribute :boot_order attribute :annotation attribute :extra_config diff --git a/lib/fog/vsphere/requests/compute/create_vm.rb b/lib/fog/vsphere/requests/compute/create_vm.rb index 4e9b585..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 @@ -153,6 +154,9 @@ def device_change(attributes) if (cdroms = attributes[:cdroms]) devices << cdroms.map { |cdrom| create_cdrom(cdrom, cdroms.index(cdrom)) } end + + devices << create_virtual_tpm if attributes[:virtual_tpm] + devices.flatten end @@ -170,6 +174,8 @@ def boot_options(attributes, vm_cfg) options[:bootRetryDelay] = attributes[:boot_retry] end + options[:efiSecureBootEnabled] = attributes[:secure_boot] if attributes.key?(:secure_boot) + options.empty? ? nil : RbVmomi::VIM::VirtualMachineBootOptions.new(options) end @@ -333,12 +339,20 @@ def create_cdrom(cdrom, index = 0, operation = :add, controller_key = 200) } end + def create_virtual_tpm + { + operation: :add, + device: RbVmomi::VIM::VirtualTPM.new(key: -1) + } + end + def extra_config(attributes) extra_config = attributes[:extra_config] || { 'bios.bootOrder' => 'ethernet0' } extra_config.map { |k, v| { key: k, value: v.to_s } } end end + # rubocop:enable Metrics/ClassLength class Mock def create_vm(attributes = {}) id = SecureRandom.uuid