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

Secure Boot & Virtual TPM #305

Merged
merged 2 commits into from
Jul 29, 2024
Merged
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
2 changes: 2 additions & 0 deletions lib/fog/vsphere/compute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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'
Expand Down
2 changes: 2 additions & 0 deletions lib/fog/vsphere/models/compute/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 15 additions & 1 deletion lib/fog/vsphere/requests/compute/create_vm.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module Fog
module Vsphere
class Compute
# rubocop:disable Metrics/ClassLength
class Real
def create_vm(attributes = {})
# build up vm configuration
Expand All @@ -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)
chris1984 marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down
Loading