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

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

View File

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

View File

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

View File

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