Move step_export to common.

This commit is contained in:
Alexander Laamanen 2017-03-05 22:15:53 +02:00 committed by Megan Marsh
parent 63054fb808
commit a68a639a1a
3 changed files with 23 additions and 18 deletions

View File

@ -1,4 +1,4 @@
package iso
package common
import (
"bytes"
@ -19,12 +19,14 @@ import (
// Uses:
// display_name string
type StepExport struct {
Format string
SkipExport bool
OutputDir string
Format string
SkipExport bool
VMName string
OVFToolOptions []string
OutputDir string
}
func (s *StepExport) generateArgs(c *Config, displayName string, hidePassword bool) []string {
func (s *StepExport) generateArgs(c *DriverConfig, outputPath string, hidePassword bool) []string {
password := url.QueryEscape(c.RemotePassword)
if hidePassword {
password = "****"
@ -33,18 +35,19 @@ func (s *StepExport) generateArgs(c *Config, displayName string, hidePassword bo
"--noSSLVerify=true",
"--skipManifestCheck",
"-tt=" + s.Format,
"vi://" + c.RemoteUser + ":" + password + "@" + c.RemoteHost + "/" + displayName,
s.OutputDir,
"vi://" + c.RemoteUser + ":" + password + "@" + c.RemoteHost + "/" + s.VMName,
outputPath,
}
return append(c.OVFToolOptions, args...)
return append(s.OVFToolOptions, args...)
}
func (s *StepExport) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
c := state.Get("config").(*Config)
c := state.Get("driverConfig").(*DriverConfig)
ui := state.Get("ui").(packer.Ui)
// Skip export if requested
if c.SkipExport {
if s.SkipExport {
ui.Say("Skipping export of virtual machine...")
return multistep.ActionContinue
}
@ -60,7 +63,7 @@ func (s *StepExport) Run(_ context.Context, state multistep.StateBag) multistep.
}
if _, err := exec.LookPath(ovftool); err != nil {
err := fmt.Errorf("Error %s not found: %s", ovftool, err)
err = fmt.Errorf("Error %s not found: %s", ovftool, err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt

View File

@ -1,4 +1,4 @@
package iso
package common
import (
"context"
@ -15,9 +15,9 @@ func testStepExport_wrongtype_impl(t *testing.T, remoteType string) {
state := testState(t)
step := new(StepExport)
var config Config
var config DriverConfig
config.RemoteType = "foo"
state.Put("config", &config)
state.Put("driverConfig", &config)
if action := step.Run(context.Background(), state); action != multistep.ActionContinue {
t.Fatalf("bad action: %#v", action)

View File

@ -260,6 +260,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
state.Put("hook", hook)
state.Put("ui", ui)
state.Put("sshConfig", &b.config.SSHConfig)
state.Put("driverConfig", &b.config.DriverConfig)
steps := []multistep.Step{
&vmwcommon.StepPrepareTools{
@ -360,10 +361,11 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
&vmwcommon.StepUploadVMX{
RemoteType: b.config.RemoteType,
},
&StepExport{
Format: b.config.Format,
SkipExport: b.config.SkipExport,
OutputDir: exportOutputPath,
&vmwcommon.StepExport{
Format: b.config.Format,
SkipExport: b.config.SkipExport,
VMName: b.config.VMName,
OVFToolOptions: b.config.OVFToolOptions,
},
}