From 61ee3a44f5365032549e684f23cc10ab7daff1e3 Mon Sep 17 00:00:00 2001 From: Ali Rizvi-Santiago Date: Wed, 21 Nov 2018 00:43:14 -0600 Subject: [PATCH] Modified the cpus and memory options for the vmware builders to only apply them if they were specified. --- builder/vmware/common/hw_config.go | 6 ------ builder/vmware/common/hw_config_test.go | 2 +- builder/vmware/iso/step_create_vmx.go | 19 +++++++++++++++---- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/builder/vmware/common/hw_config.go b/builder/vmware/common/hw_config.go index 7f6b65034..fa092402b 100644 --- a/builder/vmware/common/hw_config.go +++ b/builder/vmware/common/hw_config.go @@ -36,17 +36,11 @@ func (c *HWConfig) Prepare(ctx *interpolate.Context) []error { errs = append(errs, fmt.Errorf("An invalid number of cpus was specified (cpus < 0): %d", c.CpuCount)) c.CpuCount = 0 } - if c.CpuCount == 0 { - c.CpuCount = 1 - } if c.MemorySize < 0 { errs = append(errs, fmt.Errorf("An invalid amount of memory was specified (memory < 0): %d", c.MemorySize)) c.MemorySize = 0 } - if c.MemorySize == 0 { - c.MemorySize = 512 - } // Peripherals if !c.Sound { diff --git a/builder/vmware/common/hw_config_test.go b/builder/vmware/common/hw_config_test.go index ce1f23277..be884b144 100644 --- a/builder/vmware/common/hw_config_test.go +++ b/builder/vmware/common/hw_config_test.go @@ -22,7 +22,7 @@ func TestHWConfigPrepare(t *testing.T) { t.Fatalf("err: %#v", errs) } - if c.CpuCount < 1 { + if c.CpuCount < 0 { t.Errorf("bad cpu count: %d", c.CpuCount) } diff --git a/builder/vmware/iso/step_create_vmx.go b/builder/vmware/iso/step_create_vmx.go index dba6746a7..5aca4485f 100644 --- a/builder/vmware/iso/step_create_vmx.go +++ b/builder/vmware/iso/step_create_vmx.go @@ -160,9 +160,6 @@ func (s *stepCreateVMX) Run(_ context.Context, state multistep.StateBag) multist Version: config.Version, ISOPath: isoPath, - CpuCount: strconv.Itoa(config.HWConfig.CpuCount), - MemorySize: strconv.Itoa(config.HWConfig.MemorySize), - SCSI_Present: "FALSE", SCSI_diskAdapterType: "lsilogic", SATA_Present: "FALSE", @@ -413,8 +410,22 @@ func (s *stepCreateVMX) Run(_ context.Context, state multistep.StateBag) multist s.tempDir = vmxDir } + /// Now to handle options that will modify the template + vmxData := vmwcommon.ParseVMX(vmxContents) + + // Set the number of cpus if it was specified + if config.HWConfig.CpuCount > 0 { + vmxData["numvcpus"] = strconv.Itoa(config.HWConfig.CpuCount) + } + + // Apply the memory size that was specified + if config.HWConfig.MemorySize > 0 { + vmxData["memsize"] = strconv.Itoa(config.HWConfig.MemorySize) + } + + /// Write the vmxData to the vmxPath vmxPath := filepath.Join(vmxDir, config.VMName+".vmx") - if err := vmwcommon.WriteVMX(vmxPath, vmwcommon.ParseVMX(vmxContents)); err != nil { + if err := vmwcommon.WriteVMX(vmxPath, vmxData); err != nil { err := fmt.Errorf("Error creating VMX file: %s", err) state.Put("error", err) ui.Error(err.Error())