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