Commit b2287239 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

builder/vmware: for remote builds, put VMX in temp dir

parent a4b54f1c
...@@ -26,9 +26,11 @@ type vmxTemplateData struct { ...@@ -26,9 +26,11 @@ type vmxTemplateData struct {
// //
// Produces: // Produces:
// vmx_path string - The path to the VMX file. // 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) config := state.Get("config").(*config)
isoPath := state.Get("iso_path").(string) isoPath := state.Get("iso_path").(string)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)
...@@ -91,7 +93,23 @@ func (stepCreateVMX) Run(state multistep.StateBag) multistep.StepAction { ...@@ -91,7 +93,23 @@ func (stepCreateVMX) Run(state multistep.StateBag) multistep.StepAction {
// Set this so that no dialogs ever appear from Packer. // Set this so that no dialogs ever appear from Packer.
vmxData["msg.autoAnswer"] = "true" 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 { if err := WriteVMX(vmxPath, vmxData); err != nil {
err := fmt.Errorf("Error creating VMX file: %s", err) err := fmt.Errorf("Error creating VMX file: %s", err)
state.Put("error", err) state.Put("error", err)
...@@ -104,7 +122,10 @@ func (stepCreateVMX) Run(state multistep.StateBag) multistep.StepAction { ...@@ -104,7 +122,10 @@ func (stepCreateVMX) Run(state multistep.StateBag) multistep.StepAction {
return multistep.ActionContinue 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. // This is the default VMX template used if no other template is given.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment