Replace export output dir in state bag with params
step_export now has the OutputDir as a param instead of getting it from the state bag, on the advice of @mwhooker in PR comment
This commit is contained in:
parent
e851efb1b6
commit
1e9b0f7b8f
|
@ -215,7 +215,6 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
|||
state.Put("debug", b.config.PackerDebug)
|
||||
state.Put("dir", dir)
|
||||
state.Put("driver", driver)
|
||||
state.Put("exportPath", exportOutputPath)
|
||||
state.Put("hook", hook)
|
||||
state.Put("ui", ui)
|
||||
|
||||
|
@ -309,6 +308,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
|||
&StepExport{
|
||||
Format: b.config.Format,
|
||||
SkipExport: b.config.SkipExport,
|
||||
OutputDir: exportOutputPath,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -16,9 +16,10 @@ import (
|
|||
type StepExport struct {
|
||||
Format string
|
||||
SkipExport bool
|
||||
OutputDir string
|
||||
}
|
||||
|
||||
func (s *StepExport) generateArgs(c *Config, outputPath string, hidePassword bool) []string {
|
||||
func (s *StepExport) generateArgs(c *Config, hidePassword bool) []string {
|
||||
password := url.QueryEscape(c.RemotePassword)
|
||||
if hidePassword {
|
||||
password = "****"
|
||||
|
@ -28,7 +29,7 @@ func (s *StepExport) generateArgs(c *Config, outputPath string, hidePassword boo
|
|||
"--skipManifestCheck",
|
||||
"-tt=" + s.Format,
|
||||
"vi://" + c.RemoteUser + ":" + password + "@" + c.RemoteHost + "/" + c.VMName,
|
||||
outputPath,
|
||||
s.OutputDir,
|
||||
}
|
||||
return append(c.OVFToolOptions, args...)
|
||||
}
|
||||
|
@ -60,16 +61,18 @@ func (s *StepExport) Run(state multistep.StateBag) multistep.StepAction {
|
|||
}
|
||||
|
||||
// Export the VM
|
||||
outputPath := state.Get("exportPath").(string)
|
||||
if s.OutputDir == "" {
|
||||
s.OutputDir = c.VMName + "." + s.Format
|
||||
}
|
||||
|
||||
if s.Format == "ova" {
|
||||
os.MkdirAll(outputPath, 0755)
|
||||
os.MkdirAll(s.OutputDir, 0755)
|
||||
}
|
||||
|
||||
ui.Say("Exporting virtual machine...")
|
||||
ui.Message(fmt.Sprintf("Executing: %s %s", ovftool, strings.Join(s.generateArgs(c, outputPath, true), " ")))
|
||||
ui.Message(fmt.Sprintf("Executing: %s %s", ovftool, strings.Join(s.generateArgs(c, true), " ")))
|
||||
var out bytes.Buffer
|
||||
cmd := exec.Command(ovftool, s.generateArgs(c, outputPath, false)...)
|
||||
cmd := exec.Command(ovftool, s.generateArgs(c, false)...)
|
||||
cmd.Stdout = &out
|
||||
if err := cmd.Run(); err != nil {
|
||||
err := fmt.Errorf("Error exporting virtual machine: %s\n%s\n", err, out.String())
|
||||
|
|
Loading…
Reference in New Issue