packer-cn/builder/vmware/common/vmx_config.go

60 lines
1.2 KiB
Go
Raw Normal View History

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"`
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,
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,
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
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
}
newVMXDataPost[k] = v
}
c.VMXDataPost = newVMXDataPost
2013-12-26 17:14:19 -05:00
return errs
}