|
|
|
|
@ -26,9 +26,11 @@ type vmxTemplateData struct {
|
|
|
|
|
//
|
|
|
|
|
// Produces:
|
|
|
|
|
// vmx_path string - The path to the VMX file.
|
|
|
|
|
type stepCreateVMX struct{}
|
|
|
|
|
type stepCreateVMX struct {
|
|
|
|
|
tempDir string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (stepCreateVMX) Run(state multistep.StateBag) multistep.StepAction {
|
|
|
|
|
func (s *stepCreateVMX) Run(state multistep.StateBag) multistep.StepAction {
|
|
|
|
|
config := state.Get("config").(*config)
|
|
|
|
|
isoPath := state.Get("iso_path").(string)
|
|
|
|
|
ui := state.Get("ui").(packer.Ui)
|
|
|
|
|
@ -91,7 +93,23 @@ func (stepCreateVMX) Run(state multistep.StateBag) multistep.StepAction {
|
|
|
|
|
// Set this so that no dialogs ever appear from Packer.
|
|
|
|
|
vmxData["msg.autoAnswer"] = "true"
|
|
|
|
|
|
|
|
|
|
vmxPath := filepath.Join(config.OutputDir, config.VMName+".vmx")
|
|
|
|
|
vmxDir := config.OutputDir
|
|
|
|
|
if config.RemoteType != "" {
|
|
|
|
|
// For remote builds, we just put the VMX in a temporary
|
|
|
|
|
// directory since it just gets uploaded anyways.
|
|
|
|
|
vmxDir, err = ioutil.TempDir("", "packer-vmx")
|
|
|
|
|
if err != nil {
|
|
|
|
|
err := fmt.Errorf("Error preparing VMX template: %s", err)
|
|
|
|
|
state.Put("error", err)
|
|
|
|
|
ui.Error(err.Error())
|
|
|
|
|
return multistep.ActionHalt
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Set the tempDir so we clean it up
|
|
|
|
|
s.tempDir = vmxDir
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vmxPath := filepath.Join(vmxDir, config.VMName+".vmx")
|
|
|
|
|
if err := WriteVMX(vmxPath, vmxData); err != nil {
|
|
|
|
|
err := fmt.Errorf("Error creating VMX file: %s", err)
|
|
|
|
|
state.Put("error", err)
|
|
|
|
|
@ -104,7 +122,10 @@ func (stepCreateVMX) Run(state multistep.StateBag) multistep.StepAction {
|
|
|
|
|
return multistep.ActionContinue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (stepCreateVMX) Cleanup(multistep.StateBag) {
|
|
|
|
|
func (s *stepCreateVMX) Cleanup(multistep.StateBag) {
|
|
|
|
|
if s.tempDir != "" {
|
|
|
|
|
os.RemoveAll(s.tempDir)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This is the default VMX template used if no other template is given.
|
|
|
|
|
|