class PackerFiles::Virtual::KVM
Abstraction for KVM(QEMU) builder in Packer. Refer to Packer.io documentation on more details on the various variables for QEMU ISO Builder
.
Public Class Methods
new() { |self| ... }
click to toggle source
Constructor. Supports the standard block semantics via yield
# File lib/PackerFiles/Virtual/KVM.rb, line 55 def initialize(&block) self.type = 'qemu' yield self if block_given? end
Public Instance Methods
Hypervisor(hyper, amd64=true)
click to toggle source
Given an Hypervisor
object, convert into a list of qemuargs commands
# File lib/PackerFiles/Virtual/KVM.rb, line 61 def Hypervisor(hyper, amd64=true) # Allocate a new array to store values. value = Array.new # If CPU hot plug is enabled, then current cpu count < max cpu count count = hyper.cpu_count.to_s if (hyper.cpu_hot_plug) value << ["-smp", "cpus=#{count},maxcpus=255"] else value << ["-smp", "cpus=#{count},maxcpus=#{count}"] end # NOTE: CPU Execution Cap is not implemented in KVM # NOTE: Video RAM Size is not implemented in KVM # RAM Size is always translated into MiB value << ["-m", MiB(hyper.ram_size).to_s] # Memory Balloon size is ignored by KVM. It is just enabling or # disabling a feature. if MiB(hyper.guest_balloon_size) > 0 value << ["-balloon", "none"] else value << ["-balloon", "virtio"] end # ACPI is by default enabled on KVM. We just have to handle the # disabled case. if !hyper.acpi_enabled value << ["-no-acpi"] end # We have to use EFI firmware for virtual machines, if it has been # asked for. if hyper.use_efi value << ["-bios", "/usr/share/ovmf/OVMF.fd"] end # KVM works very differently w.r.t. CPU features. First a base CPU # (64 bit or 32 bit) has to be selected and then more features need # to be added. cpu_features = (amd64)?'qemu64':'qemu32' cpu_features += ',+pae' if hyper.pae_enabled cpu_features += ',+vmx' if hyper.hw_virt_enabled cpu_features += ',+npt' if hyper.hw_nested_pages cpu_features += ',+pse36' if hyper.use_large_pages cpu_features += ',+hypervisor' if hyper.unrestricted_guest_mode value << ["-cpu", cpu_features] # Set the value for QEMU Args self.qemuargs = value end