Add ability to select CPU type

This commit is contained in:
Samuel Noordhuis 2019-10-06 21:39:53 +11:00
parent 68127870f7
commit 5add6cc6c8
No known key found for this signature in database
GPG Key ID: 235E5588064934CF
4 changed files with 14 additions and 1 deletions

View File

@ -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"

View File

@ -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)
}

View File

@ -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,

View File

@ -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`.