packer-cn/builder/virtualbox/common/vboxmanage_config.go

40 lines
793 B
Go
Raw Normal View History

2013-12-22 12:24:29 -05:00
package common
import (
"fmt"
"strconv"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/template/interpolate"
2013-12-22 12:24:29 -05:00
)
type VBoxManageConfig struct {
VBoxManage [][]string `mapstructure:"vboxmanage"`
}
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)
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
}
return errs
2013-12-22 12:24:29 -05:00
}