From 72da7cbfbb4bd8e07320cf0562a9fea1557a136b Mon Sep 17 00:00:00 2001 From: Ali Rizvi-Santiago Date: Sun, 25 Mar 2018 18:51:37 -0500 Subject: [PATCH 1/2] Fixed a case-sensitivity issue when determing the network type during cloning in the vmware-vmx builder and added also some logs that output the different options that were determined from the .vmx. This outputs more accurate debug information and helps out with issue #5925 --- builder/vmware/vmx/step_clone_vmx.go | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/builder/vmware/vmx/step_clone_vmx.go b/builder/vmware/vmx/step_clone_vmx.go index bd644ca30..482adb46b 100644 --- a/builder/vmware/vmx/step_clone_vmx.go +++ b/builder/vmware/vmx/step_clone_vmx.go @@ -22,8 +22,10 @@ func (s *StepCloneVMX) Run(_ context.Context, state multistep.StateBag) multiste driver := state.Get("driver").(vmwcommon.Driver) ui := state.Get("ui").(packer.Ui) + // initially we need to stash the path to the original .vmx file vmxPath := filepath.Join(s.OutputDir, s.VMName+".vmx") + // so first, let's clone the source path to the vmxPath ui.Say("Cloning source VM...") log.Printf("Cloning from: %s", s.Path) log.Printf("Cloning to: %s", vmxPath) @@ -31,13 +33,16 @@ func (s *StepCloneVMX) Run(_ context.Context, state multistep.StateBag) multiste state.Put("error", err) return multistep.ActionHalt } + ui.Say("Successfully cloned source VM to: %s", vmxPath) + // now we read the .vmx so we can determine what else to stash vmxData, err := vmwcommon.ReadVMX(vmxPath) if err != nil { state.Put("error", err) return multistep.ActionHalt } + // figure out the disk filename by walking through all device types var diskName string if _, ok := vmxData["scsi0:0.filename"]; ok { diskName = vmxData["scsi0:0.filename"] @@ -53,19 +58,25 @@ func (s *StepCloneVMX) Run(_ context.Context, state multistep.StateBag) multiste state.Put("error", err) return multistep.ActionHalt } + log.Printf("Found root disk filename: %s", diskName) + // determine the network type by reading out of the .vmx var networkType string - if _, ok := vmxData["ethernet0.connectionType"]; ok { - networkType = vmxData["ethernet0.connectionType"] + if _, ok := vmxData["ethernet0.connectiontype"]; ok { + networkType = vmxData["ethernet0.connectiontype"] + log.Printf("Discovered the network type: %s", networkType) } if networkType == "" { networkType = "nat" - log.Printf("Defaulting to network type : nat") + log.Printf("Defaulting to network type: %s", networkType) } + ui.Say("Using network type: %s", networkType) - state.Put("vmnetwork", networkType) - state.Put("full_disk_path", filepath.Join(s.OutputDir, diskName)) + // we were able to find everything, so stash it in our state. state.Put("vmx_path", vmxPath) + state.Put("full_disk_path", filepath.Join(s.OutputDir, diskName)) + state.Put("vmnetwork", networkType) + return multistep.ActionContinue } From 55702a697af5b6ea63590d85eb5c2243142c6f83 Mon Sep 17 00:00:00 2001 From: Ali Rizvi-Santiago Date: Sun, 25 Mar 2018 19:03:37 -0500 Subject: [PATCH 2/2] Ack, forgot to :w in vim. Changed ui.Say in step_clone_vmx.go to use fmt.Sprintf as it originally was a call to log.Printf. --- builder/vmware/vmx/step_clone_vmx.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/builder/vmware/vmx/step_clone_vmx.go b/builder/vmware/vmx/step_clone_vmx.go index 482adb46b..f0bdd586d 100644 --- a/builder/vmware/vmx/step_clone_vmx.go +++ b/builder/vmware/vmx/step_clone_vmx.go @@ -33,7 +33,7 @@ func (s *StepCloneVMX) Run(_ context.Context, state multistep.StateBag) multiste state.Put("error", err) return multistep.ActionHalt } - ui.Say("Successfully cloned source VM to: %s", vmxPath) + ui.Say(fmt.Sprintf("Successfully cloned source VM to: %s", vmxPath)) // now we read the .vmx so we can determine what else to stash vmxData, err := vmwcommon.ReadVMX(vmxPath) @@ -70,7 +70,7 @@ func (s *StepCloneVMX) Run(_ context.Context, state multistep.StateBag) multiste networkType = "nat" log.Printf("Defaulting to network type: %s", networkType) } - ui.Say("Using network type: %s", networkType) + ui.Say(fmt.Sprintf("Using network type: %s", networkType)) // we were able to find everything, so stash it in our state. state.Put("vmx_path", vmxPath)