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