2014-11-16 13:31:08 -05:00
|
|
|
package iso
|
|
|
|
|
|
|
|
import (
|
2018-01-22 18:32:33 -05:00
|
|
|
"context"
|
2014-11-16 13:31:08 -05:00
|
|
|
"fmt"
|
2018-01-22 20:21:10 -05:00
|
|
|
"path/filepath"
|
|
|
|
|
2017-04-04 16:39:01 -04:00
|
|
|
vmwcommon "github.com/hashicorp/packer/builder/vmware/common"
|
2018-01-19 19:18:44 -05:00
|
|
|
"github.com/hashicorp/packer/helper/multistep"
|
2017-04-04 16:39:01 -04:00
|
|
|
"github.com/hashicorp/packer/packer"
|
2014-11-16 13:31:08 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// This step upload the VMX to the remote host
|
|
|
|
//
|
|
|
|
// Uses:
|
|
|
|
// driver Driver
|
|
|
|
// ui packer.Ui
|
|
|
|
// vmx_path string
|
|
|
|
//
|
|
|
|
// Produces:
|
|
|
|
// <nothing>
|
2015-06-09 00:34:20 -04:00
|
|
|
type StepUploadVMX struct {
|
|
|
|
RemoteType string
|
2014-11-16 13:31:08 -05:00
|
|
|
}
|
|
|
|
|
2018-01-22 18:31:41 -05:00
|
|
|
func (c *StepUploadVMX) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
2014-11-16 13:31:08 -05:00
|
|
|
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 {
|
2015-06-09 00:34:20 -04:00
|
|
|
remoteVmxPath := filepath.ToSlash(filepath.Join(fmt.Sprintf("%s", remoteDriver), filepath.Base(vmxPath)))
|
2014-11-16 13:31:08 -05:00
|
|
|
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) {}
|