@ -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).
RamSize MB 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 . RamSize MB < 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 ,
RamSize MB : b . config . RamSize MB ,
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 . RamSize MB == 0 {
b . config . RamSize MB = DefaultRamSize
if b . config . RamSize == 0 {
b . config . RamSize = DefaultRamSize
}
log . Println ( fmt . Sprintf ( "%s: %v" , "RamSize" , b . config . RamSize MB ) )
log . Println ( fmt . Sprintf ( "%s: %v" , "RamSize" , b . config . RamSize ) )
if b . config . RamSize MB < MinRamSize {
return fmt . Errorf ( "ram_size_mb: Virtual machine requires memory size >= %v MB, but defined: %v" , MinRamSize , b . config . RamSize MB )
} else if b . config . RamSize MB > MaxRamSize {
return fmt . Errorf ( "ram_size_mb: Virtual machine requires memory size <= %v MB, but defined: %v" , MaxRamSize , b . config . RamSize MB )
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 . RamSize MB ) ) < 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." )
}
}