2013-12-26 17:14:19 -05:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
2016-01-21 18:19:11 -05:00
|
|
|
"fmt"
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
"github.com/mitchellh/packer/common"
|
2015-05-27 17:16:28 -04:00
|
|
|
"github.com/mitchellh/packer/template/interpolate"
|
2013-12-26 17:14:19 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
type VMXConfig struct {
|
2014-05-10 13:19:35 -04:00
|
|
|
VMXData map[string]string `mapstructure:"vmx_data"`
|
2014-05-09 12:25:15 -04:00
|
|
|
VMXDataPost map[string]string `mapstructure:"vmx_data_post"`
|
2013-12-26 17:14:19 -05:00
|
|
|
}
|
|
|
|
|
2016-01-25 12:01:56 -05:00
|
|
|
func (c *VMXConfig) Prepare(ctx *interpolate.Context, remoteType string) []error {
|
2016-01-21 18:19:11 -05:00
|
|
|
var errs []error
|
|
|
|
var err error
|
|
|
|
var desiredMem uint64
|
|
|
|
|
2016-01-25 12:01:56 -05:00
|
|
|
// Validate memory resources, only on local hosts
|
|
|
|
if remoteType == "" {
|
|
|
|
for k, v := range c.VMXData {
|
|
|
|
if k == "memsize" {
|
|
|
|
desiredMem, err = strconv.ParseUint(v, 10, 64)
|
|
|
|
if err != nil {
|
|
|
|
errs = append(errs, fmt.Errorf("Error parsing string: %s", err))
|
|
|
|
}
|
2016-01-21 18:19:11 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if err = common.AvailableMem(desiredMem); err != nil {
|
|
|
|
errs = append(errs, fmt.Errorf("Unavailable Resources: %s", err))
|
|
|
|
}
|
|
|
|
|
|
|
|
return errs
|
2013-12-26 17:14:19 -05:00
|
|
|
}
|