builder/vmware: more flexible ISO removing

/cc @timsutton - This is a bit more flexible.
This commit is contained in:
Mitchell Hashimoto 2013-07-20 19:08:20 -07:00
parent 55c82530a5
commit f6854ae07e
1 changed files with 22 additions and 6 deletions

View File

@ -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 {