Rename instance_memory to vm_memory

Note that vm_memory is now in MB; instance_memory was in bytes
SetStaticMemoryRange now takes int64
Fixed example
This commit is contained in:
Cheng Sun 2014-12-18 17:26:10 +00:00
parent 2e1f94e831
commit b9a7feb225
4 changed files with 16 additions and 15 deletions

View File

@ -25,7 +25,7 @@ type config struct {
HostIp string `mapstructure:"host_ip"` HostIp string `mapstructure:"host_ip"`
VMName string `mapstructure:"vm_name"` VMName string `mapstructure:"vm_name"`
InstanceMemory string `mapstructure:"instance_memory"` VMMemory uint `mapstructure:"vm_memory"`
DiskSize uint `mapstructure:"disk_size"` DiskSize uint `mapstructure:"disk_size"`
CloneTemplate string `mapstructure:"clone_template"` CloneTemplate string `mapstructure:"clone_template"`
SrName string `mapstructure:"sr_name"` SrName string `mapstructure:"sr_name"`
@ -134,8 +134,8 @@ func (self *Builder) Prepare(raws ...interface{}) (params []string, retErr error
self.config.DiskSize = 40000 self.config.DiskSize = 40000
} }
if self.config.InstanceMemory == "" { if self.config.VMMemory == 0 {
self.config.InstanceMemory = "1024000000" self.config.VMMemory = 1024
} }
if self.config.CloneTemplate == "" { if self.config.CloneTemplate == "" {
@ -176,7 +176,6 @@ func (self *Builder) Prepare(raws ...interface{}) (params []string, retErr error
"password": &self.config.Password, "password": &self.config.Password,
"host_ip": &self.config.HostIp, "host_ip": &self.config.HostIp,
"vm_name": &self.config.VMName, "vm_name": &self.config.VMName,
"instance_memory": &self.config.InstanceMemory,
"clone_template": &self.config.CloneTemplate, "clone_template": &self.config.CloneTemplate,
"sr_name": &self.config.SrName, "sr_name": &self.config.SrName,
"network_name": &self.config.NetworkName, "network_name": &self.config.NetworkName,

View File

@ -537,9 +537,11 @@ func (self *VM) GetGuestMetrics() (metrics map[string]interface{}, err error) {
return metrics, nil return metrics, nil
} }
func (self *VM) SetStaticMemoryRange(min, max string) (err error) { func (self *VM) SetStaticMemoryRange(min, max uint) (err error) {
result := APIResult{} result := APIResult{}
err = self.Client.APICall(&result, "VM.set_memory_limits", self.Ref, min, max, min, max) strMin := fmt.Sprintf("%d", min)
strMax := fmt.Sprintf("%d", max)
err = self.Client.APICall(&result, "VM.set_memory_limits", self.Ref, strMin, strMax, strMin, strMax)
if err != nil { if err != nil {
return err return err
} }

View File

@ -48,9 +48,9 @@ func (self *stepCreateInstance) Run(state multistep.StateBag) multistep.StepActi
return multistep.ActionHalt return multistep.ActionHalt
} }
err = instance.SetStaticMemoryRange(config.InstanceMemory, config.InstanceMemory) err = instance.SetStaticMemoryRange(config.VMMemory*1024*1024, config.VMMemory*1024*1024)
if err != nil { if err != nil {
ui.Error(fmt.Sprintf("Error setting VM memory=%s: %s", config.InstanceMemory, err.Error())) ui.Error(fmt.Sprintf("Error setting VM memory=%d: %s", config.VMMemory*1024*1024, err.Error()))
return multistep.ActionHalt return multistep.ActionHalt
} }

View File

@ -5,7 +5,7 @@
"password": "hostpassword", "password": "hostpassword",
"host_ip": "10.81.2.105", "host_ip": "10.81.2.105",
"vm_name": "packer-centos-6-4", "vm_name": "packer-centos-6-4",
"instance_memory": "2048000000", "vm_memory": 2048,
"disk_size": 40000, "disk_size": 40000,
"iso_name": "CentOS-6.4-x86_64-minimal.iso", "iso_name": "CentOS-6.4-x86_64-minimal.iso",
"http_directory": "http", "http_directory": "http",