github.com/rothwerx/packer@v0.9.0/builder/vmware/common/step_clean_vmx.go (about) 1 package common 2 3 import ( 4 "fmt" 5 "log" 6 "regexp" 7 "strings" 8 9 "github.com/mitchellh/multistep" 10 "github.com/mitchellh/packer/packer" 11 ) 12 13 // This step cleans up the VMX by removing or changing this prior to 14 // being ready for use. 15 // 16 // Uses: 17 // ui packer.Ui 18 // vmx_path string 19 // 20 // Produces: 21 // <nothing> 22 type StepCleanVMX struct{} 23 24 func (s StepCleanVMX) Run(state multistep.StateBag) multistep.StepAction { 25 ui := state.Get("ui").(packer.Ui) 26 vmxPath := state.Get("vmx_path").(string) 27 28 ui.Say("Cleaning VMX prior to finishing up...") 29 30 vmxData, err := ReadVMX(vmxPath) 31 if err != nil { 32 state.Put("error", fmt.Errorf("Error reading VMX: %s", err)) 33 return multistep.ActionHalt 34 } 35 36 // Delete the floppy0 entries so the floppy is no longer mounted 37 ui.Message("Unmounting floppy from VMX...") 38 for k, _ := range vmxData { 39 if strings.HasPrefix(k, "floppy0.") { 40 log.Printf("Deleting key: %s", k) 41 delete(vmxData, k) 42 } 43 } 44 vmxData["floppy0.present"] = "FALSE" 45 46 devRe := regexp.MustCompile(`^ide\d:\d\.`) 47 for k, v := range vmxData { 48 ide := devRe.FindString(k) 49 if ide == "" || v != "cdrom-image" { 50 continue 51 } 52 53 ui.Message("Detaching ISO from CD-ROM device...") 54 55 vmxData[ide+"devicetype"] = "cdrom-raw" 56 vmxData[ide+"filename"] = "auto detect" 57 vmxData[ide+"clientdevice"] = "TRUE" 58 } 59 60 ui.Message("Disabling VNC server...") 61 vmxData["remotedisplay.vnc.enabled"] = "FALSE" 62 63 // Rewrite the VMX 64 if err := WriteVMX(vmxPath, vmxData); err != nil { 65 state.Put("error", fmt.Errorf("Error writing VMX: %s", err)) 66 return multistep.ActionHalt 67 } 68 69 return multistep.ActionContinue 70 } 71 72 func (StepCleanVMX) Cleanup(multistep.StateBag) {}