From b9a7feb225ad08ca620810b65301bafa5044cfeb Mon Sep 17 00:00:00 2001 From: Cheng Sun Date: Thu, 18 Dec 2014 17:26:10 +0000 Subject: [PATCH] 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 --- builder/xenserver/builder.go | 19 +++++++++---------- builder/xenserver/client.go | 6 ++++-- builder/xenserver/step_create_instance.go | 4 ++-- examples/centos-6.4.conf | 2 +- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/builder/xenserver/builder.go b/builder/xenserver/builder.go index 1abf8d7..9574caa 100644 --- a/builder/xenserver/builder.go +++ b/builder/xenserver/builder.go @@ -24,13 +24,13 @@ type config struct { Password string `mapstructure:"password"` HostIp string `mapstructure:"host_ip"` - VMName string `mapstructure:"vm_name"` - InstanceMemory string `mapstructure:"instance_memory"` - DiskSize uint `mapstructure:"disk_size"` - CloneTemplate string `mapstructure:"clone_template"` - SrName string `mapstructure:"sr_name"` - FloppyFiles []string `mapstructure:"floppy_files"` - NetworkName string `mapstructure:"network_name"` + VMName string `mapstructure:"vm_name"` + VMMemory uint `mapstructure:"vm_memory"` + DiskSize uint `mapstructure:"disk_size"` + CloneTemplate string `mapstructure:"clone_template"` + SrName string `mapstructure:"sr_name"` + FloppyFiles []string `mapstructure:"floppy_files"` + NetworkName string `mapstructure:"network_name"` HostPortMin uint `mapstructure:"host_port_min"` HostPortMax uint `mapstructure:"host_port_max"` @@ -134,8 +134,8 @@ func (self *Builder) Prepare(raws ...interface{}) (params []string, retErr error self.config.DiskSize = 40000 } - if self.config.InstanceMemory == "" { - self.config.InstanceMemory = "1024000000" + if self.config.VMMemory == 0 { + self.config.VMMemory = 1024 } if self.config.CloneTemplate == "" { @@ -176,7 +176,6 @@ func (self *Builder) Prepare(raws ...interface{}) (params []string, retErr error "password": &self.config.Password, "host_ip": &self.config.HostIp, "vm_name": &self.config.VMName, - "instance_memory": &self.config.InstanceMemory, "clone_template": &self.config.CloneTemplate, "sr_name": &self.config.SrName, "network_name": &self.config.NetworkName, diff --git a/builder/xenserver/client.go b/builder/xenserver/client.go index c5bfe11..9fdffcd 100644 --- a/builder/xenserver/client.go +++ b/builder/xenserver/client.go @@ -537,9 +537,11 @@ func (self *VM) GetGuestMetrics() (metrics map[string]interface{}, err error) { return metrics, nil } -func (self *VM) SetStaticMemoryRange(min, max string) (err error) { +func (self *VM) SetStaticMemoryRange(min, max uint) (err error) { 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 { return err } diff --git a/builder/xenserver/step_create_instance.go b/builder/xenserver/step_create_instance.go index 668f695..927bca5 100644 --- a/builder/xenserver/step_create_instance.go +++ b/builder/xenserver/step_create_instance.go @@ -48,9 +48,9 @@ func (self *stepCreateInstance) Run(state multistep.StateBag) multistep.StepActi return multistep.ActionHalt } - err = instance.SetStaticMemoryRange(config.InstanceMemory, config.InstanceMemory) + err = instance.SetStaticMemoryRange(config.VMMemory*1024*1024, config.VMMemory*1024*1024) 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 } diff --git a/examples/centos-6.4.conf b/examples/centos-6.4.conf index 3de670a..2adfc77 100644 --- a/examples/centos-6.4.conf +++ b/examples/centos-6.4.conf @@ -5,7 +5,7 @@ "password": "hostpassword", "host_ip": "10.81.2.105", "vm_name": "packer-centos-6-4", - "instance_memory": "2048000000", + "vm_memory": 2048, "disk_size": 40000, "iso_name": "CentOS-6.4-x86_64-minimal.iso", "http_directory": "http",