Commit b2b74431 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

builder/parallels/pvm: interpolation

parent 76c2d2cb
...@@ -68,7 +68,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe ...@@ -68,7 +68,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
new(parallelscommon.StepAttachFloppy), new(parallelscommon.StepAttachFloppy),
&parallelscommon.StepPrlctl{ &parallelscommon.StepPrlctl{
Commands: b.config.Prlctl, Commands: b.config.Prlctl,
Tpl: b.config.tpl, Ctx: b.config.ctx,
}, },
&parallelscommon.StepRun{ &parallelscommon.StepRun{
BootWait: b.config.BootWait, BootWait: b.config.BootWait,
...@@ -78,7 +78,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe ...@@ -78,7 +78,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
BootCommand: b.config.BootCommand, BootCommand: b.config.BootCommand,
HostInterfaces: []string{}, HostInterfaces: []string{},
VMName: b.config.VMName, VMName: b.config.VMName,
Tpl: b.config.tpl, Ctx: b.config.ctx,
}, },
&common.StepConnectSSH{ &common.StepConnectSSH{
SSHAddress: parallelscommon.SSHAddress, SSHAddress: parallelscommon.SSHAddress,
...@@ -92,7 +92,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe ...@@ -92,7 +92,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
ParallelsToolsFlavor: b.config.ParallelsToolsFlavor, ParallelsToolsFlavor: b.config.ParallelsToolsFlavor,
ParallelsToolsGuestPath: b.config.ParallelsToolsGuestPath, ParallelsToolsGuestPath: b.config.ParallelsToolsGuestPath,
ParallelsToolsMode: b.config.ParallelsToolsMode, ParallelsToolsMode: b.config.ParallelsToolsMode,
Tpl: b.config.tpl, Ctx: b.config.ctx,
}, },
new(common.StepProvision), new(common.StepProvision),
&parallelscommon.StepShutdown{ &parallelscommon.StepShutdown{
......
...@@ -6,7 +6,9 @@ import ( ...@@ -6,7 +6,9 @@ import (
parallelscommon "github.com/mitchellh/packer/builder/parallels/common" parallelscommon "github.com/mitchellh/packer/builder/parallels/common"
"github.com/mitchellh/packer/common" "github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/helper/config"
"github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/template/interpolate"
) )
// Config is the configuration structure for the builder. // Config is the configuration structure for the builder.
...@@ -26,57 +28,39 @@ type Config struct { ...@@ -26,57 +28,39 @@ type Config struct {
VMName string `mapstructure:"vm_name"` VMName string `mapstructure:"vm_name"`
ReassignMac bool `mapstructure:"reassign_mac"` ReassignMac bool `mapstructure:"reassign_mac"`
tpl *packer.ConfigTemplate ctx interpolate.Context
} }
func NewConfig(raws ...interface{}) (*Config, []string, error) { func NewConfig(raws ...interface{}) (*Config, []string, error) {
c := new(Config) 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 { if err != nil {
return nil, nil, err return nil, nil, err
} }
c.tpl, err = packer.NewConfigTemplate()
if err != nil {
return nil, nil, err
}
c.tpl.UserVars = c.PackerUserVars
if c.VMName == "" { if c.VMName == "" {
c.VMName = fmt.Sprintf("packer-%s-{{timestamp}}", c.PackerBuildName) c.VMName = fmt.Sprintf("packer-%s-{{timestamp}}", c.PackerBuildName)
} }
// Prepare the errors // Prepare the errors
errs := common.CheckUnusedConfig(md) var errs *packer.MultiError
errs = packer.MultiErrorAppend(errs, c.FloppyConfig.Prepare(c.tpl)...) errs = packer.MultiErrorAppend(errs, c.FloppyConfig.Prepare(&c.ctx)...)
errs = packer.MultiErrorAppend(errs, c.OutputConfig.Prepare(c.tpl, &c.PackerConfig)...) errs = packer.MultiErrorAppend(errs, c.OutputConfig.Prepare(&c.ctx, &c.PackerConfig)...)
errs = packer.MultiErrorAppend(errs, c.PrlctlConfig.Prepare(c.tpl)...) errs = packer.MultiErrorAppend(errs, c.PrlctlConfig.Prepare(&c.ctx)...)
errs = packer.MultiErrorAppend(errs, c.PrlctlVersionConfig.Prepare(c.tpl)...) errs = packer.MultiErrorAppend(errs, c.PrlctlVersionConfig.Prepare(&c.ctx)...)
errs = packer.MultiErrorAppend(errs, c.RunConfig.Prepare(c.tpl)...) errs = packer.MultiErrorAppend(errs, c.RunConfig.Prepare(&c.ctx)...)
errs = packer.MultiErrorAppend(errs, c.ShutdownConfig.Prepare(c.tpl)...) errs = packer.MultiErrorAppend(errs, c.ShutdownConfig.Prepare(&c.ctx)...)
errs = packer.MultiErrorAppend(errs, c.SSHConfig.Prepare(c.tpl)...) errs = packer.MultiErrorAppend(errs, c.SSHConfig.Prepare(&c.ctx)...)
errs = packer.MultiErrorAppend(errs, c.ToolsConfig.Prepare(c.tpl)...) errs = packer.MultiErrorAppend(errs, c.ToolsConfig.Prepare(&c.ctx)...)
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))
}
}
if c.SourcePath == "" { if c.SourcePath == "" {
errs = packer.MultiErrorAppend(errs, fmt.Errorf("source_path is required")) errs = packer.MultiErrorAppend(errs, fmt.Errorf("source_path is required"))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment