2013-12-26 17:14:19 -05:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/mitchellh/packer/packer"
|
|
|
|
)
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
func (c *VMXConfig) Prepare(t *packer.ConfigTemplate) []error {
|
|
|
|
errs := make([]error, 0)
|
|
|
|
newVMXData := make(map[string]string)
|
|
|
|
for k, v := range c.VMXData {
|
|
|
|
var err error
|
|
|
|
k, err = t.Process(k, nil)
|
|
|
|
if err != nil {
|
|
|
|
errs = append(errs,
|
2014-05-09 12:25:15 -04:00
|
|
|
fmt.Errorf("Error processing vmx_data key %s: %s", k, err))
|
2013-12-26 17:14:19 -05:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
v, err = t.Process(v, nil)
|
|
|
|
if err != nil {
|
|
|
|
errs = append(errs,
|
2014-05-09 12:25:15 -04:00
|
|
|
fmt.Errorf("Error processing vmx_data value '%s': %s", v, err))
|
2013-12-26 17:14:19 -05:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
newVMXData[k] = v
|
|
|
|
}
|
|
|
|
c.VMXData = newVMXData
|
|
|
|
|
2014-05-09 12:25:15 -04:00
|
|
|
newVMXDataPost := make(map[string]string)
|
|
|
|
for k, v := range c.VMXDataPost {
|
|
|
|
var err error
|
|
|
|
k, err = t.Process(k, nil)
|
|
|
|
if err != nil {
|
|
|
|
errs = append(errs,
|
|
|
|
fmt.Errorf("Error processing vmx_post_data key %s: %s", k, err))
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
v, err = t.Process(v, nil)
|
|
|
|
if err != nil {
|
|
|
|
errs = append(errs,
|
|
|
|
fmt.Errorf("Error processing vmx_post_data value '%s': %s", v, err))
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2014-05-12 17:43:12 -04:00
|
|
|
newVMXDataPost[k] = v
|
2014-05-09 12:25:15 -04:00
|
|
|
}
|
|
|
|
c.VMXDataPost = newVMXDataPost
|
|
|
|
|
2013-12-26 17:14:19 -05:00
|
|
|
return errs
|
|
|
|
}
|