Merge pull request #90 from michael2012z/master

Add options to configure the number of VCPUs.
This commit is contained in:
Rob Dobson 2017-10-18 10:11:40 +01:00 committed by GitHub
commit 5e1f8571d6
4 changed files with 40 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_host` - the IP for the XenServer host being used.
* `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.
* `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.

View File

@ -22,10 +22,12 @@ type config struct {
common.PackerConfig `mapstructure:",squash"`
xscommon.CommonConfig `mapstructure:",squash"`
VMMemory uint `mapstructure:"vm_memory"`
DiskSize uint `mapstructure:"disk_size"`
CloneTemplate string `mapstructure:"clone_template"`
VMOtherConfig map[string]string `mapstructure:"vm_other_config"`
VCPUsMax uint `mapstructure:"vcpus_max"`
VCPUsAtStartup uint `mapstructure:"vcpus_atstartup"`
VMMemory uint `mapstructure:"vm_memory"`
DiskSize uint `mapstructure:"disk_size"`
CloneTemplate string `mapstructure:"clone_template"`
VMOtherConfig map[string]string `mapstructure:"vm_other_config"`
ISOChecksum string `mapstructure:"iso_checksum"`
ISOChecksumType string `mapstructure:"iso_checksum_type"`
@ -77,6 +79,18 @@ func (self *Builder) Prepare(raws ...interface{}) (params []string, retErr error
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 {
self.config.VMMemory = 1024
}

View File

@ -50,6 +50,18 @@ func (self *stepCreateInstance) Run(state multistep.StateBag) multistep.StepActi
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))
if err != nil {
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",
"apic": "true",
"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
"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
allocate for the VM. By default, this is 1024 (1 GB).