From 89fb8f0d3ea8e3400544328bb18a0cbf9bb7a52f Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Tue, 27 Nov 2018 15:43:48 -0800 Subject: [PATCH 1/2] fix defaulting/lack thereof for cpu count and memory in vmware template --- builder/vmware/iso/step_create_vmx.go | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/builder/vmware/iso/step_create_vmx.go b/builder/vmware/iso/step_create_vmx.go index 5aca4485f..4fa5254f8 100644 --- a/builder/vmware/iso/step_create_vmx.go +++ b/builder/vmware/iso/step_create_vmx.go @@ -315,6 +315,18 @@ func (s *stepCreateVMX) Run(_ context.Context, state multistep.StateBag) multist templateData.Serial_Host = "" templateData.Serial_Auto = "FALSE" + // Set the number of cpus if it was specified + if config.HWConfig.CpuCount > 0 { + templateData.CpuCount = strconv.Itoa(config.HWConfig.CpuCount) + } + + // Apply the memory size that was specified + if config.HWConfig.MemorySize > 0 { + templateData.MemorySize = strconv.Itoa(config.HWConfig.MemorySize) + } else { + templateData.MemorySize = "512" + } + switch serial.Union.(type) { case *vmwcommon.SerialConfigPipe: templateData.Serial_Type = "pipe" @@ -412,15 +424,8 @@ func (s *stepCreateVMX) Run(_ context.Context, state multistep.StateBag) multist /// 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) + if vmxData["numvcpus"] == "" { + delete(vmxData, "numvcpus") } /// Write the vmxData to the vmxPath From ec75913412f441386b4113b048bce3263bbdf055 Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Tue, 27 Nov 2018 16:34:26 -0800 Subject: [PATCH 2/2] fix crash that occurs when dir is nil --- builder/vmware/common/artifact.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/builder/vmware/common/artifact.go b/builder/vmware/common/artifact.go index b8056e544..c9fa075d2 100644 --- a/builder/vmware/common/artifact.go +++ b/builder/vmware/common/artifact.go @@ -49,7 +49,10 @@ func (a *artifact) State(name string) interface{} { } func (a *artifact) Destroy() error { - return a.dir.RemoveAll() + if a.dir != nil { + return a.dir.RemoveAll() + } + return nil } func NewArtifact(remoteType string, format string, exportOutputPath string, vmName string, skipExport bool, keepRegistered bool, state multistep.StateBag) (packer.Artifact, error) {