From 1127096beb3d22d825d3218fd6813bba828ae391 Mon Sep 17 00:00:00 2001 From: Eric Mowry Date: Thu, 28 Feb 2019 16:43:47 -0500 Subject: [PATCH 1/4] Setting extendedconfigfile to the name of the VM so that when ESXi makes the vmxf it is named after the VM and ESXi will properly delete the file when the VM gets deleted. --- builder/vmware/common/step_configure_vmx.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/builder/vmware/common/step_configure_vmx.go b/builder/vmware/common/step_configure_vmx.go index a4ebd7ae6..fd8bdea87 100644 --- a/builder/vmware/common/step_configure_vmx.go +++ b/builder/vmware/common/step_configure_vmx.go @@ -102,6 +102,8 @@ func (s *StepConfigureVMX) Run(_ context.Context, state multistep.StateBag) mult } } + vmxData["extendedconfigfile"] = fmt.Sprintf("%s.vmxf", s.DisplayName) + err = WriteVMX(vmxPath, vmxData) if err != nil { From e74a81e27b898330bf9933c86ce2c918f033b92c Mon Sep 17 00:00:00 2001 From: Eric Mowry Date: Thu, 28 Feb 2019 16:47:46 -0500 Subject: [PATCH 2/4] Deny the copying of .vmxf from the source VM to the target VM. If this file gets copied over to the new VM once the VM gets deleted the .vmxf and the folder for the VM stay on the datastore. This causes Packer to hang because the folder on the datastore does not go away during the cleanup process. --- builder/vmware/common/driver_esx5.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builder/vmware/common/driver_esx5.go b/builder/vmware/common/driver_esx5.go index 4b083e5ff..b82aac7b2 100644 --- a/builder/vmware/common/driver_esx5.go +++ b/builder/vmware/common/driver_esx5.go @@ -68,7 +68,7 @@ func (d *ESX5Driver) Clone(dst, src string, linked bool) error { return fmt.Errorf("Failed to copy the vmx file %s: %s", srcVmx, err) } - filesToClone, err := d.run(nil, "find", strconv.Quote(srcDir), "! -name '*.vmdk' ! -name '*.vmx' -type f ! -size 0") + filesToClone, err := d.run(nil, "find", strconv.Quote(srcDir), "! -name '*.vmdk' ! -name '*.vmx' ! -name '*.vmxf' -type f ! -size 0") if err != nil { return fmt.Errorf("Failed to get the file list to copy: %s", err) } From 109ba2c54c5eca427efe67e570d47c4cc5add472 Mon Sep 17 00:00:00 2001 From: Eric Mowry Date: Thu, 28 Feb 2019 21:36:25 -0500 Subject: [PATCH 3/4] After testing a ISO and VMX clone along with setting the display_name option it was determined that having no name for the .vmxf file did not work either. Updating to check if displayName is not empty before using and falling back to VMName if displayName is empty. --- builder/vmware/common/step_configure_vmx.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/builder/vmware/common/step_configure_vmx.go b/builder/vmware/common/step_configure_vmx.go index fd8bdea87..1d94e4362 100644 --- a/builder/vmware/common/step_configure_vmx.go +++ b/builder/vmware/common/step_configure_vmx.go @@ -102,7 +102,16 @@ func (s *StepConfigureVMX) Run(_ context.Context, state multistep.StateBag) mult } } - vmxData["extendedconfigfile"] = fmt.Sprintf("%s.vmxf", s.DisplayName) + // Set the extendedConfigFile setting for the .vmxf filename to the VMName + // if displayName is not set. This is needed so that when VMWare creates + // the .vmxf file it matches the displayName if it is set. When just using + // the sisplayName if it was empty VMWare would make a file named ".vmxf". + // The ".vmxf" file would not get deleted when the VM got deleted. + if s.DisplayName != "" { + vmxData["extendedconfigfile"] = fmt.Sprintf("%s.vmxf", s.DisplayName) + } else { + vmxData["extendedconfigfile"] = fmt.Sprintf("%s.vmxf", s.VMName) + } err = WriteVMX(vmxPath, vmxData) From cef3d0eb248179504af6830a0c9c4be50815d4e8 Mon Sep 17 00:00:00 2001 From: Eric Mowry Date: Fri, 1 Mar 2019 14:16:00 -0500 Subject: [PATCH 4/4] Ran make fmt per Megan's request. --- builder/vmware/common/step_configure_vmx.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/builder/vmware/common/step_configure_vmx.go b/builder/vmware/common/step_configure_vmx.go index 1d94e4362..702f0e0e6 100644 --- a/builder/vmware/common/step_configure_vmx.go +++ b/builder/vmware/common/step_configure_vmx.go @@ -103,15 +103,15 @@ func (s *StepConfigureVMX) Run(_ context.Context, state multistep.StateBag) mult } // Set the extendedConfigFile setting for the .vmxf filename to the VMName - // if displayName is not set. This is needed so that when VMWare creates + // if displayName is not set. This is needed so that when VMWare creates // the .vmxf file it matches the displayName if it is set. When just using // the sisplayName if it was empty VMWare would make a file named ".vmxf". // The ".vmxf" file would not get deleted when the VM got deleted. - if s.DisplayName != "" { - vmxData["extendedconfigfile"] = fmt.Sprintf("%s.vmxf", s.DisplayName) - } else { - vmxData["extendedconfigfile"] = fmt.Sprintf("%s.vmxf", s.VMName) - } + if s.DisplayName != "" { + vmxData["extendedconfigfile"] = fmt.Sprintf("%s.vmxf", s.DisplayName) + } else { + vmxData["extendedconfigfile"] = fmt.Sprintf("%s.vmxf", s.VMName) + } err = WriteVMX(vmxPath, vmxData)