|
|
|
|
@ -6,7 +6,9 @@ import (
|
|
|
|
|
|
|
|
|
|
parallelscommon "github.com/mitchellh/packer/builder/parallels/common"
|
|
|
|
|
"github.com/mitchellh/packer/common"
|
|
|
|
|
"github.com/mitchellh/packer/helper/config"
|
|
|
|
|
"github.com/mitchellh/packer/packer"
|
|
|
|
|
"github.com/mitchellh/packer/template/interpolate"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Config is the configuration structure for the builder.
|
|
|
|
|
@ -26,57 +28,39 @@ type Config struct {
|
|
|
|
|
VMName string `mapstructure:"vm_name"`
|
|
|
|
|
ReassignMac bool `mapstructure:"reassign_mac"`
|
|
|
|
|
|
|
|
|
|
tpl *packer.ConfigTemplate
|
|
|
|
|
ctx interpolate.Context
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewConfig(raws ...interface{}) (*Config, []string, error) {
|
|
|
|
|
c := new(Config)
|
|
|
|
|
md, err := common.DecodeConfig(c, raws...)
|
|
|
|
|
err := config.Decode(&c, &config.DecodeOpts{
|
|
|
|
|
Interpolate: true,
|
|
|
|
|
InterpolateFilter: &interpolate.RenderFilter{
|
|
|
|
|
Exclude: []string{
|
|
|
|
|
"boot_command",
|
|
|
|
|
"prlctl",
|
|
|
|
|
"parallel_tools_guest_path",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}, raws...)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
c.tpl, err = packer.NewConfigTemplate()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, nil, err
|
|
|
|
|
}
|
|
|
|
|
c.tpl.UserVars = c.PackerUserVars
|
|
|
|
|
|
|
|
|
|
if c.VMName == "" {
|
|
|
|
|
c.VMName = fmt.Sprintf("packer-%s-{{timestamp}}", c.PackerBuildName)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Prepare the errors
|
|
|
|
|
errs := common.CheckUnusedConfig(md)
|
|
|
|
|
errs = packer.MultiErrorAppend(errs, c.FloppyConfig.Prepare(c.tpl)...)
|
|
|
|
|
errs = packer.MultiErrorAppend(errs, c.OutputConfig.Prepare(c.tpl, &c.PackerConfig)...)
|
|
|
|
|
errs = packer.MultiErrorAppend(errs, c.PrlctlConfig.Prepare(c.tpl)...)
|
|
|
|
|
errs = packer.MultiErrorAppend(errs, c.PrlctlVersionConfig.Prepare(c.tpl)...)
|
|
|
|
|
errs = packer.MultiErrorAppend(errs, c.RunConfig.Prepare(c.tpl)...)
|
|
|
|
|
errs = packer.MultiErrorAppend(errs, c.ShutdownConfig.Prepare(c.tpl)...)
|
|
|
|
|
errs = packer.MultiErrorAppend(errs, c.SSHConfig.Prepare(c.tpl)...)
|
|
|
|
|
errs = packer.MultiErrorAppend(errs, c.ToolsConfig.Prepare(c.tpl)...)
|
|
|
|
|
|
|
|
|
|
templates := map[string]*string{
|
|
|
|
|
"source_path": &c.SourcePath,
|
|
|
|
|
"vm_name": &c.VMName,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for n, ptr := range templates {
|
|
|
|
|
var err error
|
|
|
|
|
*ptr, err = c.tpl.Process(*ptr, nil)
|
|
|
|
|
if err != nil {
|
|
|
|
|
errs = packer.MultiErrorAppend(
|
|
|
|
|
errs, fmt.Errorf("Error processing %s: %s", n, err))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for i, command := range c.BootCommand {
|
|
|
|
|
if err := c.tpl.Validate(command); err != nil {
|
|
|
|
|
errs = packer.MultiErrorAppend(errs,
|
|
|
|
|
fmt.Errorf("Error processing boot_command[%d]: %s", i, err))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
var errs *packer.MultiError
|
|
|
|
|
errs = packer.MultiErrorAppend(errs, c.FloppyConfig.Prepare(&c.ctx)...)
|
|
|
|
|
errs = packer.MultiErrorAppend(errs, c.OutputConfig.Prepare(&c.ctx, &c.PackerConfig)...)
|
|
|
|
|
errs = packer.MultiErrorAppend(errs, c.PrlctlConfig.Prepare(&c.ctx)...)
|
|
|
|
|
errs = packer.MultiErrorAppend(errs, c.PrlctlVersionConfig.Prepare(&c.ctx)...)
|
|
|
|
|
errs = packer.MultiErrorAppend(errs, c.RunConfig.Prepare(&c.ctx)...)
|
|
|
|
|
errs = packer.MultiErrorAppend(errs, c.ShutdownConfig.Prepare(&c.ctx)...)
|
|
|
|
|
errs = packer.MultiErrorAppend(errs, c.SSHConfig.Prepare(&c.ctx)...)
|
|
|
|
|
errs = packer.MultiErrorAppend(errs, c.ToolsConfig.Prepare(&c.ctx)...)
|
|
|
|
|
|
|
|
|
|
if c.SourcePath == "" {
|
|
|
|
|
errs = packer.MultiErrorAppend(errs, fmt.Errorf("source_path is required"))
|
|
|
|
|
|