github.com/mitchellh/packer@v1.3.2/builder/vmware/iso/step_upload_vmx.go (about) 1 package iso 2 3 import ( 4 "context" 5 "fmt" 6 "path/filepath" 7 8 vmwcommon "github.com/hashicorp/packer/builder/vmware/common" 9 "github.com/hashicorp/packer/helper/multistep" 10 "github.com/hashicorp/packer/packer" 11 ) 12 13 // This step upload the VMX to the remote host 14 // 15 // Uses: 16 // driver Driver 17 // ui packer.Ui 18 // vmx_path string 19 // 20 // Produces: 21 // <nothing> 22 type StepUploadVMX struct { 23 RemoteType string 24 } 25 26 func (c *StepUploadVMX) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { 27 driver := state.Get("driver").(vmwcommon.Driver) 28 29 ui := state.Get("ui").(packer.Ui) 30 vmxPath := state.Get("vmx_path").(string) 31 32 if c.RemoteType == "esx5" { 33 remoteDriver, ok := driver.(RemoteDriver) 34 if ok { 35 remoteVmxPath := filepath.ToSlash(filepath.Join(fmt.Sprintf("%s", remoteDriver), filepath.Base(vmxPath))) 36 if err := remoteDriver.upload(remoteVmxPath, vmxPath); err != nil { 37 state.Put("error", fmt.Errorf("Error writing VMX: %s", err)) 38 return multistep.ActionHalt 39 } 40 } 41 if err := remoteDriver.ReloadVM(); err != nil { 42 ui.Error(fmt.Sprintf("Error reload VM: %s", err)) 43 } 44 } 45 46 return multistep.ActionContinue 47 } 48 49 func (StepUploadVMX) Cleanup(multistep.StateBag) {}