Commit e9246ec4 authored by Christian Groschupp's avatar Christian Groschupp

builder/vmware/iso: Upload VMX to ESX5 after editing [GH-1422,GH-1083]

parent ec216a52
...@@ -368,6 +368,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe ...@@ -368,6 +368,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
SkipFloppy: true, SkipFloppy: true,
}, },
&vmwcommon.StepCleanVMX{}, &vmwcommon.StepCleanVMX{},
&StepUploadVMX{
RemoteType: b.config.RemoteType,
},
&vmwcommon.StepCompactDisk{ &vmwcommon.StepCompactDisk{
Skip: b.config.SkipCompaction, Skip: b.config.SkipCompaction,
}, },
......
...@@ -56,6 +56,10 @@ func (d *ESX5Driver) IsRunning(string) (bool, error) { ...@@ -56,6 +56,10 @@ func (d *ESX5Driver) IsRunning(string) (bool, error) {
return strings.Contains(state, "Powered on"), nil 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 { func (d *ESX5Driver) Start(vmxPathLocal string, headless bool) error {
for i := 0; i < 20; i++ { for i := 0; i < 20; i++ {
err := d.sh("vim-cmd", "vmsvc/power.on", d.vmId) err := d.sh("vim-cmd", "vmsvc/power.on", d.vmId)
......
...@@ -17,4 +17,10 @@ type RemoteDriver interface { ...@@ -17,4 +17,10 @@ type RemoteDriver interface {
// Removes a VM from inventory specified by the path to the VMX given. // Removes a VM from inventory specified by the path to the VMX given.
Unregister(string) error Unregister(string) error
// Uploads a local file to remote side.
upload(dst, src string) error
// Reload VM on remote side.
ReloadVM() error
} }
...@@ -19,6 +19,10 @@ type RemoteDriverMock struct { ...@@ -19,6 +19,10 @@ type RemoteDriverMock struct {
UnregisterCalled bool UnregisterCalled bool
UnregisterPath string UnregisterPath string
UnregisterErr error UnregisterErr error
uploadErr error
ReloadVMErr error
} }
func (d *RemoteDriverMock) UploadISO(path string, checksum string, checksumType string) (string, error) { func (d *RemoteDriverMock) UploadISO(path string, checksum string, checksumType string) (string, error) {
...@@ -38,3 +42,11 @@ func (d *RemoteDriverMock) Unregister(path string) error { ...@@ -38,3 +42,11 @@ func (d *RemoteDriverMock) Unregister(path string) error {
d.UnregisterPath = path d.UnregisterPath = path
return d.UnregisterErr return d.UnregisterErr
} }
func (d *RemoteDriverMock) upload(dst, src string) error {
return d.uploadErr
}
func (d *RemoteDriverMock) ReloadVM() error {
return d.ReloadVMErr
}
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:
// <nothing>
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) {}
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