builder/vmware: more flexible ISO removing
/cc @timsutton - This is a bit more flexible.
This commit is contained in:
parent
55c82530a5
commit
f6854ae07e
|
@ -7,6 +7,7 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -22,10 +23,12 @@ import (
|
||||||
type stepCleanVMX struct{}
|
type stepCleanVMX struct{}
|
||||||
|
|
||||||
func (s stepCleanVMX) Run(state map[string]interface{}) multistep.StepAction {
|
func (s stepCleanVMX) Run(state map[string]interface{}) multistep.StepAction {
|
||||||
|
isoPath := state["iso_path"].(string)
|
||||||
ui := state["ui"].(packer.Ui)
|
ui := state["ui"].(packer.Ui)
|
||||||
vmxPath := state["vmx_path"].(string)
|
vmxPath := state["vmx_path"].(string)
|
||||||
|
|
||||||
|
ui.Say("Cleaning VMX prior to finishing up...")
|
||||||
|
|
||||||
vmxData, err := s.readVMX(vmxPath)
|
vmxData, err := s.readVMX(vmxPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
state["error"] = fmt.Errorf("Error reading VMX: %s", err)
|
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 {
|
if _, ok := state["floppy_path"]; ok {
|
||||||
// Delete the floppy0 entries so the floppy is no longer mounted
|
// 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 {
|
for k, _ := range vmxData {
|
||||||
if strings.HasPrefix(k, "floppy0.") {
|
if strings.HasPrefix(k, "floppy0.") {
|
||||||
log.Printf("Deleting key: %s", k)
|
log.Printf("Deleting key: %s", k)
|
||||||
|
@ -44,10 +47,23 @@ func (s stepCleanVMX) Run(state map[string]interface{}) multistep.StepAction {
|
||||||
vmxData["floppy0.present"] = "FALSE"
|
vmxData["floppy0.present"] = "FALSE"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Change the CD-ROM device back to auto-detect, ejecting the iso
|
ui.Message("Detatching ISO from CD-ROM device...")
|
||||||
ui.Say("Detatching ISO from CD-ROM device...")
|
devRe := regexp.MustCompile(`^ide\d:\d\.`)
|
||||||
vmxData["ide1:0.fileName"] = "auto detect"
|
for k, _ := range vmxData {
|
||||||
vmxData["ide1:0.deviceType"] = "cdrom-raw"
|
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
|
// Rewrite the VMX
|
||||||
if err := WriteVMX(vmxPath, vmxData); err != nil {
|
if err := WriteVMX(vmxPath, vmxData); err != nil {
|
||||||
|
|
Loading…
Reference in New Issue