github.com/daniellockard/packer@v0.7.6-0.20141210173435-5a9390934716/builder/vmware/iso/step_upload_vmx.go (about)

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