From 0680cb08e5ea3caa9543a0b8a4300591cb966162 Mon Sep 17 00:00:00 2001 From: Lee Date: Sat, 1 Jul 2017 00:19:27 +0100 Subject: [PATCH 1/2] Add support for temp_path directive to override systemp %temp% --- builder/hyperv/common/step_create_tempdir.go | 15 ++++++++++----- builder/hyperv/iso/builder.go | 5 ++++- website/source/docs/builders/hyperv-iso.html.md | 3 +++ 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/builder/hyperv/common/step_create_tempdir.go b/builder/hyperv/common/step_create_tempdir.go index 269ba4eae..c1ca46fa2 100644 --- a/builder/hyperv/common/step_create_tempdir.go +++ b/builder/hyperv/common/step_create_tempdir.go @@ -2,14 +2,16 @@ package common import ( "fmt" - "github.com/hashicorp/packer/packer" - "github.com/mitchellh/multistep" "io/ioutil" "os" + + "github.com/hashicorp/packer/packer" + "github.com/mitchellh/multistep" ) type StepCreateTempDir struct { - dirPath string + TempPath string + dirPath string } func (s *StepCreateTempDir) Run(state multistep.StateBag) multistep.StepAction { @@ -17,8 +19,11 @@ func (s *StepCreateTempDir) Run(state multistep.StateBag) multistep.StepAction { ui.Say("Creating temporary directory...") - tempDir := os.TempDir() - packerTempDir, err := ioutil.TempDir(tempDir, "packerhv") + if s.TempPath == "" { + s.TempPath = os.TempDir() + } + + packerTempDir, err := ioutil.TempDir(s.TempPath, "packerhv") if err != nil { err := fmt.Errorf("Error creating temporary directory: %s", err) state.Put("error", err) diff --git a/builder/hyperv/iso/builder.go b/builder/hyperv/iso/builder.go index cd73c4873..48d1aa938 100644 --- a/builder/hyperv/iso/builder.go +++ b/builder/hyperv/iso/builder.go @@ -90,6 +90,7 @@ type Config struct { EnableDynamicMemory bool `mapstructure:"enable_dynamic_memory"` EnableSecureBoot bool `mapstructure:"enable_secure_boot"` EnableVirtualizationExtensions bool `mapstructure:"enable_virtualization_extensions"` + TempPath string `mapstructure:"temp_path"` Communicator string `mapstructure:"communicator"` @@ -303,7 +304,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe state.Put("ui", ui) steps := []multistep.Step{ - &hypervcommon.StepCreateTempDir{}, + &hypervcommon.StepCreateTempDir{ + TempPath: b.config.TempPath, + }, &hypervcommon.StepOutputDir{ Force: b.config.PackerForce, Path: b.config.OutputDir, diff --git a/website/source/docs/builders/hyperv-iso.html.md b/website/source/docs/builders/hyperv-iso.html.md index c7dee3e89..b06c0a191 100644 --- a/website/source/docs/builders/hyperv-iso.html.md +++ b/website/source/docs/builders/hyperv-iso.html.md @@ -197,6 +197,9 @@ can be configured for this builder. machine, without the file extension. By default this is "packer-BUILDNAME", where "BUILDNAME" is the name of the build. +- `temp_path` (string) - This is the temporary path in which Packer will create the virtual + machine + ## Boot Command The `boot_command` configuration is very important: it specifies the keys From 599b8882780bb7d8a2c245117d0eb0785332c2f6 Mon Sep 17 00:00:00 2001 From: Lee Date: Sat, 1 Jul 2017 00:29:18 +0100 Subject: [PATCH 2/2] Update docs to indicate default path --- website/source/docs/builders/hyperv-iso.html.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/source/docs/builders/hyperv-iso.html.md b/website/source/docs/builders/hyperv-iso.html.md index b06c0a191..97099c31c 100644 --- a/website/source/docs/builders/hyperv-iso.html.md +++ b/website/source/docs/builders/hyperv-iso.html.md @@ -198,7 +198,7 @@ can be configured for this builder. where "BUILDNAME" is the name of the build. - `temp_path` (string) - This is the temporary path in which Packer will create the virtual - machine + machine. Default value is system `%temp%` ## Boot Command