2013-12-22 12:24:29 -05:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
2016-01-21 18:19:11 -05:00
|
|
|
"fmt"
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
"github.com/mitchellh/packer/common"
|
2015-05-27 17:01:08 -04:00
|
|
|
"github.com/mitchellh/packer/template/interpolate"
|
2013-12-22 12:24:29 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
type VBoxManageConfig struct {
|
|
|
|
VBoxManage [][]string `mapstructure:"vboxmanage"`
|
|
|
|
}
|
|
|
|
|
2015-05-27 17:01:08 -04:00
|
|
|
func (c *VBoxManageConfig) Prepare(ctx *interpolate.Context) []error {
|
2013-12-22 12:24:29 -05:00
|
|
|
if c.VBoxManage == nil {
|
|
|
|
c.VBoxManage = make([][]string, 0)
|
2016-01-21 18:19:11 -05:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
var errs []error
|
|
|
|
var err error
|
|
|
|
var desiredMem uint64
|
|
|
|
|
|
|
|
for _, cmd := range c.VBoxManage {
|
|
|
|
if cmd[2] == "--memory" {
|
|
|
|
desiredMem, err = strconv.ParseUint(cmd[3], 10, 64)
|
|
|
|
if err != nil {
|
|
|
|
errs = append(errs, fmt.Errorf("Error parsing string: %s", err))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if err = common.AvailableMem(desiredMem); err != nil {
|
|
|
|
errs = append(errs, fmt.Errorf("Unavailable Resources: %s", err))
|
2013-12-22 12:24:29 -05:00
|
|
|
}
|
|
|
|
|
2016-01-21 18:19:11 -05:00
|
|
|
return errs
|
2013-12-22 12:24:29 -05:00
|
|
|
}
|