2017-01-31 05:05:49 -05:00
|
|
|
package common
|
2014-11-16 13:31:08 -05:00
|
|
|
|
|
|
|
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"
|
|
|
|
|
2020-11-17 19:31:03 -05:00
|
|
|
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
|
2020-11-19 14:54:31 -05:00
|
|
|
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
2014-11-16 13:31:08 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// This step upload the VMX to the remote host
|
|
|
|
//
|
|
|
|
// Uses:
|
|
|
|
// driver Driver
|
2020-11-19 14:54:31 -05:00
|
|
|
// ui packersdk.Ui
|
2014-11-16 13:31:08 -05:00
|
|
|
// 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
|
|
|
}
|
|
|
|
|
2019-03-29 11:50:02 -04:00
|
|
|
func (c *StepUploadVMX) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
2017-01-31 05:05:49 -05:00
|
|
|
driver := state.Get("driver").(Driver)
|
2014-11-16 13:31:08 -05:00
|
|
|
|
2020-11-19 14:54:31 -05:00
|
|
|
ui := state.Get("ui").(packersdk.Ui)
|
2014-11-16 13:31:08 -05:00
|
|
|
vmxPath := state.Get("vmx_path").(string)
|
|
|
|
|
|
|
|
if c.RemoteType == "esx5" {
|
2017-01-31 05:05:49 -05:00
|
|
|
remoteDriver, ok := driver.(RemoteDriver)
|
2014-11-16 13:31:08 -05:00
|
|
|
if ok {
|
2015-06-09 00:34:20 -04:00
|
|
|
remoteVmxPath := filepath.ToSlash(filepath.Join(fmt.Sprintf("%s", remoteDriver), filepath.Base(vmxPath)))
|
2020-08-17 14:35:42 -04:00
|
|
|
if err := remoteDriver.upload(remoteVmxPath, vmxPath, nil); err != nil {
|
2014-11-16 13:31:08 -05:00
|
|
|
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) {}
|