From 062c62eed8362876c51cb8d58933c740b9419166 Mon Sep 17 00:00:00 2001 From: Ali Rizvi-Santiago Date: Fri, 11 Jan 2019 18:58:57 -0600 Subject: [PATCH 1/6] Added support for specifying the number of cores as `cores` to vmware-common. --- builder/vmware/common/hw_config.go | 6 ++++++ builder/vmware/common/hw_config_test.go | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/builder/vmware/common/hw_config.go b/builder/vmware/common/hw_config.go index d740025c2..588d295f1 100644 --- a/builder/vmware/common/hw_config.go +++ b/builder/vmware/common/hw_config.go @@ -14,6 +14,7 @@ type HWConfig struct { // cpu information CpuCount int `mapstructure:"cpus"` MemorySize int `mapstructure:"memory"` + CoreCount int `mapstructure:"cores"` // network type and adapter Network string `mapstructure:"network"` @@ -40,6 +41,11 @@ func (c *HWConfig) Prepare(ctx *interpolate.Context) []error { errs = append(errs, fmt.Errorf("An invalid amount of memory was specified (memory < 0): %d", c.MemorySize)) } + // Hardware and cpu options + if c.CoreCount < 0 { + errs = append(errs, fmt.Errorf("An invalid number of cores was specified (cores < 0): %d", c.CoreCount)) + } + // Peripherals if !c.Sound { c.Sound = false diff --git a/builder/vmware/common/hw_config_test.go b/builder/vmware/common/hw_config_test.go index be884b144..3532dc1b9 100644 --- a/builder/vmware/common/hw_config_test.go +++ b/builder/vmware/common/hw_config_test.go @@ -8,6 +8,7 @@ import ( func testHWConfig() *HWConfig { return &HWConfig{ CpuCount: 1, + CoreCount: 1, MemorySize: 512, Sound: true, @@ -26,6 +27,10 @@ func TestHWConfigPrepare(t *testing.T) { t.Errorf("bad cpu count: %d", c.CpuCount) } + if c.CoreCount < 0 { + t.Errorf("bad core count: %d", c.CoreCount) + } + if c.MemorySize < 0 { t.Errorf("bad memory size: %d", c.MemorySize) } From 4894873971ce1a6fa0c64b7a3f5fc622c45fc97c Mon Sep 17 00:00:00 2001 From: Ali Rizvi-Santiago Date: Fri, 11 Jan 2019 19:00:54 -0600 Subject: [PATCH 2/6] Added logic to the vmware-iso builder that appends the number of cores per socket to the vmx in `stepCreateVmx`. --- builder/vmware/iso/step_create_vmx.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/builder/vmware/iso/step_create_vmx.go b/builder/vmware/iso/step_create_vmx.go index 5a46c14ef..d812aab49 100644 --- a/builder/vmware/iso/step_create_vmx.go +++ b/builder/vmware/iso/step_create_vmx.go @@ -429,12 +429,19 @@ func (s *stepCreateVMX) Run(_ context.Context, state multistep.StateBag) multist s.tempDir = vmxDir } - /// Now to handle options that will modify the template + /// Now to handle options that will modify the template without using "vmxTemplateData" vmxData := vmwcommon.ParseVMX(vmxContents) + + // If no cpus were specified, then remove the entry to use the default if vmxData["numvcpus"] == "" { delete(vmxData, "numvcpus") } + // If some number of cores were specified, then update "cpuid.coresPerSocket" with the requested value + if config.HWConfig.CoreCount > 0 { + vmxData["cpuid.corespersocket"] = strconv.Itoa(config.HWConfig.CoreCount) + } + /// Write the vmxData to the vmxPath vmxPath := filepath.Join(vmxDir, config.VMName+".vmx") if err := vmwcommon.WriteVMX(vmxPath, vmxData); err != nil { From 4d3f9cc1afe1c6c08286190f5ec620abca5ec192 Mon Sep 17 00:00:00 2001 From: Ali Rizvi-Santiago Date: Fri, 11 Jan 2019 19:06:49 -0600 Subject: [PATCH 3/6] Updated the documentation for the vmware-iso builder to describe the `cores` option. --- website/source/docs/builders/vmware-iso.html.md.erb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/website/source/docs/builders/vmware-iso.html.md.erb b/website/source/docs/builders/vmware-iso.html.md.erb index 12d0d77cc..180af5c08 100644 --- a/website/source/docs/builders/vmware-iso.html.md.erb +++ b/website/source/docs/builders/vmware-iso.html.md.erb @@ -100,6 +100,8 @@ builder. - `cpus` (number) - The number of cpus to use when building the VM. +- `cores` (number) - The number of cores per socket to use when building the VM. + - `cdrom_adapter_type` (string) - The adapter type (or bus) that will be used by the cdrom device. This is chosen by default based on the disk adapter type. VMware tends to lean towards `ide` for the cdrom device unless From 0c37a3c68fd859fd97ce645210d8bb4b19ae96dc Mon Sep 17 00:00:00 2001 From: Ali Rizvi-Santiago Date: Thu, 17 Jan 2019 10:38:19 -0600 Subject: [PATCH 4/6] Renamed the terse option, `cores`, to to the less-terse version `cores_per_socket`. --- builder/vmware/common/hw_config.go | 2 +- website/source/docs/builders/vmware-iso.html.md.erb | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/builder/vmware/common/hw_config.go b/builder/vmware/common/hw_config.go index 588d295f1..eb3ed46c2 100644 --- a/builder/vmware/common/hw_config.go +++ b/builder/vmware/common/hw_config.go @@ -14,7 +14,7 @@ type HWConfig struct { // cpu information CpuCount int `mapstructure:"cpus"` MemorySize int `mapstructure:"memory"` - CoreCount int `mapstructure:"cores"` + CoreCount int `mapstructure:"cores_per_socket"` // network type and adapter Network string `mapstructure:"network"` diff --git a/website/source/docs/builders/vmware-iso.html.md.erb b/website/source/docs/builders/vmware-iso.html.md.erb index 180af5c08..e7ecb350d 100644 --- a/website/source/docs/builders/vmware-iso.html.md.erb +++ b/website/source/docs/builders/vmware-iso.html.md.erb @@ -100,7 +100,8 @@ builder. - `cpus` (number) - The number of cpus to use when building the VM. -- `cores` (number) - The number of cores per socket to use when building the VM. +- `cores_per_socket` (number) - The number of cores per socket to use when + building the VM. - `cdrom_adapter_type` (string) - The adapter type (or bus) that will be used by the cdrom device. This is chosen by default based on the disk adapter From 9d2f98394e08da38cf0aa5d69b6d623aa5b19504 Mon Sep 17 00:00:00 2001 From: Ali Rizvi-Santiago Date: Thu, 17 Jan 2019 14:49:07 -0600 Subject: [PATCH 5/6] Revert "Renamed the terse option, `cores`, to to the less-terse version `cores_per_socket`." This reverts commit 0c37a3c68fd859fd97ce645210d8bb4b19ae96dc and avoids bikeshedding from other committers. --- builder/vmware/common/hw_config.go | 2 +- website/source/docs/builders/vmware-iso.html.md.erb | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/builder/vmware/common/hw_config.go b/builder/vmware/common/hw_config.go index eb3ed46c2..588d295f1 100644 --- a/builder/vmware/common/hw_config.go +++ b/builder/vmware/common/hw_config.go @@ -14,7 +14,7 @@ type HWConfig struct { // cpu information CpuCount int `mapstructure:"cpus"` MemorySize int `mapstructure:"memory"` - CoreCount int `mapstructure:"cores_per_socket"` + CoreCount int `mapstructure:"cores"` // network type and adapter Network string `mapstructure:"network"` diff --git a/website/source/docs/builders/vmware-iso.html.md.erb b/website/source/docs/builders/vmware-iso.html.md.erb index e7ecb350d..180af5c08 100644 --- a/website/source/docs/builders/vmware-iso.html.md.erb +++ b/website/source/docs/builders/vmware-iso.html.md.erb @@ -100,8 +100,7 @@ builder. - `cpus` (number) - The number of cpus to use when building the VM. -- `cores_per_socket` (number) - The number of cores per socket to use when - building the VM. +- `cores` (number) - The number of cores per socket to use when building the VM. - `cdrom_adapter_type` (string) - The adapter type (or bus) that will be used by the cdrom device. This is chosen by default based on the disk adapter From 3f559f878248cc4d3a98f7d2c238a72f53111d3d Mon Sep 17 00:00:00 2001 From: Ali Rizvi-Santiago Date: Fri, 25 Jan 2019 02:40:34 -0600 Subject: [PATCH 6/6] Updated the documentation with the vmx option that it uses. --- website/source/docs/builders/vmware-iso.html.md.erb | 1 + 1 file changed, 1 insertion(+) diff --git a/website/source/docs/builders/vmware-iso.html.md.erb b/website/source/docs/builders/vmware-iso.html.md.erb index 180af5c08..0a2411d79 100644 --- a/website/source/docs/builders/vmware-iso.html.md.erb +++ b/website/source/docs/builders/vmware-iso.html.md.erb @@ -101,6 +101,7 @@ builder. - `cpus` (number) - The number of cpus to use when building the VM. - `cores` (number) - The number of cores per socket to use when building the VM. + This corresponds to the `cpuid.coresPerSocket` option in the .vmx file. - `cdrom_adapter_type` (string) - The adapter type (or bus) that will be used by the cdrom device. This is chosen by default based on the disk adapter