Add options to configure the number of VCPUs.

This commit is contained in:
Michael Zhao 2017-10-12 00:14:23 -07:00
parent 5e44cd6434
commit 191ac47af3
4 changed files with 41 additions and 5 deletions

View File

@ -77,6 +77,8 @@ A brief explanation of what the config parameters mean:
* `remote_password` - the password for the XenServer host being used. * `remote_password` - the password for the XenServer host being used.
* `remote_host` - the IP for the XenServer host being used. * `remote_host` - the IP for the XenServer host being used.
* `vm_name` - the name that should be given to the created VM. * `vm_name` - the name that should be given to the created VM.
* `vcpus_max` - the maximum number of VCPUs for the VM.
* `vcpus_atstartup` - the number of startup VCPUs for the VM.
* `vm_memory` - the static memory configuration for the VM, in MB. * `vm_memory` - the static memory configuration for the VM, in MB.
* `disk_size` - the size of the disk the VM should be created with, in MB. * `disk_size` - the size of the disk the VM should be created with, in MB.
* `iso_name` - the name of the ISO visible on a ISO SR connected to the XenServer host. * `iso_name` - the name of the ISO visible on a ISO SR connected to the XenServer host.

View File

@ -22,10 +22,12 @@ type config struct {
common.PackerConfig `mapstructure:",squash"` common.PackerConfig `mapstructure:",squash"`
xscommon.CommonConfig `mapstructure:",squash"` xscommon.CommonConfig `mapstructure:",squash"`
VMMemory uint `mapstructure:"vm_memory"` VCPUsMax uint `mapstructure:"vcpus_max"`
DiskSize uint `mapstructure:"disk_size"` VCPUsAtStartup uint `mapstructure:"vcpus_atstartup"`
CloneTemplate string `mapstructure:"clone_template"` VMMemory uint `mapstructure:"vm_memory"`
VMOtherConfig map[string]string `mapstructure:"vm_other_config"` DiskSize uint `mapstructure:"disk_size"`
CloneTemplate string `mapstructure:"clone_template"`
VMOtherConfig map[string]string `mapstructure:"vm_other_config"`
ISOChecksum string `mapstructure:"iso_checksum"` ISOChecksum string `mapstructure:"iso_checksum"`
ISOChecksumType string `mapstructure:"iso_checksum_type"` ISOChecksumType string `mapstructure:"iso_checksum_type"`
@ -77,6 +79,18 @@ func (self *Builder) Prepare(raws ...interface{}) (params []string, retErr error
self.config.DiskSize = 40000 self.config.DiskSize = 40000
} }
if self.config.VCPUsMax == 0 {
self.config.VCPUsMax = 1
}
if self.config.VCPUsAtStartup == 0 {
self.config.VCPUsAtStartup = 1
}
if self.config.VCPUsAtStartup > self.config.VCPUsMax {
self.config.VCPUsAtStartup = self.config.VCPUsMax
}
if self.config.VMMemory == 0 { if self.config.VMMemory == 0 {
self.config.VMMemory = 1024 self.config.VMMemory = 1024
} }
@ -93,6 +107,7 @@ func (self *Builder) Prepare(raws ...interface{}) (params []string, retErr error
pargs["apic"] = "true" pargs["apic"] = "true"
pargs["timeoffset"] = "0" pargs["timeoffset"] = "0"
pargs["acpi"] = "1" pargs["acpi"] = "1"
pargs["cores-per-socket"] = "1"
self.config.PlatformArgs = pargs self.config.PlatformArgs = pargs
} }

View File

@ -50,6 +50,18 @@ func (self *stepCreateInstance) Run(state multistep.StateBag) multistep.StepActi
return multistep.ActionHalt return multistep.ActionHalt
} }
err = instance.SetVCPUsMax(config.VCPUsMax)
if err != nil {
ui.Error(fmt.Sprintf("Error setting VM VCPUs Max=%d: %s", config.VCPUsMax, err.Error()))
return multistep.ActionHalt
}
err = instance.SetVCPUsAtStartup(config.VCPUsAtStartup)
if err != nil {
ui.Error(fmt.Sprintf("Error setting VM VCPUs At Startup=%d: %s", config.VCPUsAtStartup, err.Error()))
return multistep.ActionHalt
}
err = instance.SetStaticMemoryRange(uint64(config.VMMemory*1024*1024), uint64(config.VMMemory*1024*1024)) err = instance.SetStaticMemoryRange(uint64(config.VMMemory*1024*1024), uint64(config.VMMemory*1024*1024))
if err != nil { if err != nil {
ui.Error(fmt.Sprintf("Error setting VM memory=%d: %s", config.VMMemory*1024*1024, err.Error())) ui.Error(fmt.Sprintf("Error setting VM memory=%d: %s", config.VMMemory*1024*1024, err.Error()))

View File

@ -167,7 +167,8 @@ each category, the available options are alphabetized and described.
"pae": "true", "pae": "true",
"apic": "true", "apic": "true",
"timeoffset": "0", "timeoffset": "0",
"acpi": "1" "acpi": "1",
"cores-per-socket": "1"
} }
``` ```
@ -211,6 +212,12 @@ each category, the available options are alphabetized and described.
machine, without the file extension. By default this is machine, without the file extension. By default this is
"packer-BUILDNAME-TIMESTAMP", where "BUILDNAME" is the name of the build. "packer-BUILDNAME-TIMESTAMP", where "BUILDNAME" is the name of the build.
* `vcpus_max` (integer) - The maximum number of VCPUs for the VM.
By default this is 1.
* `vcpus_atstartup` (integer) - The number of startup VCPUs for the VM.
By default this is 1.
* `vm_memory` (integer) - The size, in megabytes, of the amount of memory to * `vm_memory` (integer) - The size, in megabytes, of the amount of memory to
allocate for the VM. By default, this is 1024 (1 GB). allocate for the VM. By default, this is 1024 (1 GB).