diff --git a/builder/vmware/iso/step_export.go b/builder/vmware/common/step_export.go similarity index 82% rename from builder/vmware/iso/step_export.go rename to builder/vmware/common/step_export.go index c39443c8f..3b0cf5920 100644 --- a/builder/vmware/iso/step_export.go +++ b/builder/vmware/common/step_export.go @@ -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 diff --git a/builder/vmware/iso/step_export_test.go b/builder/vmware/common/step_export_test.go similarity index 90% rename from builder/vmware/iso/step_export_test.go rename to builder/vmware/common/step_export_test.go index 27c2a0c36..70197c827 100644 --- a/builder/vmware/iso/step_export_test.go +++ b/builder/vmware/common/step_export_test.go @@ -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) diff --git a/builder/vmware/iso/builder.go b/builder/vmware/iso/builder.go index c9cd16bce..03b4cfc5d 100644 --- a/builder/vmware/iso/builder.go +++ b/builder/vmware/iso/builder.go @@ -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, }, }