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 ( import (
"bytes" "bytes"
@ -21,10 +21,12 @@ import (
type StepExport struct { type StepExport struct {
Format string Format string
SkipExport bool SkipExport bool
VMName string
OVFToolOptions []string
OutputDir 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) password := url.QueryEscape(c.RemotePassword)
if hidePassword { if hidePassword {
password = "****" password = "****"
@ -33,18 +35,19 @@ func (s *StepExport) generateArgs(c *Config, displayName string, hidePassword bo
"--noSSLVerify=true", "--noSSLVerify=true",
"--skipManifestCheck", "--skipManifestCheck",
"-tt=" + s.Format, "-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 { 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) ui := state.Get("ui").(packer.Ui)
// Skip export if requested // Skip export if requested
if c.SkipExport { if s.SkipExport {
ui.Say("Skipping export of virtual machine...") ui.Say("Skipping export of virtual machine...")
return multistep.ActionContinue return multistep.ActionContinue
} }
@ -60,7 +63,7 @@ func (s *StepExport) Run(_ context.Context, state multistep.StateBag) multistep.
} }
if _, err := exec.LookPath(ovftool); err != nil { 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) state.Put("error", err)
ui.Error(err.Error()) ui.Error(err.Error())
return multistep.ActionHalt return multistep.ActionHalt

View File

@ -1,4 +1,4 @@
package iso package common
import ( import (
"context" "context"
@ -15,9 +15,9 @@ func testStepExport_wrongtype_impl(t *testing.T, remoteType string) {
state := testState(t) state := testState(t)
step := new(StepExport) step := new(StepExport)
var config Config var config DriverConfig
config.RemoteType = "foo" config.RemoteType = "foo"
state.Put("config", &config) state.Put("driverConfig", &config)
if action := step.Run(context.Background(), state); action != multistep.ActionContinue { if action := step.Run(context.Background(), state); action != multistep.ActionContinue {
t.Fatalf("bad action: %#v", action) 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("hook", hook)
state.Put("ui", ui) state.Put("ui", ui)
state.Put("sshConfig", &b.config.SSHConfig) state.Put("sshConfig", &b.config.SSHConfig)
state.Put("driverConfig", &b.config.DriverConfig)
steps := []multistep.Step{ steps := []multistep.Step{
&vmwcommon.StepPrepareTools{ &vmwcommon.StepPrepareTools{
@ -360,10 +361,11 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
&vmwcommon.StepUploadVMX{ &vmwcommon.StepUploadVMX{
RemoteType: b.config.RemoteType, RemoteType: b.config.RemoteType,
}, },
&StepExport{ &vmwcommon.StepExport{
Format: b.config.Format, Format: b.config.Format,
SkipExport: b.config.SkipExport, SkipExport: b.config.SkipExport,
OutputDir: exportOutputPath, VMName: b.config.VMName,
OVFToolOptions: b.config.OVFToolOptions,
}, },
} }