2019-05-31 08:27:41 -04:00
|
|
|
//go:generate struct-markdown
|
|
|
|
|
2018-11-17 06:16:14 -05:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/hashicorp/packer/template/interpolate"
|
|
|
|
)
|
|
|
|
|
|
|
|
type HWConfig struct {
|
2019-05-28 11:50:58 -04:00
|
|
|
// The number of cpus to use for building the VM.
|
2019-06-06 10:29:25 -04:00
|
|
|
// Defaults to 1.
|
|
|
|
CpuCount int `mapstructure:"cpus" required:"false"`
|
2019-05-28 11:50:58 -04:00
|
|
|
// The amount of memory to use for building the VM in
|
2019-06-06 10:29:25 -04:00
|
|
|
// megabytes. Defaults to 512 megabytes.
|
2019-05-28 11:50:58 -04:00
|
|
|
MemorySize int `mapstructure:"memory" required:"false"`
|
|
|
|
// Specifies whether to enable the sound device when
|
2019-06-06 10:29:25 -04:00
|
|
|
// building the VM. Defaults to false.
|
2019-05-28 11:50:58 -04:00
|
|
|
Sound bool `mapstructure:"sound" required:"false"`
|
|
|
|
// Specifies whether to enable the USB bus when building
|
2019-06-06 10:29:25 -04:00
|
|
|
// the VM. Defaults to false.
|
|
|
|
USB bool `mapstructure:"usb" required:"false"`
|
2018-11-17 06:16:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *HWConfig) Prepare(ctx *interpolate.Context) []error {
|
|
|
|
var errs []error
|
|
|
|
|
|
|
|
// Hardware and cpu options
|
|
|
|
if c.CpuCount < 0 {
|
2018-11-17 07:31:49 -05:00
|
|
|
errs = append(errs, fmt.Errorf("An invalid number of cpus was specified (cpus < 0): %d", c.CpuCount))
|
2018-11-17 06:16:14 -05:00
|
|
|
}
|
|
|
|
if c.CpuCount == 0 {
|
|
|
|
c.CpuCount = 1
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.MemorySize < 0 {
|
2018-11-17 07:31:49 -05:00
|
|
|
errs = append(errs, fmt.Errorf("An invalid memory size was specified (memory < 0): %d", c.MemorySize))
|
2018-11-17 06:16:14 -05:00
|
|
|
}
|
|
|
|
if c.MemorySize == 0 {
|
|
|
|
c.MemorySize = 512
|
|
|
|
}
|
|
|
|
|
|
|
|
// Peripherals
|
|
|
|
if !c.Sound {
|
|
|
|
c.Sound = false
|
|
|
|
}
|
|
|
|
|
|
|
|
if !c.USB {
|
|
|
|
c.USB = false
|
|
|
|
}
|
|
|
|
|
2018-11-22 21:19:00 -05:00
|
|
|
return errs
|
2018-11-17 06:16:14 -05:00
|
|
|
}
|