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 ( import (
"fmt" "fmt"
"github.com/hashicorp/packer/packer"
"github.com/mitchellh/multistep"
"io/ioutil" "io/ioutil"
"os" "os"
"github.com/hashicorp/packer/packer"
"github.com/mitchellh/multistep"
) )
type StepCreateTempDir struct { type StepCreateTempDir struct {
dirPath string TempPath string
dirPath string
} }
func (s *StepCreateTempDir) Run(state multistep.StateBag) multistep.StepAction { 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...") ui.Say("Creating temporary directory...")
tempDir := os.TempDir() if s.TempPath == "" {
packerTempDir, err := ioutil.TempDir(tempDir, "packerhv") s.TempPath = os.TempDir()
}
packerTempDir, err := ioutil.TempDir(s.TempPath, "packerhv")
if err != nil { if err != nil {
err := fmt.Errorf("Error creating temporary directory: %s", err) err := fmt.Errorf("Error creating temporary directory: %s", err)
state.Put("error", err) state.Put("error", err)

View File

@ -80,6 +80,7 @@ type Config struct {
EnableDynamicMemory bool `mapstructure:"enable_dynamic_memory"` EnableDynamicMemory bool `mapstructure:"enable_dynamic_memory"`
EnableSecureBoot bool `mapstructure:"enable_secure_boot"` EnableSecureBoot bool `mapstructure:"enable_secure_boot"`
EnableVirtualizationExtensions bool `mapstructure:"enable_virtualization_extensions"` EnableVirtualizationExtensions bool `mapstructure:"enable_virtualization_extensions"`
TempPath string `mapstructure:"temp_path"`
Communicator string `mapstructure:"communicator"` 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) state.Put("ui", ui)
steps := []multistep.Step{ steps := []multistep.Step{
&hypervcommon.StepCreateTempDir{}, &hypervcommon.StepCreateTempDir{
TempPath: b.config.TempPath,
},
&hypervcommon.StepOutputDir{ &hypervcommon.StepOutputDir{
Force: b.config.PackerForce, Force: b.config.PackerForce,
Path: b.config.OutputDir, 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", machine, without the file extension. By default this is "packer-BUILDNAME",
where "BUILDNAME" is the name of the build. 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 ## Boot Command
The `boot_command` configuration is very important: it specifies the keys The `boot_command` configuration is very important: it specifies the keys