From 5add6cc6c86864acea29092a66916ca19c5fd051 Mon Sep 17 00:00:00 2001 From: Samuel Noordhuis Date: Sun, 6 Oct 2019 21:39:53 +1100 Subject: [PATCH 1/2] Add ability to select CPU type --- builder/proxmox/config.go | 5 +++++ builder/proxmox/config_test.go | 4 ++++ builder/proxmox/step_start_vm.go | 2 +- website/source/docs/builders/proxmox.html.md | 4 ++++ 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/builder/proxmox/config.go b/builder/proxmox/config.go index 6889c8c07..9b478672c 100644 --- a/builder/proxmox/config.go +++ b/builder/proxmox/config.go @@ -40,6 +40,7 @@ type Config struct { Memory int `mapstructure:"memory"` Cores int `mapstructure:"cores"` Sockets int `mapstructure:"sockets"` + CPUType string `mapstructure:"cpu_type"` OS string `mapstructure:"os"` NICs []nicConfig `mapstructure:"network_adapters"` Disks []diskConfig `mapstructure:"disks"` @@ -129,6 +130,10 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) { log.Printf("Number of sockets %d is too small, using default: 1", c.Sockets) c.Sockets = 1 } + if c.CPUType == "" { + log.Printf("CPU type not set, using default 'kvm64'") + c.CPUType = "kvm64" + } if c.OS == "" { log.Printf("OS not set, using default 'other'") c.OS = "other" diff --git a/builder/proxmox/config_test.go b/builder/proxmox/config_test.go index ec654dc54..65d9df9d9 100644 --- a/builder/proxmox/config_test.go +++ b/builder/proxmox/config_test.go @@ -90,6 +90,7 @@ func TestBasicExampleFromDocsIsValid(t *testing.T) { // Memory 0 is too small, using default: 512 // Number of cores 0 is too small, using default: 1 // Number of sockets 0 is too small, using default: 1 + // CPU type not set, using default 'kvm64' // OS not set, using default 'other' // NIC 0 model not set, using default 'e1000' // Disk 0 cache mode not set, using default 'none' @@ -104,6 +105,9 @@ func TestBasicExampleFromDocsIsValid(t *testing.T) { if b.config.Sockets != 1 { t.Errorf("Expected Sockets to be 1, got %d", b.config.Sockets) } + if b.config.CPUType != "kvm64" { + t.Errorf("Expected CPU type to be 'kvm64', got %s", b.config.CPUType) + } if b.config.OS != "other" { t.Errorf("Expected OS to be 'other', got %s", b.config.OS) } diff --git a/builder/proxmox/step_start_vm.go b/builder/proxmox/step_start_vm.go index 76663b33f..ee67ca7df 100644 --- a/builder/proxmox/step_start_vm.go +++ b/builder/proxmox/step_start_vm.go @@ -31,7 +31,7 @@ func (s *stepStartVM) Run(ctx context.Context, state multistep.StateBag) multist Name: c.VMName, Agent: agent, Boot: "cdn", // Boot priority, c:CDROM -> d:Disk -> n:Network - QemuCpu: "host", + QemuCpu: c.CPUType, Description: "Packer ephemeral build VM", Memory: c.Memory, QemuCores: c.Cores, diff --git a/website/source/docs/builders/proxmox.html.md b/website/source/docs/builders/proxmox.html.md index ca7c99ea3..68e5aa5a7 100644 --- a/website/source/docs/builders/proxmox.html.md +++ b/website/source/docs/builders/proxmox.html.md @@ -73,6 +73,10 @@ builder. - `sockets` (int) - How many CPU sockets to give the virtual machine. Defaults to `1` +- `cpu_type` (string) - The CPU type to emulate. See the Proxmox API + documentation for the complete list of accepted values. For best + performance, set this to `host`. Defaults to `kvm64`. + - `os` (string) - The operating system. Can be `wxp`, `w2k`, `w2k3`, `w2k8`, `wvista`, `win7`, `win8`, `win10`, `l24` (Linux 2.4), `l26` (Linux 2.6+), `solaris` or `other`. Defaults to `other`. From eecac683b869683baa1335deb858cb5a489174ff Mon Sep 17 00:00:00 2001 From: Samuel Noordhuis Date: Tue, 8 Oct 2019 19:45:15 +1100 Subject: [PATCH 2/2] Update builder/proxmox/config.go Co-Authored-By: Adrien Delorme --- builder/proxmox/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builder/proxmox/config.go b/builder/proxmox/config.go index 3f516beb7..766d3e71d 100644 --- a/builder/proxmox/config.go +++ b/builder/proxmox/config.go @@ -39,7 +39,7 @@ type Config struct { Memory int `mapstructure:"memory"` Cores int `mapstructure:"cores"` - CPUType string `mapstructure:"cpu_type"` + CPUType string `mapstructure:"cpu_type"` Sockets int `mapstructure:"sockets"` OS string `mapstructure:"os"` NICs []nicConfig `mapstructure:"network_adapters"`