From 56c56282058c748f2a748718c35a11c93370dcbb Mon Sep 17 00:00:00 2001 From: Matthew Hooker Date: Mon, 23 Jan 2017 17:47:35 -0800 Subject: [PATCH 1/7] builder/vmware-iso: set ovftool output path --- builder/vmware/iso/step_export.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builder/vmware/iso/step_export.go b/builder/vmware/iso/step_export.go index 974c89852..13f5cf77f 100644 --- a/builder/vmware/iso/step_export.go +++ b/builder/vmware/iso/step_export.go @@ -59,7 +59,7 @@ func (s *StepExport) Run(state multistep.StateBag) multistep.StepAction { } // Export the VM - outputPath := filepath.Join(c.VMName, c.VMName+"."+s.Format) + outputPath := filepath.Join(c.OutputDir, c.VMName+"."+s.Format) if s.Format == "ova" { os.MkdirAll(outputPath, 0755) From f8df5f81dbc3851090122db31d30afe2e17c0701 Mon Sep 17 00:00:00 2001 From: Jimmy The Dog Date: Fri, 24 Feb 2017 12:46:00 +0000 Subject: [PATCH 2/7] builder/vmware-iso: set local output dir --- builder/vmware/iso/builder.go | 4 ++++ builder/vmware/iso/step_export.go | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/builder/vmware/iso/builder.go b/builder/vmware/iso/builder.go index 10fce5911..6f512ac82 100755 --- a/builder/vmware/iso/builder.go +++ b/builder/vmware/iso/builder.go @@ -199,7 +199,10 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe default: dir = new(vmwcommon.LocalOutputDir) } + + var localDir localOutputDir if b.config.RemoteType != "" && b.config.Format != "" { + localDir = localOutputDir{b.config.OutputDir} b.config.OutputDir = b.config.VMName } dir.SetOutputDir(b.config.OutputDir) @@ -210,6 +213,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe state.Put("config", &b.config) state.Put("debug", b.config.PackerDebug) state.Put("dir", dir) + state.Put("localDir", localDir) state.Put("driver", driver) state.Put("hook", hook) state.Put("ui", ui) diff --git a/builder/vmware/iso/step_export.go b/builder/vmware/iso/step_export.go index 13f5cf77f..b7fcbd24c 100644 --- a/builder/vmware/iso/step_export.go +++ b/builder/vmware/iso/step_export.go @@ -59,7 +59,8 @@ func (s *StepExport) Run(state multistep.StateBag) multistep.StepAction { } // Export the VM - outputPath := filepath.Join(c.OutputDir, c.VMName+"."+s.Format) + localDir := state.Get("localDir").(localOutputDir) + outputPath := filepath.Join(fmt.Sprintf("%v", localDir), c.VMName+"."+s.Format) if s.Format == "ova" { os.MkdirAll(outputPath, 0755) From 7a2b30dcc44107560c89421fa4f1774b90e768ff Mon Sep 17 00:00:00 2001 From: Jimmy The Dog Date: Fri, 24 Feb 2017 13:18:28 +0000 Subject: [PATCH 3/7] builder/vmware-iso: need to always set local output dir, or non-remote build exports will fail --- builder/vmware/iso/builder.go | 4 ++-- builder/vmware/iso/step_export.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/builder/vmware/iso/builder.go b/builder/vmware/iso/builder.go index 6f512ac82..163d90184 100755 --- a/builder/vmware/iso/builder.go +++ b/builder/vmware/iso/builder.go @@ -200,9 +200,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe dir = new(vmwcommon.LocalOutputDir) } - var localDir localOutputDir + localDir := localOutputDir{b.config.OutputDir} + log.Printf("b.config.OutputDir: %s, localDir: %s", b.config.OutputDir, localDir.dir) if b.config.RemoteType != "" && b.config.Format != "" { - localDir = localOutputDir{b.config.OutputDir} b.config.OutputDir = b.config.VMName } dir.SetOutputDir(b.config.OutputDir) diff --git a/builder/vmware/iso/step_export.go b/builder/vmware/iso/step_export.go index b7fcbd24c..c3ba3024a 100644 --- a/builder/vmware/iso/step_export.go +++ b/builder/vmware/iso/step_export.go @@ -60,7 +60,7 @@ func (s *StepExport) Run(state multistep.StateBag) multistep.StepAction { // Export the VM localDir := state.Get("localDir").(localOutputDir) - outputPath := filepath.Join(fmt.Sprintf("%v", localDir), c.VMName+"."+s.Format) + outputPath := filepath.Join(localDir.dir, c.VMName+"."+s.Format) if s.Format == "ova" { os.MkdirAll(outputPath, 0755) From 14810523b8aaf7f72951de2bbb42ce32d7981e7b Mon Sep 17 00:00:00 2001 From: Jimmy The Dog Date: Fri, 24 Feb 2017 14:48:38 +0000 Subject: [PATCH 4/7] builder/vmware-iso: get artifact files from local dir --- builder/vmware/iso/builder.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builder/vmware/iso/builder.go b/builder/vmware/iso/builder.go index 163d90184..877b779ff 100755 --- a/builder/vmware/iso/builder.go +++ b/builder/vmware/iso/builder.go @@ -333,7 +333,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(localDir.dir) files, err = dir.ListFiles() } else { files, err = state.Get("dir").(OutputDir).ListFiles() From ce41055ac6b19c8040de9d8ec01e95eefeded5c2 Mon Sep 17 00:00:00 2001 From: Jimmy The Dog Date: Fri, 24 Feb 2017 14:49:40 +0000 Subject: [PATCH 5/7] builder/vmware-iso: do not append to output dir, as ovftool does that --- builder/vmware/iso/step_export.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/builder/vmware/iso/step_export.go b/builder/vmware/iso/step_export.go index c3ba3024a..1e43d12fd 100644 --- a/builder/vmware/iso/step_export.go +++ b/builder/vmware/iso/step_export.go @@ -8,7 +8,6 @@ import ( "net/url" "os" "os/exec" - "path/filepath" "runtime" "strings" ) @@ -60,7 +59,7 @@ func (s *StepExport) Run(state multistep.StateBag) multistep.StepAction { // Export the VM localDir := state.Get("localDir").(localOutputDir) - outputPath := filepath.Join(localDir.dir, c.VMName+"."+s.Format) + outputPath := localDir.dir if s.Format == "ova" { os.MkdirAll(outputPath, 0755) From e851efb1b6e176176dd6498a310f5e62b0d5f33a Mon Sep 17 00:00:00 2001 From: Jimmy The Dog Date: Fri, 10 Mar 2017 08:20:48 +0000 Subject: [PATCH 6/7] Set export_dir to the output_dir property --- builder/vmware/iso/builder.go | 8 ++++---- builder/vmware/iso/step_export.go | 5 +---- 2 files changed, 5 insertions(+), 8 deletions(-) mode change 100755 => 100644 builder/vmware/iso/builder.go diff --git a/builder/vmware/iso/builder.go b/builder/vmware/iso/builder.go old mode 100755 new mode 100644 index 6eb6a30f1..b01cb1f32 --- a/builder/vmware/iso/builder.go +++ b/builder/vmware/iso/builder.go @@ -201,8 +201,8 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe dir = new(vmwcommon.LocalOutputDir) } - localDir := localOutputDir{b.config.OutputDir} - log.Printf("b.config.OutputDir: %s, localDir: %s", b.config.OutputDir, localDir.dir) + exportOutputPath := b.config.OutputDir + if b.config.RemoteType != "" && b.config.Format != "" { b.config.OutputDir = b.config.VMName } @@ -214,8 +214,8 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe state.Put("config", &b.config) state.Put("debug", b.config.PackerDebug) state.Put("dir", dir) - state.Put("localDir", localDir) state.Put("driver", driver) + state.Put("exportPath", exportOutputPath) state.Put("hook", hook) state.Put("ui", ui) @@ -334,7 +334,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(localDir.dir) + dir.SetOutputDir(exportOutputPath) files, err = dir.ListFiles() } else { files, err = state.Get("dir").(OutputDir).ListFiles() diff --git a/builder/vmware/iso/step_export.go b/builder/vmware/iso/step_export.go index 67a12a570..04c526aae 100644 --- a/builder/vmware/iso/step_export.go +++ b/builder/vmware/iso/step_export.go @@ -60,8 +60,7 @@ func (s *StepExport) Run(state multistep.StateBag) multistep.StepAction { } // Export the VM - localDir := state.Get("localDir").(localOutputDir) - outputPath := localDir.dir + outputPath := state.Get("exportPath").(string) if s.Format == "ova" { os.MkdirAll(outputPath, 0755) @@ -81,8 +80,6 @@ func (s *StepExport) Run(state multistep.StateBag) multistep.StepAction { ui.Message(fmt.Sprintf("%s", out.String())) - state.Put("exportPath", outputPath) - return multistep.ActionContinue } From 1e9b0f7b8f7bdff29c10b8c0934aa904999b2561 Mon Sep 17 00:00:00 2001 From: Jimmy The Dog Date: Fri, 10 Mar 2017 10:43:45 +0000 Subject: [PATCH 7/7] 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 --- builder/vmware/iso/builder.go | 2 +- builder/vmware/iso/step_export.go | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/builder/vmware/iso/builder.go b/builder/vmware/iso/builder.go index b01cb1f32..9a0738842 100644 --- a/builder/vmware/iso/builder.go +++ b/builder/vmware/iso/builder.go @@ -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, }, } diff --git a/builder/vmware/iso/step_export.go b/builder/vmware/iso/step_export.go index 04c526aae..d8c91f82c 100644 --- a/builder/vmware/iso/step_export.go +++ b/builder/vmware/iso/step_export.go @@ -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())