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