Merge pull request #4592 from jimmythedog/ovfexportpath-localoutputdir
Ovfexportpath localoutputdir -- Merging for release with 1.1.0
This commit is contained in:
commit
e93d64e80f
|
@ -200,6 +200,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
|||
default:
|
||||
dir = new(vmwcommon.LocalOutputDir)
|
||||
}
|
||||
|
||||
exportOutputPath := b.config.OutputDir
|
||||
|
||||
if b.config.RemoteType != "" && b.config.Format != "" {
|
||||
b.config.OutputDir = b.config.VMName
|
||||
}
|
||||
|
@ -307,6 +310,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,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -332,7 +336,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
|||
var files []string
|
||||
if b.config.RemoteType != "" && b.config.Format != "" {
|
||||
dir = new(vmwcommon.LocalOutputDir)
|
||||
dir.SetOutputDir(b.config.OutputDir)
|
||||
dir.SetOutputDir(exportOutputPath)
|
||||
files, err = dir.ListFiles()
|
||||
} else {
|
||||
files, err = state.Get("dir").(OutputDir).ListFiles()
|
||||
|
|
|
@ -6,7 +6,6 @@ import (
|
|||
"net/url"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
|
@ -17,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 = "****"
|
||||
|
@ -29,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...)
|
||||
}
|
||||
|
@ -62,16 +62,18 @@ func (s *StepExport) Run(state multistep.StateBag) multistep.StepAction {
|
|||
}
|
||||
|
||||
// Export the VM
|
||||
outputPath := filepath.Join(c.VMName, c.VMName+"."+s.Format)
|
||||
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())
|
||||
|
@ -82,8 +84,6 @@ func (s *StepExport) Run(state multistep.StateBag) multistep.StepAction {
|
|||
|
||||
ui.Message(fmt.Sprintf("%s", out.String()))
|
||||
|
||||
state.Put("exportPath", outputPath)
|
||||
|
||||
return multistep.ActionContinue
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue