Adding support for nested Hyper-V
This commit is contained in:
parent
f94c2cd2f7
commit
6d391fc34a
|
@ -22,7 +22,7 @@ type StepCreateVM struct {
|
||||||
Generation uint
|
Generation uint
|
||||||
Cpu uint
|
Cpu uint
|
||||||
EnableSecureBoot bool
|
EnableSecureBoot bool
|
||||||
ExposeVirtualizationExtensions bool
|
EnableVirtualizationExtensions bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StepCreateVM) Run(state multistep.StateBag) multistep.StepAction {
|
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
|
return multistep.ActionHalt
|
||||||
}
|
}
|
||||||
|
|
||||||
err = driver.SetVirtualMachineCpu(s.VMName, s.Cpu, s.ExposeVirtualizationExtensions)
|
err = driver.SetVirtualMachineCpu(s.VMName, s.Cpu, s.EnableVirtualizationExtensions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err := fmt.Errorf("Error creating setting virtual machine cpu: %s", err)
|
err := fmt.Errorf("Error creating setting virtual machine cpu: %s", err)
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
|
|
|
@ -89,7 +89,7 @@ type Config struct {
|
||||||
Cpu uint `mapstructure:"cpu"`
|
Cpu uint `mapstructure:"cpu"`
|
||||||
Generation uint `mapstructure:"generation"`
|
Generation uint `mapstructure:"generation"`
|
||||||
EnableSecureBoot bool `mapstructure:"enable_secure_boot"`
|
EnableSecureBoot bool `mapstructure:"enable_secure_boot"`
|
||||||
EnableVirtualizationExtensions `mapstructure:"enable_virtualization_extensions`
|
EnableVirtualizationExtensions bool `mapstructure:"enable_virtualization_extensions"`
|
||||||
|
|
||||||
Communicator string `mapstructure:"communicator"`
|
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,
|
Generation: b.config.Generation,
|
||||||
Cpu: b.config.Cpu,
|
Cpu: b.config.Cpu,
|
||||||
EnableSecureBoot: b.config.EnableSecureBoot,
|
EnableSecureBoot: b.config.EnableSecureBoot,
|
||||||
EnableVirtualizationExtensions: b.config.EnableVirtualizationExtensions
|
EnableVirtualizationExtensions: b.config.EnableVirtualizationExtensions,
|
||||||
},
|
},
|
||||||
&hypervcommon.StepEnableIntegrationService{},
|
&hypervcommon.StepEnableIntegrationService{},
|
||||||
|
|
||||||
|
|
|
@ -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 = `
|
var script = `
|
||||||
param([string]$vmName, [int]$cpu, [bool]$exposeVirtualizationExtensions)
|
param([string]$vmName, [int]$cpu, [bool]$exposeVirtualizationExtensions)
|
||||||
Set-VMProcessor -VMName $vmName -Count $cpu -exposeVirtualizationExtensions $exposeVirtualizationExtensions
|
Set-VMProcessor -VMName $vmName -Count $cpu -exposeVirtualizationExtensions $exposeVirtualizationExtensions
|
||||||
`
|
`
|
||||||
|
exposeVirtualizationExtensionsString := "$False"
|
||||||
|
if enableVirtualizationExtensions {
|
||||||
|
exposeVirtualizationExtensionsString = "$True"
|
||||||
|
}
|
||||||
var ps powershell.PowerShellCmd
|
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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue