diff --git a/builder/vmware/iso/step_export.go b/builder/vmware/iso/step_export.go index 50b1efd9f..c39443c8f 100644 --- a/builder/vmware/iso/step_export.go +++ b/builder/vmware/iso/step_export.go @@ -14,13 +14,17 @@ import ( "github.com/hashicorp/packer/packer" ) +// This step exports a VM built on ESXi using ovftool +// +// Uses: +// display_name string type StepExport struct { Format string SkipExport bool OutputDir string } -func (s *StepExport) generateArgs(c *Config, hidePassword bool) []string { +func (s *StepExport) generateArgs(c *Config, displayName string, hidePassword bool) []string { password := url.QueryEscape(c.RemotePassword) if hidePassword { password = "****" @@ -29,7 +33,7 @@ func (s *StepExport) generateArgs(c *Config, hidePassword bool) []string { "--noSSLVerify=true", "--skipManifestCheck", "-tt=" + s.Format, - "vi://" + c.RemoteUser + ":" + password + "@" + c.RemoteHost + "/" + c.VMName, + "vi://" + c.RemoteUser + ":" + password + "@" + c.RemoteHost + "/" + displayName, s.OutputDir, } return append(c.OVFToolOptions, args...) @@ -72,9 +76,13 @@ func (s *StepExport) Run(_ context.Context, state multistep.StateBag) multistep. } ui.Say("Exporting virtual machine...") - ui.Message(fmt.Sprintf("Executing: %s %s", ovftool, strings.Join(s.generateArgs(c, true), " "))) + var displayName string + if v, ok := state.GetOk("display_name"); ok { + displayName = v.(string) + } + ui.Message(fmt.Sprintf("Executing: %s %s", ovftool, strings.Join(s.generateArgs(c, displayName, true), " "))) var out bytes.Buffer - cmd := exec.Command(ovftool, s.generateArgs(c, false)...) + cmd := exec.Command(ovftool, s.generateArgs(c, displayName, false)...) cmd.Stdout = &out if err := cmd.Run(); err != nil { err := fmt.Errorf("Error exporting virtual machine: %s\n%s\n", err, out.String())