Added options for nested virtualisation and RTC time base.

This commit is contained in:
Thomas Dreibholz 2021-03-08 09:58:17 +01:00
parent f4caf5978f
commit 4c9f3eb9ca
2 changed files with 30 additions and 1 deletions

View File

@ -52,6 +52,14 @@ type Config struct {
// When set to bios, the firmare is BIOS. This is the default.
// When set to efi, the firmare is EFI.
Firmware string `mapstructure:"firmware" required:"false"`
// Nested virtualization: false or true.
// When set to true, nested virtualisation (VT-x/AMD-V) is enabled.
// When set to false, nested virtualisation is disabled. This is the default.
NestedVirt bool `mapstructure:"nested_virt" required:"false"`
// RTC time base: UTC or local.
// When set to true, the RTC is set as UTC time.
// When set to false, the RTC is set as local time. This is the default.
RTCTimeBase string `mapstructure:"rtc_time_base" required:"false"`
// The size, in megabytes, of the hard disk to create for the VM. By
// default, this is 40000 (about 40 GB).
DiskSize uint `mapstructure:"disk_size" required:"false"`
@ -212,6 +220,17 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
errs, errors.New("firmware can only be bios or efi"))
}
if b.config.RTCTimeBase == "" {
b.config.RTCTimeBase = "local"
}
switch b.config.RTCTimeBase {
case "UTC", "local":
// do nothing
default:
errs = packersdk.MultiErrorAppend(
errs, errors.New("rtc_time_base can only be UTC or local"))
}
if b.config.DiskSize == 0 {
b.config.DiskSize = 40000
}

View File

@ -26,7 +26,7 @@ func (s *stepCreateVM) Run(ctx context.Context, state multistep.StateBag) multis
name := config.VMName
commands := make([][]string, 10)
commands := make([][]string, 12)
commands[0] = []string{
"createvm", "--name", name,
"--ostype", config.GuestOSType, "--register",
@ -60,6 +60,16 @@ func (s *stepCreateVM) Run(ctx context.Context, state multistep.StateBag) multis
"--nictype7", config.NICType,
"--nictype8", config.NICType}
commands[9] = []string{"modifyvm", name, "--graphicscontroller", config.GfxController}
if config.RTCTimeBase == "UTC" {
commands[10] = []string{"modifyvm", name, "--rtcuseutc", "on"}
} else {
commands[10] = []string{"modifyvm", name, "--rtcuseutc", "off"}
}
if config.NestedVirt == true {
commands[11] = []string{"modifyvm", name, "--nested-hw-virt", "on"}
} else {
commands[11] = []string{"modifyvm", name, "--nested-hw-virt", "off"}
}
ui.Say("Creating virtual machine...")
for _, command := range commands {