Move step_register and step_uload_vmx from iso to common.
This commit is contained in:
parent
b5298464c5
commit
ba22090bc9
|
@ -47,8 +47,8 @@ func (d *ESX5Driver) Clone(dst, src string, linked bool) error {
|
|||
|
||||
linesToArray := func(lines string) []string { return strings.Split(strings.Trim(lines, "\n"), "\n") }
|
||||
|
||||
d.SetOutputDir(dst)
|
||||
srcVmx := d.datastorePath(path.Dir(src))
|
||||
d.SetOutputDir(path.Dir(dst))
|
||||
srcVmx := d.datastorePath(src)
|
||||
dstVmx := d.datastorePath(dst)
|
||||
srcDir := path.Dir(srcVmx)
|
||||
dstDir := path.Dir(dstVmx)
|
||||
|
|
|
@ -30,7 +30,6 @@ func (s *StepConfigureVMX) Run(_ context.Context, state multistep.StateBag) mult
|
|||
|
||||
var vmxContents []byte
|
||||
var err error
|
||||
driver := state.Get("driver").(Driver)
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
|
||||
vmxPath := state.Get("vmx_path").(string)
|
||||
|
@ -75,13 +74,7 @@ func (s *StepConfigureVMX) Run(_ context.Context, state multistep.StateBag) mult
|
|||
}
|
||||
}
|
||||
|
||||
if remoteDriver, ok := driver.(RemoteDriver); ok {
|
||||
var buf bytes.Buffer
|
||||
buf.WriteString(EncodeVMX(vmxData))
|
||||
err = remoteDriver.WriteFile(vmxPath, buf.Bytes())
|
||||
} else {
|
||||
err = WriteVMX(vmxPath, vmxData)
|
||||
}
|
||||
err = WriteVMX(vmxPath, vmxData)
|
||||
|
||||
if err != nil {
|
||||
err := fmt.Errorf("Error writing VMX file: %s", err)
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
package iso
|
||||
package common
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
vmwcommon "github.com/hashicorp/packer/builder/vmware/common"
|
||||
"github.com/hashicorp/packer/helper/multistep"
|
||||
"github.com/hashicorp/packer/packer"
|
||||
)
|
||||
|
@ -13,14 +12,15 @@ import (
|
|||
type StepRegister struct {
|
||||
registeredPath string
|
||||
Format string
|
||||
KeepRegistered bool
|
||||
}
|
||||
|
||||
func (s *StepRegister) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
||||
driver := state.Get("driver").(vmwcommon.Driver)
|
||||
driver := state.Get("driver").(Driver)
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
vmxPath := state.Get("vmx_path").(string)
|
||||
|
||||
if remoteDriver, ok := driver.(vmwcommon.RemoteDriver); ok {
|
||||
if remoteDriver, ok := driver.(RemoteDriver); ok {
|
||||
ui.Say("Registering remote VM...")
|
||||
if err := remoteDriver.Register(vmxPath); err != nil {
|
||||
err := fmt.Errorf("Error registering VM: %s", err)
|
||||
|
@ -40,18 +40,17 @@ func (s *StepRegister) Cleanup(state multistep.StateBag) {
|
|||
return
|
||||
}
|
||||
|
||||
driver := state.Get("driver").(vmwcommon.Driver)
|
||||
driver := state.Get("driver").(Driver)
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
config := state.Get("config").(*Config)
|
||||
|
||||
_, cancelled := state.GetOk(multistep.StateCancelled)
|
||||
_, halted := state.GetOk(multistep.StateHalted)
|
||||
if (config.KeepRegistered) && (!cancelled && !halted) {
|
||||
if (s.KeepRegistered) && (!cancelled && !halted) {
|
||||
ui.Say("Keeping virtual machine registered with ESX host (keep_registered = true)")
|
||||
return
|
||||
}
|
||||
|
||||
if remoteDriver, ok := driver.(vmwcommon.RemoteDriver); ok {
|
||||
if remoteDriver, ok := driver.(RemoteDriver); ok {
|
||||
if s.Format == "" || config.SkipExport {
|
||||
ui.Say("Unregistering virtual machine...")
|
||||
if err := remoteDriver.Unregister(s.registeredPath); err != nil {
|
|
@ -1,4 +1,4 @@
|
|||
package iso
|
||||
package common
|
||||
|
||||
import (
|
||||
"context"
|
|
@ -1,11 +1,11 @@
|
|||
package iso
|
||||
package common
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"path/filepath"
|
||||
|
||||
vmwcommon "github.com/hashicorp/packer/builder/vmware/common"
|
||||
"github.com/hashicorp/packer/helper/multistep"
|
||||
"github.com/hashicorp/packer/packer"
|
||||
)
|
||||
|
@ -24,15 +24,16 @@ type StepUploadVMX struct {
|
|||
}
|
||||
|
||||
func (c *StepUploadVMX) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
||||
driver := state.Get("driver").(vmwcommon.Driver)
|
||||
driver := state.Get("driver").(Driver)
|
||||
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
vmxPath := state.Get("vmx_path").(string)
|
||||
|
||||
if c.RemoteType == "esx5" {
|
||||
remoteDriver, ok := driver.(vmwcommon.RemoteDriver)
|
||||
remoteDriver, ok := driver.(RemoteDriver)
|
||||
if ok {
|
||||
remoteVmxPath := filepath.ToSlash(filepath.Join(fmt.Sprintf("%s", remoteDriver), filepath.Base(vmxPath)))
|
||||
log.Printf("Uploading VMX file from %s to %s", vmxPath, remoteVmxPath)
|
||||
if err := remoteDriver.Upload(remoteVmxPath, vmxPath); err != nil {
|
||||
state.Put("error", fmt.Errorf("Error writing VMX: %s", err))
|
||||
return multistep.ActionHalt
|
|
@ -341,8 +341,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
|||
VNCPortMax: b.config.VNCPortMax,
|
||||
VNCDisablePassword: b.config.VNCDisablePassword,
|
||||
},
|
||||
&StepRegister{
|
||||
Format: b.config.Format,
|
||||
&vmwcommon.StepRegister{
|
||||
Format: b.config.Format,
|
||||
KeepRegistered: b.config.KeepRegistered,
|
||||
},
|
||||
&vmwcommon.StepRun{
|
||||
DurationBeforeStop: 5 * time.Second,
|
||||
|
@ -387,7 +388,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
|||
RemoveEthernetInterfaces: b.config.VMXConfig.VMXRemoveEthernet,
|
||||
VNCEnabled: !b.config.DisableVNC,
|
||||
},
|
||||
&StepUploadVMX{
|
||||
&vmwcommon.StepUploadVMX{
|
||||
RemoteType: b.config.RemoteType,
|
||||
},
|
||||
&StepExport{
|
||||
|
|
|
@ -80,6 +80,13 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
|||
HTTPPortMin: b.config.HTTPPortMin,
|
||||
HTTPPortMax: b.config.HTTPPortMax,
|
||||
},
|
||||
&vmwcommon.StepUploadVMX{
|
||||
RemoteType: b.config.RemoteType,
|
||||
},
|
||||
&vmwcommon.StepRegister{
|
||||
Format: "foo",
|
||||
KeepRegistered: false,
|
||||
},
|
||||
&vmwcommon.StepConfigureVNC{
|
||||
Enabled: !b.config.DisableVNC,
|
||||
VNCBindAddress: b.config.VNCBindAddress,
|
||||
|
|
Loading…
Reference in New Issue