Add new config options for setting CPU and Memory Hot Add (#71)
This commit is contained in:
parent
778f32da89
commit
13a6aa2c3c
|
@ -327,6 +327,8 @@ func hardwareConfig() string {
|
|||
config["CPU_limit"] = 1500
|
||||
config["RAM"] = 2048
|
||||
config["RAM_reservation"] = 1024
|
||||
config["CPU_hot_plug"] = true
|
||||
config["RAM_hot_plug"] = true
|
||||
|
||||
return commonT.RenderConfig(config)
|
||||
}
|
||||
|
@ -366,6 +368,16 @@ func checkHardware(t *testing.T) builderT.TestCheckFunc {
|
|||
t.Errorf("VM should have RAM reservation for 1024 MB, got %v", ramReservation)
|
||||
}
|
||||
|
||||
cpuHotAdd := vmInfo.Config.CpuHotAddEnabled
|
||||
if !*cpuHotAdd {
|
||||
t.Errorf("VM should have CPU hot add enabled, got %v", cpuHotAdd)
|
||||
}
|
||||
|
||||
memoryHotAdd := vmInfo.Config.MemoryHotAddEnabled
|
||||
if !*memoryHotAdd {
|
||||
t.Errorf("VM should have Memory hot add enabled, got %v", memoryHotAdd)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,14 +19,16 @@ func (s *StepConfigureHardware) Run(state multistep.StateBag) multistep.StepActi
|
|||
ui.Say("Customizing hardware parameters...")
|
||||
|
||||
err := vm.Configure(&driver.HardwareConfig{
|
||||
CPUs: s.config.CPUs,
|
||||
CPUReservation: s.config.CPUReservation,
|
||||
CPULimit: s.config.CPULimit,
|
||||
RAM: s.config.RAM,
|
||||
RAMReservation: s.config.RAMReservation,
|
||||
RAMReserveAll: s.config.RAMReserveAll,
|
||||
DiskSize: s.config.DiskSize,
|
||||
NestedHV: s.config.NestedHV,
|
||||
CPUs: s.config.CPUs,
|
||||
CPUReservation: s.config.CPUReservation,
|
||||
CPULimit: s.config.CPULimit,
|
||||
RAM: s.config.RAM,
|
||||
RAMReservation: s.config.RAMReservation,
|
||||
RAMReserveAll: s.config.RAMReserveAll,
|
||||
DiskSize: s.config.DiskSize,
|
||||
NestedHV: s.config.NestedHV,
|
||||
CpuHotAddEnabled: s.config.CpuHotAddEnabled,
|
||||
MemoryHotAddEnabled: s.config.MemoryHotAddEnabled,
|
||||
})
|
||||
if err != nil {
|
||||
state.Put("error", err)
|
||||
|
|
|
@ -6,14 +6,16 @@ import (
|
|||
)
|
||||
|
||||
type HardwareConfig struct {
|
||||
CPUs int32 `mapstructure:"CPUs"`
|
||||
CPUReservation int64 `mapstructure:"CPU_reservation"`
|
||||
CPULimit int64 `mapstructure:"CPU_limit"`
|
||||
RAM int64 `mapstructure:"RAM"`
|
||||
RAMReservation int64 `mapstructure:"RAM_reservation"`
|
||||
RAMReserveAll bool `mapstructure:"RAM_reserve_all"`
|
||||
DiskSize int64 `mapstructure:"disk_size"`
|
||||
NestedHV bool `mapstructure:"NestedHV"`
|
||||
CPUs int32 `mapstructure:"CPUs"`
|
||||
CPUReservation int64 `mapstructure:"CPU_reservation"`
|
||||
CPULimit int64 `mapstructure:"CPU_limit"`
|
||||
RAM int64 `mapstructure:"RAM"`
|
||||
RAMReservation int64 `mapstructure:"RAM_reservation"`
|
||||
RAMReserveAll bool `mapstructure:"RAM_reserve_all"`
|
||||
DiskSize int64 `mapstructure:"disk_size"`
|
||||
NestedHV bool `mapstructure:"NestedHV"`
|
||||
CpuHotAddEnabled bool `mapstructure:"CPU_hot_plug"`
|
||||
MemoryHotAddEnabled bool `mapstructure:"RAM_hot_plug"`
|
||||
}
|
||||
|
||||
func (c *HardwareConfig) Prepare() []error {
|
||||
|
@ -28,12 +30,14 @@ func (c *HardwareConfig) Prepare() []error {
|
|||
|
||||
func (c *HardwareConfig) ToDriverHardwareConfig() driver.HardwareConfig {
|
||||
return driver.HardwareConfig{
|
||||
CPUs: c.CPUs,
|
||||
CPUReservation: c.CPUReservation,
|
||||
CPULimit: c.CPULimit,
|
||||
RAM: c.RAM,
|
||||
RAMReservation: c.RAMReservation,
|
||||
RAMReserveAll: c.RAMReserveAll,
|
||||
DiskSize: c.DiskSize,
|
||||
CPUs: c.CPUs,
|
||||
CPUReservation: c.CPUReservation,
|
||||
CPULimit: c.CPULimit,
|
||||
RAM: c.RAM,
|
||||
RAMReservation: c.RAMReservation,
|
||||
RAMReserveAll: c.RAMReserveAll,
|
||||
DiskSize: c.DiskSize,
|
||||
CpuHotAddEnabled: c.CpuHotAddEnabled,
|
||||
MemoryHotAddEnabled: c.MemoryHotAddEnabled,
|
||||
}
|
||||
}
|
||||
|
|
21
driver/vm.go
21
driver/vm.go
|
@ -26,14 +26,16 @@ type CloneConfig struct {
|
|||
}
|
||||
|
||||
type HardwareConfig struct {
|
||||
CPUs int32
|
||||
CPUReservation int64
|
||||
CPULimit int64
|
||||
RAM int64
|
||||
RAMReservation int64
|
||||
RAMReserveAll bool
|
||||
DiskSize int64
|
||||
NestedHV bool
|
||||
CPUs int32
|
||||
CPUReservation int64
|
||||
CPULimit int64
|
||||
RAM int64
|
||||
RAMReservation int64
|
||||
RAMReserveAll bool
|
||||
DiskSize int64
|
||||
NestedHV bool
|
||||
CpuHotAddEnabled bool
|
||||
MemoryHotAddEnabled bool
|
||||
}
|
||||
|
||||
type CreateConfig struct {
|
||||
|
@ -389,6 +391,9 @@ func (config HardwareConfig) toConfigSpec() types.VirtualMachineConfigSpec {
|
|||
confSpec.MemoryReservationLockedToMax = &config.RAMReserveAll
|
||||
confSpec.NestedHVEnabled = &config.NestedHV
|
||||
|
||||
confSpec.CpuHotAddEnabled = &config.CpuHotAddEnabled
|
||||
confSpec.MemoryHotAddEnabled = &config.MemoryHotAddEnabled
|
||||
|
||||
return confSpec
|
||||
}
|
||||
|
||||
|
|
|
@ -115,11 +115,13 @@ func cloneDefaultCheck(t *testing.T, vm *VirtualMachine, config *CloneConfig) {
|
|||
func configureCheck(t *testing.T, vm *VirtualMachine, _ *CloneConfig) {
|
||||
log.Printf("[DEBUG] Configuring the vm")
|
||||
hwConfig := &HardwareConfig{
|
||||
CPUs: 2,
|
||||
CPUReservation: 1000,
|
||||
CPULimit: 1500,
|
||||
RAM: 2048,
|
||||
RAMReservation: 1024,
|
||||
CPUs: 2,
|
||||
CPUReservation: 1000,
|
||||
CPULimit: 1500,
|
||||
RAM: 2048,
|
||||
RAMReservation: 1024,
|
||||
MemoryHotAddEnabled: true,
|
||||
CpuHotAddEnabled: true,
|
||||
}
|
||||
vm.Configure(hwConfig)
|
||||
|
||||
|
@ -153,6 +155,16 @@ func configureCheck(t *testing.T, vm *VirtualMachine, _ *CloneConfig) {
|
|||
if ramReservation != hwConfig.RAMReservation {
|
||||
t.Errorf("VM should have RAM reservation for %v MB, got %v", hwConfig.RAMReservation, ramReservation)
|
||||
}
|
||||
|
||||
cpuHotAdd := vmInfo.Config.CpuHotAddEnabled
|
||||
if *cpuHotAdd != hwConfig.CpuHotAddEnabled {
|
||||
t.Errorf("VM should have CPU hot add set to %v, got %v", hwConfig.CpuHotAddEnabled, cpuHotAdd)
|
||||
}
|
||||
|
||||
memoryHotAdd := vmInfo.Config.MemoryHotAddEnabled
|
||||
if *memoryHotAdd != hwConfig.MemoryHotAddEnabled {
|
||||
t.Errorf("VM should have Memroy hot add set to %v, got %v", hwConfig.MemoryHotAddEnabled, memoryHotAdd)
|
||||
}
|
||||
}
|
||||
|
||||
func configureRAMReserveAllCheck(t *testing.T, vm *VirtualMachine, _ *CloneConfig) {
|
||||
|
|
Loading…
Reference in New Issue