diff --git a/builder/vmware/step_clean_vmx.go b/builder/vmware/step_clean_vmx.go index cc9841681..3aec60f7e 100644 --- a/builder/vmware/step_clean_vmx.go +++ b/builder/vmware/step_clean_vmx.go @@ -7,6 +7,7 @@ import ( "io/ioutil" "log" "os" + "regexp" "strings" ) @@ -22,10 +23,12 @@ import ( type stepCleanVMX struct{} func (s stepCleanVMX) Run(state map[string]interface{}) multistep.StepAction { - + isoPath := state["iso_path"].(string) ui := state["ui"].(packer.Ui) vmxPath := state["vmx_path"].(string) + ui.Say("Cleaning VMX prior to finishing up...") + vmxData, err := s.readVMX(vmxPath) if err != nil { state["error"] = fmt.Errorf("Error reading VMX: %s", err) @@ -34,7 +37,7 @@ func (s stepCleanVMX) Run(state map[string]interface{}) multistep.StepAction { if _, ok := state["floppy_path"]; ok { // Delete the floppy0 entries so the floppy is no longer mounted - ui.Say("Unmounting floppy from VMX...") + ui.Message("Unmounting floppy from VMX...") for k, _ := range vmxData { if strings.HasPrefix(k, "floppy0.") { log.Printf("Deleting key: %s", k) @@ -44,10 +47,23 @@ func (s stepCleanVMX) Run(state map[string]interface{}) multistep.StepAction { vmxData["floppy0.present"] = "FALSE" } - // Change the CD-ROM device back to auto-detect, ejecting the iso - ui.Say("Detatching ISO from CD-ROM device...") - vmxData["ide1:0.fileName"] = "auto detect" - vmxData["ide1:0.deviceType"] = "cdrom-raw" + ui.Message("Detatching ISO from CD-ROM device...") + devRe := regexp.MustCompile(`^ide\d:\d\.`) + for k, _ := range vmxData { + match := devRe.FindString(k) + if match == "" { + continue + } + + filenameKey := match + ".filename" + if filename, ok := vmxData[filenameKey]; ok { + if filename == isoPath { + // Change the CD-ROM device back to auto-detect to eject + vmxData[filenameKey] = "auto detect" + vmxData[match + ".deviceType"] = "cdrom-raw" + } + } + } // Rewrite the VMX if err := WriteVMX(vmxPath, vmxData); err != nil {