Adding support for nested Hyper-V

This commit is contained in:
Patrick Lang 2016-08-05 23:09:33 -07:00 committed by Taliesin Sisson
parent f94c2cd2f7
commit 6d391fc34a
3 changed files with 10 additions and 7 deletions

View File

@ -22,7 +22,7 @@ type StepCreateVM struct {
Generation uint
Cpu uint
EnableSecureBoot bool
ExposeVirtualizationExtensions bool
EnableVirtualizationExtensions bool
}
func (s *StepCreateVM) Run(state multistep.StateBag) multistep.StepAction {
@ -47,7 +47,7 @@ func (s *StepCreateVM) Run(state multistep.StateBag) multistep.StepAction {
return multistep.ActionHalt
}
err = driver.SetVirtualMachineCpu(s.VMName, s.Cpu, s.ExposeVirtualizationExtensions)
err = driver.SetVirtualMachineCpu(s.VMName, s.Cpu, s.EnableVirtualizationExtensions)
if err != nil {
err := fmt.Errorf("Error creating setting virtual machine cpu: %s", err)
state.Put("error", err)

View File

@ -89,7 +89,7 @@ type Config struct {
Cpu uint `mapstructure:"cpu"`
Generation uint `mapstructure:"generation"`
EnableSecureBoot bool `mapstructure:"enable_secure_boot"`
EnableVirtualizationExtensions `mapstructure:"enable_virtualization_extensions`
EnableVirtualizationExtensions bool `mapstructure:"enable_virtualization_extensions"`
Communicator string `mapstructure:"communicator"`
@ -299,7 +299,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
Generation: b.config.Generation,
Cpu: b.config.Cpu,
EnableSecureBoot: b.config.EnableSecureBoot,
EnableVirtualizationExtensions: b.config.EnableVirtualizationExtensions
EnableVirtualizationExtensions: b.config.EnableVirtualizationExtensions,
},
&hypervcommon.StepEnableIntegrationService{},

View File

@ -217,15 +217,18 @@ New-VM -Name $vmName -Path $path -MemoryStartupBytes $memoryStartupBytes -NewVHD
}
}
func SetVirtualMachineCpu(vmName string, cpu uint, exposeVirtualizationExtensions bool) error {
func SetVirtualMachineCpu(vmName string, cpu uint, enableVirtualizationExtensions bool) error {
var script = `
param([string]$vmName, [int]$cpu, [bool]$exposeVirtualizationExtensions)
Set-VMProcessor -VMName $vmName -Count $cpu -exposeVirtualizationExtensions $exposeVirtualizationExtensions
`
exposeVirtualizationExtensionsString := "$False"
if enableVirtualizationExtensions {
exposeVirtualizationExtensionsString = "$True"
}
var ps powershell.PowerShellCmd
err := ps.Run(script, vmName, strconv.FormatInt(int64(cpu), 10))
err := ps.Run(script, vmName, strconv.FormatInt(int64(cpu), 10), exposeVirtualizationExtensionsString)
return err
}