diff --git a/builder/vmware/iso/builder.go b/builder/vmware/iso/builder.go index aeda7ff41..674b308c9 100644 --- a/builder/vmware/iso/builder.go +++ b/builder/vmware/iso/builder.go @@ -368,6 +368,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe SkipFloppy: true, }, &vmwcommon.StepCleanVMX{}, + &StepUploadVMX{ + RemoteType: b.config.RemoteType, + }, &vmwcommon.StepCompactDisk{ Skip: b.config.SkipCompaction, }, diff --git a/builder/vmware/iso/driver_esx5.go b/builder/vmware/iso/driver_esx5.go index ca1733d63..1f9bd7a78 100644 --- a/builder/vmware/iso/driver_esx5.go +++ b/builder/vmware/iso/driver_esx5.go @@ -56,6 +56,10 @@ func (d *ESX5Driver) IsRunning(string) (bool, error) { return strings.Contains(state, "Powered on"), nil } +func (d *ESX5Driver) ReloadVM() error { + return d.sh("vim-cmd", "vmsvc/reload", d.vmId) +} + func (d *ESX5Driver) Start(vmxPathLocal string, headless bool) error { for i := 0; i < 20; i++ { err := d.sh("vim-cmd", "vmsvc/power.on", d.vmId) diff --git a/builder/vmware/iso/remote_driver.go b/builder/vmware/iso/remote_driver.go index b597d530a..7c62cd4d7 100644 --- a/builder/vmware/iso/remote_driver.go +++ b/builder/vmware/iso/remote_driver.go @@ -17,4 +17,10 @@ type RemoteDriver interface { // Removes a VM from inventory specified by the path to the VMX given. Unregister(string) error + + // Uploads a local file to remote side. + upload(dst, src string) error + + // Reload VM on remote side. + ReloadVM() error } diff --git a/builder/vmware/iso/remote_driver_mock.go b/builder/vmware/iso/remote_driver_mock.go index 233056ae3..2f4b3ae81 100644 --- a/builder/vmware/iso/remote_driver_mock.go +++ b/builder/vmware/iso/remote_driver_mock.go @@ -19,6 +19,10 @@ type RemoteDriverMock struct { UnregisterCalled bool UnregisterPath string UnregisterErr error + + uploadErr error + + ReloadVMErr error } func (d *RemoteDriverMock) UploadISO(path string, checksum string, checksumType string) (string, error) { @@ -38,3 +42,11 @@ func (d *RemoteDriverMock) Unregister(path string) error { d.UnregisterPath = path return d.UnregisterErr } + +func (d *RemoteDriverMock) upload(dst, src string) error { + return d.uploadErr +} + +func (d *RemoteDriverMock) ReloadVM() error { + return d.ReloadVMErr +} diff --git a/builder/vmware/iso/step_upload_vmx.go b/builder/vmware/iso/step_upload_vmx.go new file mode 100644 index 000000000..39e14af16 --- /dev/null +++ b/builder/vmware/iso/step_upload_vmx.go @@ -0,0 +1,48 @@ +package iso + +import ( + "fmt" + "github.com/mitchellh/multistep" + "github.com/mitchellh/packer/packer" + vmwcommon "github.com/mitchellh/packer/builder/vmware/common" + "path/filepath" +) + + +// This step upload the VMX to the remote host +// +// Uses: +// driver Driver +// ui packer.Ui +// vmx_path string +// +// Produces: +// +type StepUploadVMX struct{ + RemoteType string +} + +func (c *StepUploadVMX) Run(state multistep.StateBag) multistep.StepAction { + driver := state.Get("driver").(vmwcommon.Driver) + + ui := state.Get("ui").(packer.Ui) + vmxPath := state.Get("vmx_path").(string) + + if c.RemoteType == "esx5" { + remoteDriver, ok := driver.(RemoteDriver) + if ok { + remoteVmxPath := filepath.ToSlash(filepath.Join(fmt.Sprintf("%s",remoteDriver), filepath.Base(vmxPath))) + if err := remoteDriver.upload(remoteVmxPath, vmxPath); err != nil { + state.Put("error", fmt.Errorf("Error writing VMX: %s", err)) + return multistep.ActionHalt + } + } + if err := remoteDriver.ReloadVM(); err != nil { + ui.Error(fmt.Sprintf("Error reload VM: %s", err)) + } + } + + return multistep.ActionContinue +} + +func (StepUploadVMX) Cleanup(multistep.StateBag) {}