From 5014e46b4835fa7acea11fe412638e6d450166fe Mon Sep 17 00:00:00 2001 From: Michael Kuzmin Date: Tue, 18 Dec 2018 20:51:56 +0300 Subject: [PATCH] Add 'cpu_cores' parameter (#198) --- clone/builder_acc_test.go | 6 ++++++ common/step_hardware.go | 2 ++ driver/vm.go | 2 ++ iso/builder_acc_test.go | 6 ++++++ 4 files changed, 16 insertions(+) diff --git a/clone/builder_acc_test.go b/clone/builder_acc_test.go index 9f37fc4e3..2b7cb8e70 100644 --- a/clone/builder_acc_test.go +++ b/clone/builder_acc_test.go @@ -333,6 +333,7 @@ func TestCloneBuilderAcc_hardware(t *testing.T) { func hardwareConfig() string { config := defaultConfig() config["CPUs"] = 2 + config["cpu_cores"] = 2 config["CPU_reservation"] = 1000 config["CPU_limit"] = 1500 config["RAM"] = 2048 @@ -359,6 +360,11 @@ func checkHardware(t *testing.T) builderT.TestCheckFunc { t.Errorf("VM should have 2 CPU sockets, got %v", cpuSockets) } + cpuCores := vmInfo.Config.Hardware.NumCoresPerSocket + if cpuCores != 2 { + t.Errorf("VM should have 2 CPU cores per socket, got %v", cpuCores) + } + cpuReservation := *vmInfo.Config.CpuAllocation.Reservation if cpuReservation != 1000 { t.Errorf("VM should have CPU reservation for 1000 Mhz, got %v", cpuReservation) diff --git a/common/step_hardware.go b/common/step_hardware.go index e9225a6f6..00f1f2fbd 100644 --- a/common/step_hardware.go +++ b/common/step_hardware.go @@ -10,6 +10,7 @@ import ( type HardwareConfig struct { CPUs int32 `mapstructure:"CPUs"` + CpuCores int32 `mapstructure:"cpu_cores"` CPUReservation int64 `mapstructure:"CPU_reservation"` CPULimit int64 `mapstructure:"CPU_limit"` CpuHotAddEnabled bool `mapstructure:"CPU_hot_plug"` @@ -46,6 +47,7 @@ func (s *StepConfigureHardware) Run(_ context.Context, state multistep.StateBag) err := vm.Configure(&driver.HardwareConfig{ CPUs: s.Config.CPUs, + CpuCores: s.Config.CpuCores, CPUReservation: s.Config.CPUReservation, CPULimit: s.Config.CPULimit, RAM: s.Config.RAM, diff --git a/driver/vm.go b/driver/vm.go index f5af74d20..3390621ef 100644 --- a/driver/vm.go +++ b/driver/vm.go @@ -29,6 +29,7 @@ type CloneConfig struct { type HardwareConfig struct { CPUs int32 + CpuCores int32 CPUReservation int64 CPULimit int64 RAM int64 @@ -259,6 +260,7 @@ func (vm *VirtualMachine) Destroy() error { func (vm *VirtualMachine) Configure(config *HardwareConfig) error { var confSpec types.VirtualMachineConfigSpec confSpec.NumCPUs = config.CPUs + confSpec.NumCoresPerSocket = config.CpuCores confSpec.MemoryMB = config.RAM var cpuSpec types.ResourceAllocationInfo diff --git a/iso/builder_acc_test.go b/iso/builder_acc_test.go index 40a1a8e0f..222a21f79 100644 --- a/iso/builder_acc_test.go +++ b/iso/builder_acc_test.go @@ -155,6 +155,7 @@ func TestISOBuilderAcc_hardware(t *testing.T) { func hardwareConfig() string { config := defaultConfig() config["CPUs"] = 2 + config["cpu_cores"] = 2 config["CPU_reservation"] = 1000 config["CPU_limit"] = 1500 config["RAM"] = 2048 @@ -181,6 +182,11 @@ func checkHardware(t *testing.T) builderT.TestCheckFunc { t.Errorf("VM should have 2 CPU sockets, got %v", cpuSockets) } + cpuCores := vmInfo.Config.Hardware.NumCoresPerSocket + if cpuCores != 2 { + t.Errorf("VM should have 2 CPU cores per socket, got %v", cpuCores) + } + cpuReservation := *vmInfo.Config.CpuAllocation.Reservation if cpuReservation != 1000 { t.Errorf("VM should have CPU reservation for 1000 Mhz, got %v", cpuReservation)