Merge pull request #5085 from Lee303/builder-hyperv-temppath

Hyper-V Builder - Add support for temp_path directive to override system %temp%
This commit is contained in:
Taliesin Sisson 2017-07-01 06:58:01 +01:00 committed by GitHub
commit 2325c1ee58
3 changed files with 17 additions and 6 deletions

View File

@ -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)

View File

@ -80,6 +80,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"`
@ -293,7 +294,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,

View File

@ -205,6 +205,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. Default value is system `%temp%`
## Boot Command
The `boot_command` configuration is very important: it specifies the keys