From 3c1df5a7919ddb4adb683daa9720b82c3100a83a Mon Sep 17 00:00:00 2001 From: Taliesin Sisson Date: Sun, 6 Nov 2016 14:07:46 +0000 Subject: [PATCH] Remove inconsistent "_mb" from ram size --- builder/hyperv/common/step_create_vm.go | 6 ++--- builder/hyperv/iso/builder.go | 22 +++++++++---------- .../docs/builders/hyperv-iso.html.markdown | 4 ++-- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/builder/hyperv/common/step_create_vm.go b/builder/hyperv/common/step_create_vm.go index 54a5a7103..1606a41e4 100644 --- a/builder/hyperv/common/step_create_vm.go +++ b/builder/hyperv/common/step_create_vm.go @@ -18,7 +18,7 @@ import ( type StepCreateVM struct { VMName string SwitchName string - RamSizeMB uint + RamSize uint DiskSize uint Generation uint Cpu uint @@ -36,10 +36,10 @@ func (s *StepCreateVM) Run(state multistep.StateBag) multistep.StepAction { path := state.Get("packerTempDir").(string) // convert the MB to bytes - ram := int64(s.RamSizeMB * 1024 * 1024) + ramSize := int64(s.RamSize * 1024 * 1024) diskSize := int64(s.DiskSize * 1024 * 1024) - err := driver.CreateVirtualMachine(s.VMName, path, ram, diskSize, s.SwitchName, s.Generation) + err := driver.CreateVirtualMachine(s.VMName, path, ramSize, diskSize, s.SwitchName, s.Generation) if err != nil { err := fmt.Errorf("Error creating virtual machine: %s", err) state.Put("error", err) diff --git a/builder/hyperv/iso/builder.go b/builder/hyperv/iso/builder.go index 410238f2a..e81f498e0 100644 --- a/builder/hyperv/iso/builder.go +++ b/builder/hyperv/iso/builder.go @@ -61,7 +61,7 @@ type Config struct { DiskSize uint `mapstructure:"disk_size"` // The size, in megabytes, of the computer memory in the VM. // By default, this is 1024 (about 1 GB). - RamSizeMB uint `mapstructure:"ram_size_mb"` + RamSize uint `mapstructure:"ram_size"` // A list of files to place onto a floppy disk that is attached when the // VM is booted. This is most useful for unattended Windows installs, // which look for an Autounattend.xml file on removable media. By default, @@ -261,7 +261,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) { warnings = appendWarnings(warnings, warning) } - if b.config.RamSizeMB < MinNestedVirtualizationRamSize { + if b.config.RamSize < MinNestedVirtualizationRamSize { warning = fmt.Sprintf("For nested virtualization, when virtualization extension is enabled, there should be 4GB or more memory set for the vm, otherwise Hyper-V may fail to start any nested VMs.") warnings = appendWarnings(warnings, warning) } @@ -328,7 +328,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe &hypervcommon.StepCreateVM{ VMName: b.config.VMName, SwitchName: b.config.SwitchName, - RamSizeMB: b.config.RamSizeMB, + RamSize: b.config.RamSize, DiskSize: b.config.DiskSize, Generation: b.config.Generation, Cpu: b.config.Cpu, @@ -477,16 +477,16 @@ func (b *Builder) checkDiskSize() error { } func (b *Builder) checkRamSize() error { - if b.config.RamSizeMB == 0 { - b.config.RamSizeMB = DefaultRamSize + if b.config.RamSize == 0 { + b.config.RamSize = DefaultRamSize } - log.Println(fmt.Sprintf("%s: %v", "RamSize", b.config.RamSizeMB)) + log.Println(fmt.Sprintf("%s: %v", "RamSize", b.config.RamSize)) - if b.config.RamSizeMB < MinRamSize { - return fmt.Errorf("ram_size_mb: Virtual machine requires memory size >= %v MB, but defined: %v", MinRamSize, b.config.RamSizeMB) - } else if b.config.RamSizeMB > MaxRamSize { - return fmt.Errorf("ram_size_mb: Virtual machine requires memory size <= %v MB, but defined: %v", MaxRamSize, b.config.RamSizeMB) + if b.config.RamSize < MinRamSize { + return fmt.Errorf("ram_size_mb: Virtual machine requires memory size >= %v MB, but defined: %v", MinRamSize, b.config.RamSize) + } else if b.config.RamSize > MaxRamSize { + return fmt.Errorf("ram_size_mb: Virtual machine requires memory size <= %v MB, but defined: %v", MaxRamSize, b.config.RamSize) } return nil @@ -498,7 +498,7 @@ func (b *Builder) checkHostAvailableMemory() string { if powershellAvailable { freeMB := powershell.GetHostAvailableMemory() - if (freeMB - float64(b.config.RamSizeMB)) < LowRam { + if (freeMB - float64(b.config.RamSize)) < LowRam { return fmt.Sprintf("Hyper-V might fail to create a VM if there is not enough free memory in the system.") } } diff --git a/website/source/docs/builders/hyperv-iso.html.markdown b/website/source/docs/builders/hyperv-iso.html.markdown index e01deffb5..dd161b034 100644 --- a/website/source/docs/builders/hyperv-iso.html.markdown +++ b/website/source/docs/builders/hyperv-iso.html.markdown @@ -358,7 +358,7 @@ Packer config: "winrm_password": "vagrant", "winrm_timeout" : "4h", "shutdown_command": "f:\\run-sysprep.cmd", - "ram_size_mb": 4096, + "ram_size": 4096, "cpu": 4, "generation": 2, "switch_name":"LAN", @@ -886,7 +886,7 @@ Packer config: "initrd=/install/initrd.gz -- " ], "shutdown_command": "echo 'vagrant' | sudo -S -E shutdown -P now", - "ram_size_mb": 4096, + "ram_size": 4096, "cpu": 4, "generation": 1, "switch_name":"LAN"