Merge pull request #6057 from arizvisa/GH-5925

Fixed a case-sensitivity issue when determing the network type during the cloning step in the vmware-vmx builder
This commit is contained in:
Megan Marsh 2018-03-28 13:54:09 -07:00 committed by GitHub
commit 7623c26e4e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 5 deletions

View File

@ -22,8 +22,10 @@ func (s *StepCloneVMX) Run(_ context.Context, state multistep.StateBag) multiste
driver := state.Get("driver").(vmwcommon.Driver) driver := state.Get("driver").(vmwcommon.Driver)
ui := state.Get("ui").(packer.Ui) 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") vmxPath := filepath.Join(s.OutputDir, s.VMName+".vmx")
// so first, let's clone the source path to the vmxPath
ui.Say("Cloning source VM...") ui.Say("Cloning source VM...")
log.Printf("Cloning from: %s", s.Path) log.Printf("Cloning from: %s", s.Path)
log.Printf("Cloning to: %s", vmxPath) log.Printf("Cloning to: %s", vmxPath)
@ -31,13 +33,16 @@ func (s *StepCloneVMX) Run(_ context.Context, state multistep.StateBag) multiste
state.Put("error", err) state.Put("error", err)
return multistep.ActionHalt return multistep.ActionHalt
} }
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) vmxData, err := vmwcommon.ReadVMX(vmxPath)
if err != nil { if err != nil {
state.Put("error", err) state.Put("error", err)
return multistep.ActionHalt return multistep.ActionHalt
} }
// figure out the disk filename by walking through all device types
var diskName string var diskName string
if _, ok := vmxData["scsi0:0.filename"]; ok { if _, ok := vmxData["scsi0:0.filename"]; ok {
diskName = vmxData["scsi0:0.filename"] diskName = vmxData["scsi0:0.filename"]
@ -53,19 +58,25 @@ func (s *StepCloneVMX) Run(_ context.Context, state multistep.StateBag) multiste
state.Put("error", err) state.Put("error", err)
return multistep.ActionHalt return multistep.ActionHalt
} }
log.Printf("Found root disk filename: %s", diskName)
// determine the network type by reading out of the .vmx
var networkType string var networkType string
if _, ok := vmxData["ethernet0.connectionType"]; ok { if _, ok := vmxData["ethernet0.connectiontype"]; ok {
networkType = vmxData["ethernet0.connectionType"] networkType = vmxData["ethernet0.connectiontype"]
log.Printf("Discovered the network type: %s", networkType)
} }
if networkType == "" { if networkType == "" {
networkType = "nat" networkType = "nat"
log.Printf("Defaulting to network type : nat") log.Printf("Defaulting to network type: %s", networkType)
} }
ui.Say(fmt.Sprintf("Using network type: %s", networkType))
state.Put("vmnetwork", networkType) // we were able to find everything, so stash it in our state.
state.Put("full_disk_path", filepath.Join(s.OutputDir, diskName))
state.Put("vmx_path", vmxPath) state.Put("vmx_path", vmxPath)
state.Put("full_disk_path", filepath.Join(s.OutputDir, diskName))
state.Put("vmnetwork", networkType)
return multistep.ActionContinue return multistep.ActionContinue
} }