mirror of https://github.com/hashicorp/packer
Merge pull request #7017 from arizvisa/virtualbox.cpu-memory
Add configuration options to virtualbox builder to specify cpu count and memory sizepull/7037/head
commit
174c811c1e
@ -0,0 +1,44 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/packer/template/interpolate"
|
||||
)
|
||||
|
||||
type HWConfig struct {
|
||||
|
||||
// cpu information
|
||||
CpuCount int `mapstructure:"cpus"`
|
||||
MemorySize int `mapstructure:"memory"`
|
||||
|
||||
// device presence
|
||||
Sound string `mapstructure:"sound"`
|
||||
USB bool `mapstructure:"usb"`
|
||||
}
|
||||
|
||||
func (c *HWConfig) Prepare(ctx *interpolate.Context) []error {
|
||||
var errs []error
|
||||
|
||||
// Hardware and cpu options
|
||||
if c.CpuCount < 0 {
|
||||
errs = append(errs, fmt.Errorf("An invalid number of cpus was specified (cpus < 0): %d", c.CpuCount))
|
||||
}
|
||||
if c.CpuCount == 0 {
|
||||
c.CpuCount = 1
|
||||
}
|
||||
|
||||
if c.MemorySize < 0 {
|
||||
errs = append(errs, fmt.Errorf("An invalid memory size was specified (memory < 0): %d", c.MemorySize))
|
||||
}
|
||||
if c.MemorySize == 0 {
|
||||
c.MemorySize = 512
|
||||
}
|
||||
|
||||
// devices
|
||||
if c.Sound == "" {
|
||||
c.Sound = "none"
|
||||
}
|
||||
|
||||
return errs
|
||||
}
|
||||
@ -0,0 +1,20 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestHWConfigPrepare(t *testing.T) {
|
||||
c := new(HWConfig)
|
||||
if errs := c.Prepare(testConfigTemplate(t)); len(errs) > 0 {
|
||||
t.Fatalf("err: %#v", errs)
|
||||
}
|
||||
|
||||
if c.CpuCount < 1 {
|
||||
t.Errorf("bad cpu count: %d", c.CpuCount)
|
||||
}
|
||||
|
||||
if c.MemorySize < 64 {
|
||||
t.Errorf("bad memory size: %d", c.MemorySize)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue