Commit d15bc904 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

builder/virtualbox/iso: new interpolation

parent b2b74431
...@@ -2,32 +2,20 @@ package common ...@@ -2,32 +2,20 @@ package common
import ( import (
"errors" "errors"
"fmt"
"github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/template/interpolate"
) )
type ExportConfig struct { type ExportConfig struct {
Format string `mapstruture:"format"` Format string `mapstruture:"format"`
} }
func (c *ExportConfig) Prepare(t *packer.ConfigTemplate) []error { func (c *ExportConfig) Prepare(ctx *interpolate.Context) []error {
if c.Format == "" { if c.Format == "" {
c.Format = "ovf" c.Format = "ovf"
} }
templates := map[string]*string{ var errs []error
"format": &c.Format,
}
errs := make([]error, 0)
for n, ptr := range templates {
var err error
*ptr, err = t.Process(*ptr, nil)
if err != nil {
errs = append(errs, fmt.Errorf("Error processing %s: %s", n, err))
}
}
if c.Format != "ovf" && c.Format != "ova" { if c.Format != "ovf" && c.Format != "ova" {
errs = append(errs, errs = append(errs,
errors.New("invalid format, only 'ovf' or 'ova' are allowed")) errors.New("invalid format, only 'ovf' or 'ova' are allowed"))
......
package common package common
import ( import (
"fmt" "github.com/mitchellh/packer/template/interpolate"
"github.com/mitchellh/packer/packer"
) )
type ExportOpts struct { type ExportOpts struct {
ExportOpts []string `mapstructure:"export_opts"` ExportOpts []string `mapstructure:"export_opts"`
} }
func (c *ExportOpts) Prepare(t *packer.ConfigTemplate) []error { func (c *ExportOpts) Prepare(ctx *interpolate.Context) []error {
if c.ExportOpts == nil { if c.ExportOpts == nil {
c.ExportOpts = make([]string, 0) c.ExportOpts = make([]string, 0)
} }
errs := make([]error, 0) return nil
for i, str := range c.ExportOpts {
var err error
c.ExportOpts[i], err = t.Process(str, nil)
if err != nil {
errs = append(errs, fmt.Errorf("Error processing %s: %s", "export_opts", err))
}
}
return errs
} }
package common package common
import ( import (
"fmt" "github.com/mitchellh/packer/template/interpolate"
"github.com/mitchellh/packer/packer"
) )
// FloppyConfig is configuration related to created floppy disks and attaching // FloppyConfig is configuration related to created floppy disks and attaching
...@@ -12,20 +10,10 @@ type FloppyConfig struct { ...@@ -12,20 +10,10 @@ type FloppyConfig struct {
FloppyFiles []string `mapstructure:"floppy_files"` FloppyFiles []string `mapstructure:"floppy_files"`
} }
func (c *FloppyConfig) Prepare(t *packer.ConfigTemplate) []error { func (c *FloppyConfig) Prepare(ctx *interpolate.Context) []error {
if c.FloppyFiles == nil { if c.FloppyFiles == nil {
c.FloppyFiles = make([]string, 0) c.FloppyFiles = make([]string, 0)
} }
errs := make([]error, 0) return nil
for i, file := range c.FloppyFiles {
var err error
c.FloppyFiles[i], err = t.Process(file, nil)
if err != nil {
errs = append(errs, fmt.Errorf(
"Error processing floppy_files[%d]: %s", i, err))
}
}
return errs
} }
...@@ -2,33 +2,22 @@ package common ...@@ -2,33 +2,22 @@ package common
import ( import (
"fmt" "fmt"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/packer"
"os" "os"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/template/interpolate"
) )
type OutputConfig struct { type OutputConfig struct {
OutputDir string `mapstructure:"output_directory"` OutputDir string `mapstructure:"output_directory"`
} }
func (c *OutputConfig) Prepare(t *packer.ConfigTemplate, pc *common.PackerConfig) []error { func (c *OutputConfig) Prepare(ctx *interpolate.Context, pc *common.PackerConfig) []error {
if c.OutputDir == "" { if c.OutputDir == "" {
c.OutputDir = fmt.Sprintf("output-%s", pc.PackerBuildName) c.OutputDir = fmt.Sprintf("output-%s", pc.PackerBuildName)
} }
templates := map[string]*string{ var errs []error
"output_directory": &c.OutputDir,
}
errs := make([]error, 0)
for n, ptr := range templates {
var err error
*ptr, err = t.Process(*ptr, nil)
if err != nil {
errs = append(errs, fmt.Errorf("Error processing %s: %s", n, err))
}
}
if !pc.PackerForce { if !pc.PackerForce {
if _, err := os.Stat(c.OutputDir); err == nil { if _, err := os.Stat(c.OutputDir); err == nil {
errs = append(errs, fmt.Errorf( errs = append(errs, fmt.Errorf(
......
...@@ -5,7 +5,7 @@ import ( ...@@ -5,7 +5,7 @@ import (
"fmt" "fmt"
"time" "time"
"github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/template/interpolate"
) )
type RunConfig struct { type RunConfig struct {
...@@ -19,7 +19,7 @@ type RunConfig struct { ...@@ -19,7 +19,7 @@ type RunConfig struct {
BootWait time.Duration `` BootWait time.Duration ``
} }
func (c *RunConfig) Prepare(t *packer.ConfigTemplate) []error { func (c *RunConfig) Prepare(ctx *interpolate.Context) []error {
if c.RawBootWait == "" { if c.RawBootWait == "" {
c.RawBootWait = "10s" c.RawBootWait = "10s"
} }
...@@ -32,20 +32,7 @@ func (c *RunConfig) Prepare(t *packer.ConfigTemplate) []error { ...@@ -32,20 +32,7 @@ func (c *RunConfig) Prepare(t *packer.ConfigTemplate) []error {
c.HTTPPortMax = 9000 c.HTTPPortMax = 9000
} }
templates := map[string]*string{ var errs []error
"boot_wait": &c.RawBootWait,
"http_directory": &c.HTTPDir,
}
errs := make([]error, 0)
for n, ptr := range templates {
var err error
*ptr, err = t.Process(*ptr, nil)
if err != nil {
errs = append(errs, fmt.Errorf("Error processing %s: %s", n, err))
}
}
var err error var err error
c.BootWait, err = time.ParseDuration(c.RawBootWait) c.BootWait, err = time.ParseDuration(c.RawBootWait)
if err != nil { if err != nil {
......
...@@ -2,8 +2,9 @@ package common ...@@ -2,8 +2,9 @@ package common
import ( import (
"fmt" "fmt"
"github.com/mitchellh/packer/packer"
"time" "time"
"github.com/mitchellh/packer/template/interpolate"
) )
type ShutdownConfig struct { type ShutdownConfig struct {
...@@ -13,25 +14,12 @@ type ShutdownConfig struct { ...@@ -13,25 +14,12 @@ type ShutdownConfig struct {
ShutdownTimeout time.Duration `` ShutdownTimeout time.Duration ``
} }
func (c *ShutdownConfig) Prepare(t *packer.ConfigTemplate) []error { func (c *ShutdownConfig) Prepare(ctx *interpolate.Context) []error {
if c.RawShutdownTimeout == "" { if c.RawShutdownTimeout == "" {
c.RawShutdownTimeout = "5m" c.RawShutdownTimeout = "5m"
} }
templates := map[string]*string{ var errs []error
"shutdown_command": &c.ShutdownCommand,
"shutdown_timeout": &c.RawShutdownTimeout,
}
errs := make([]error, 0)
for n, ptr := range templates {
var err error
*ptr, err = t.Process(*ptr, nil)
if err != nil {
errs = append(errs, fmt.Errorf("Error processing %s: %s", n, err))
}
}
var err error var err error
c.ShutdownTimeout, err = time.ParseDuration(c.RawShutdownTimeout) c.ShutdownTimeout, err = time.ParseDuration(c.RawShutdownTimeout)
if err != nil { if err != nil {
......
...@@ -7,7 +7,7 @@ import ( ...@@ -7,7 +7,7 @@ import (
"time" "time"
commonssh "github.com/mitchellh/packer/common/ssh" commonssh "github.com/mitchellh/packer/common/ssh"
"github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/template/interpolate"
) )
type SSHConfig struct { type SSHConfig struct {
...@@ -22,7 +22,7 @@ type SSHConfig struct { ...@@ -22,7 +22,7 @@ type SSHConfig struct {
SSHWaitTimeout time.Duration SSHWaitTimeout time.Duration
} }
func (c *SSHConfig) Prepare(t *packer.ConfigTemplate) []error { func (c *SSHConfig) Prepare(ctx *interpolate.Context) []error {
if c.SSHHostPortMin == 0 { if c.SSHHostPortMin == 0 {
c.SSHHostPortMin = 2222 c.SSHHostPortMin = 2222
} }
...@@ -39,22 +39,7 @@ func (c *SSHConfig) Prepare(t *packer.ConfigTemplate) []error { ...@@ -39,22 +39,7 @@ func (c *SSHConfig) Prepare(t *packer.ConfigTemplate) []error {
c.RawSSHWaitTimeout = "20m" c.RawSSHWaitTimeout = "20m"
} }
templates := map[string]*string{ var errs []error
"ssh_key_path": &c.SSHKeyPath,
"ssh_password": &c.SSHPassword,
"ssh_username": &c.SSHUser,
"ssh_wait_timeout": &c.RawSSHWaitTimeout,
}
errs := make([]error, 0)
for n, ptr := range templates {
var err error
*ptr, err = t.Process(*ptr, nil)
if err != nil {
errs = append(errs, fmt.Errorf("Error processing %s: %s", n, err))
}
}
if c.SSHKeyPath != "" { if c.SSHKeyPath != "" {
if _, err := os.Stat(c.SSHKeyPath); err != nil { if _, err := os.Stat(c.SSHKeyPath); err != nil {
errs = append(errs, fmt.Errorf("ssh_key_path is invalid: %s", err)) errs = append(errs, fmt.Errorf("ssh_key_path is invalid: %s", err))
......
...@@ -3,14 +3,16 @@ package common ...@@ -3,14 +3,16 @@ package common
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/packer"
"io" "io"
"io/ioutil" "io/ioutil"
"log" "log"
"os" "os"
"strings" "strings"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/template/interpolate"
) )
var additionsVersionMap = map[string]string{ var additionsVersionMap = map[string]string{
...@@ -31,7 +33,7 @@ type StepDownloadGuestAdditions struct { ...@@ -31,7 +33,7 @@ type StepDownloadGuestAdditions struct {
GuestAdditionsMode string GuestAdditionsMode string
GuestAdditionsURL string GuestAdditionsURL string
GuestAdditionsSHA256 string GuestAdditionsSHA256 string
Tpl *packer.ConfigTemplate Ctx interpolate.Context
} }
func (s *StepDownloadGuestAdditions) Run(state multistep.StateBag) multistep.StepAction { func (s *StepDownloadGuestAdditions) Run(state multistep.StateBag) multistep.StepAction {
...@@ -67,11 +69,11 @@ func (s *StepDownloadGuestAdditions) Run(state multistep.StateBag) multistep.Ste ...@@ -67,11 +69,11 @@ func (s *StepDownloadGuestAdditions) Run(state multistep.StateBag) multistep.Ste
// Use the provided source (URL or file path) or generate it // Use the provided source (URL or file path) or generate it
url := s.GuestAdditionsURL url := s.GuestAdditionsURL
if url != "" { if url != "" {
tplData := &guestAdditionsUrlTemplate{ s.Ctx.Data = &guestAdditionsUrlTemplate{
Version: version, Version: version,
} }
url, err = s.Tpl.Process(url, tplData) url, err = interpolate.Render(url, &s.Ctx)
if err != nil { if err != nil {
err := fmt.Errorf("Error preparing guest additions url: %s", err) err := fmt.Errorf("Error preparing guest additions url: %s", err)
state.Put("error", err) state.Put("error", err)
......
...@@ -2,13 +2,15 @@ package common ...@@ -2,13 +2,15 @@ package common
import ( import (
"fmt" "fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"log" "log"
"strings" "strings"
"time" "time"
"unicode" "unicode"
"unicode/utf8" "unicode/utf8"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/template/interpolate"
) )
const KeyLeftShift uint32 = 0xFFE1 const KeyLeftShift uint32 = 0xFFE1
...@@ -32,7 +34,7 @@ type bootCommandTemplateData struct { ...@@ -32,7 +34,7 @@ type bootCommandTemplateData struct {
type StepTypeBootCommand struct { type StepTypeBootCommand struct {
BootCommand []string BootCommand []string
VMName string VMName string
Tpl *packer.ConfigTemplate Ctx interpolate.Context
} }
func (s *StepTypeBootCommand) Run(state multistep.StateBag) multistep.StepAction { func (s *StepTypeBootCommand) Run(state multistep.StateBag) multistep.StepAction {
...@@ -41,7 +43,7 @@ func (s *StepTypeBootCommand) Run(state multistep.StateBag) multistep.StepAction ...@@ -41,7 +43,7 @@ func (s *StepTypeBootCommand) Run(state multistep.StateBag) multistep.StepAction
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)
vmName := state.Get("vmName").(string) vmName := state.Get("vmName").(string)
tplData := &bootCommandTemplateData{ s.Ctx.Data = &bootCommandTemplateData{
"10.0.2.2", "10.0.2.2",
httpPort, httpPort,
s.VMName, s.VMName,
...@@ -49,7 +51,7 @@ func (s *StepTypeBootCommand) Run(state multistep.StateBag) multistep.StepAction ...@@ -49,7 +51,7 @@ func (s *StepTypeBootCommand) Run(state multistep.StateBag) multistep.StepAction
ui.Say("Typing the boot command...") ui.Say("Typing the boot command...")
for _, command := range s.BootCommand { for _, command := range s.BootCommand {
command, err := s.Tpl.Process(command, tplData) command, err := interpolate.Render(command, &s.Ctx)
if err != nil { if err != nil {
err := fmt.Errorf("Error preparing boot command: %s", err) err := fmt.Errorf("Error preparing boot command: %s", err)
state.Put("error", err) state.Put("error", err)
......
...@@ -2,10 +2,12 @@ package common ...@@ -2,10 +2,12 @@ package common
import ( import (
"fmt" "fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"log" "log"
"os" "os"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/template/interpolate"
) )
type guestAdditionsPathTemplate struct { type guestAdditionsPathTemplate struct {
...@@ -16,7 +18,7 @@ type guestAdditionsPathTemplate struct { ...@@ -16,7 +18,7 @@ type guestAdditionsPathTemplate struct {
type StepUploadGuestAdditions struct { type StepUploadGuestAdditions struct {
GuestAdditionsMode string GuestAdditionsMode string
GuestAdditionsPath string GuestAdditionsPath string
Tpl *packer.ConfigTemplate Ctx interpolate.Context
} }
func (s *StepUploadGuestAdditions) Run(state multistep.StateBag) multistep.StepAction { func (s *StepUploadGuestAdditions) Run(state multistep.StateBag) multistep.StepAction {
...@@ -45,11 +47,11 @@ func (s *StepUploadGuestAdditions) Run(state multistep.StateBag) multistep.StepA ...@@ -45,11 +47,11 @@ func (s *StepUploadGuestAdditions) Run(state multistep.StateBag) multistep.StepA
return multistep.ActionHalt return multistep.ActionHalt
} }
tplData := &guestAdditionsPathTemplate{ s.Ctx.Data = &guestAdditionsPathTemplate{
Version: version, Version: version,
} }
s.GuestAdditionsPath, err = s.Tpl.Process(s.GuestAdditionsPath, tplData) s.GuestAdditionsPath, err = interpolate.Render(s.GuestAdditionsPath, &s.Ctx)
if err != nil { if err != nil {
err := fmt.Errorf("Error preparing guest additions path: %s", err) err := fmt.Errorf("Error preparing guest additions path: %s", err)
state.Put("error", err) state.Put("error", err)
......
...@@ -2,9 +2,11 @@ package common ...@@ -2,9 +2,11 @@ package common
import ( import (
"fmt" "fmt"
"strings"
"github.com/mitchellh/multistep" "github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/packer"
"strings" "github.com/mitchellh/packer/template/interpolate"
) )
type commandTemplate struct { type commandTemplate struct {
...@@ -22,7 +24,7 @@ type commandTemplate struct { ...@@ -22,7 +24,7 @@ type commandTemplate struct {
// Produces: // Produces:
type StepVBoxManage struct { type StepVBoxManage struct {
Commands [][]string Commands [][]string
Tpl *packer.ConfigTemplate Ctx interpolate.Context
} }
func (s *StepVBoxManage) Run(state multistep.StateBag) multistep.StepAction { func (s *StepVBoxManage) Run(state multistep.StateBag) multistep.StepAction {
...@@ -34,7 +36,7 @@ func (s *StepVBoxManage) Run(state multistep.StateBag) multistep.StepAction { ...@@ -34,7 +36,7 @@ func (s *StepVBoxManage) Run(state multistep.StateBag) multistep.StepAction {
ui.Say("Executing custom VBoxManage commands...") ui.Say("Executing custom VBoxManage commands...")
} }
tplData := &commandTemplate{ s.Ctx.Data = &commandTemplate{
Name: vmName, Name: vmName,
} }
...@@ -44,7 +46,7 @@ func (s *StepVBoxManage) Run(state multistep.StateBag) multistep.StepAction { ...@@ -44,7 +46,7 @@ func (s *StepVBoxManage) Run(state multistep.StateBag) multistep.StepAction {
for i, arg := range command { for i, arg := range command {
var err error var err error
command[i], err = s.Tpl.Process(arg, tplData) command[i], err = interpolate.Render(arg, &s.Ctx)
if err != nil { if err != nil {
err := fmt.Errorf("Error preparing vboxmanage command: %s", err) err := fmt.Errorf("Error preparing vboxmanage command: %s", err)
state.Put("error", err) state.Put("error", err)
......
package common package common
import ( import (
"fmt" "github.com/mitchellh/packer/template/interpolate"
"github.com/mitchellh/packer/packer"
) )
type VBoxVersionConfig struct { type VBoxVersionConfig struct {
VBoxVersionFile string `mapstructure:"virtualbox_version_file"` VBoxVersionFile string `mapstructure:"virtualbox_version_file"`
} }
func (c *VBoxVersionConfig) Prepare(t *packer.ConfigTemplate) []error { func (c *VBoxVersionConfig) Prepare(ctx *interpolate.Context) []error {
if c.VBoxVersionFile == "" { if c.VBoxVersionFile == "" {
c.VBoxVersionFile = ".vbox_version" c.VBoxVersionFile = ".vbox_version"
} }
templates := map[string]*string{ return nil
"virtualbox_version_file": &c.VBoxVersionFile,
}
errs := make([]error, 0)
for n, ptr := range templates {
var err error
*ptr, err = t.Process(*ptr, nil)
if err != nil {
errs = append(errs, fmt.Errorf("Error processing %s: %s", n, err))
}
}
return errs
} }
package common package common
import ( import (
"fmt" "github.com/mitchellh/packer/template/interpolate"
"github.com/mitchellh/packer/packer"
) )
type VBoxManageConfig struct { type VBoxManageConfig struct {
VBoxManage [][]string `mapstructure:"vboxmanage"` VBoxManage [][]string `mapstructure:"vboxmanage"`
} }
func (c *VBoxManageConfig) Prepare(t *packer.ConfigTemplate) []error { func (c *VBoxManageConfig) Prepare(ctx *interpolate.Context) []error {
if c.VBoxManage == nil { if c.VBoxManage == nil {
c.VBoxManage = make([][]string, 0) c.VBoxManage = make([][]string, 0)
} }
errs := make([]error, 0) return nil
for i, args := range c.VBoxManage {
for j, arg := range args {
if err := t.Validate(arg); err != nil {
errs = append(errs,
fmt.Errorf("Error processing vboxmanage[%d][%d]: %s", i, j, err))
}
}
}
return errs
} }
package common package common
import ( import (
"fmt" "github.com/mitchellh/packer/template/interpolate"
"github.com/mitchellh/packer/packer"
) )
type VBoxManagePostConfig struct { type VBoxManagePostConfig struct {
VBoxManagePost [][]string `mapstructure:"vboxmanage_post"` VBoxManagePost [][]string `mapstructure:"vboxmanage_post"`
} }
func (c *VBoxManagePostConfig) Prepare(t *packer.ConfigTemplate) []error { func (c *VBoxManagePostConfig) Prepare(ctx *interpolate.Context) []error {
if c.VBoxManagePost == nil { if c.VBoxManagePost == nil {
c.VBoxManagePost = make([][]string, 0) c.VBoxManagePost = make([][]string, 0)
} }
errs := make([]error, 0) return nil
for i, args := range c.VBoxManagePost {
for j, arg := range args {
if err := t.Validate(arg); err != nil {
errs = append(errs,
fmt.Errorf("Error processing vboxmanage_post[%d][%d]: %s", i, j, err))
}
}
}
return errs
} }
...@@ -11,17 +11,19 @@ import ( ...@@ -11,17 +11,19 @@ import (
"github.com/mitchellh/multistep" "github.com/mitchellh/multistep"
vboxcommon "github.com/mitchellh/packer/builder/virtualbox/common" vboxcommon "github.com/mitchellh/packer/builder/virtualbox/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"
) )
const BuilderId = "mitchellh.virtualbox" const BuilderId = "mitchellh.virtualbox"
type Builder struct { type Builder struct {
config config config Config
runner multistep.Runner runner multistep.Runner
} }
type config struct { type Config struct {
common.PackerConfig `mapstructure:",squash"` common.PackerConfig `mapstructure:",squash"`
vboxcommon.ExportConfig `mapstructure:",squash"` vboxcommon.ExportConfig `mapstructure:",squash"`
vboxcommon.ExportOpts `mapstructure:",squash"` vboxcommon.ExportOpts `mapstructure:",squash"`
...@@ -50,34 +52,39 @@ type config struct { ...@@ -50,34 +52,39 @@ type config struct {
RawSingleISOUrl string `mapstructure:"iso_url"` RawSingleISOUrl string `mapstructure:"iso_url"`
tpl *packer.ConfigTemplate ctx interpolate.Context
} }
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) { func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
md, err := common.DecodeConfig(&b.config, raws...) err := config.Decode(&b.config, &config.DecodeOpts{
if err != nil { Interpolate: true,
return nil, err InterpolateFilter: &interpolate.RenderFilter{
} Exclude: []string{
"boot_command",
b.config.tpl, err = packer.NewConfigTemplate() "guest_additions_path",
"guest_additions_url",
"vboxmanage",
"vboxmanage_post",
},
},
}, raws...)
if err != nil { if err != nil {
return nil, err return nil, err
} }
b.config.tpl.UserVars = b.config.PackerUserVars
// Accumulate any errors and warnings // Accumulate any errors and warnings
errs := common.CheckUnusedConfig(md) var errs *packer.MultiError
errs = packer.MultiErrorAppend(errs, b.config.ExportConfig.Prepare(b.config.tpl)...) errs = packer.MultiErrorAppend(errs, b.config.ExportConfig.Prepare(&b.config.ctx)...)
errs = packer.MultiErrorAppend(errs, b.config.ExportOpts.Prepare(b.config.tpl)...) errs = packer.MultiErrorAppend(errs, b.config.ExportOpts.Prepare(&b.config.ctx)...)
errs = packer.MultiErrorAppend(errs, b.config.FloppyConfig.Prepare(b.config.tpl)...) errs = packer.MultiErrorAppend(errs, b.config.FloppyConfig.Prepare(&b.config.ctx)...)
errs = packer.MultiErrorAppend( errs = packer.MultiErrorAppend(
errs, b.config.OutputConfig.Prepare(b.config.tpl, &b.config.PackerConfig)...) errs, b.config.OutputConfig.Prepare(&b.config.ctx, &b.config.PackerConfig)...)
errs = packer.MultiErrorAppend(errs, b.config.RunConfig.Prepare(b.config.tpl)...) errs = packer.MultiErrorAppend(errs, b.config.RunConfig.Prepare(&b.config.ctx)...)
errs = packer.MultiErrorAppend(errs, b.config.ShutdownConfig.Prepare(b.config.tpl)...) errs = packer.MultiErrorAppend(errs, b.config.ShutdownConfig.Prepare(&b.config.ctx)...)
errs = packer.MultiErrorAppend(errs, b.config.SSHConfig.Prepare(b.config.tpl)...) errs = packer.MultiErrorAppend(errs, b.config.SSHConfig.Prepare(&b.config.ctx)...)
errs = packer.MultiErrorAppend(errs, b.config.VBoxManageConfig.Prepare(b.config.tpl)...) errs = packer.MultiErrorAppend(errs, b.config.VBoxManageConfig.Prepare(&b.config.ctx)...)
errs = packer.MultiErrorAppend(errs, b.config.VBoxManagePostConfig.Prepare(b.config.tpl)...) errs = packer.MultiErrorAppend(errs, b.config.VBoxManagePostConfig.Prepare(&b.config.ctx)...)
errs = packer.MultiErrorAppend(errs, b.config.VBoxVersionConfig.Prepare(b.config.tpl)...) errs = packer.MultiErrorAppend(errs, b.config.VBoxVersionConfig.Prepare(&b.config.ctx)...)
warnings := make([]string, 0) warnings := make([]string, 0)
if b.config.DiskSize == 0 { if b.config.DiskSize == 0 {
...@@ -108,56 +115,6 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) { ...@@ -108,56 +115,6 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
b.config.VMName = fmt.Sprintf("packer-%s-{{timestamp}}", b.config.PackerBuildName) b.config.VMName = fmt.Sprintf("packer-%s-{{timestamp}}", b.config.PackerBuildName)
} }
// Errors
templates := map[string]*string{
"guest_additions_mode": &b.config.GuestAdditionsMode,
"guest_additions_sha256": &b.config.GuestAdditionsSHA256,
"guest_os_type": &b.config.GuestOSType,
"hard_drive_interface": &b.config.HardDriveInterface,
"iso_checksum": &b.config.ISOChecksum,
"iso_checksum_type": &b.config.ISOChecksumType,
"iso_interface": &b.config.ISOInterface,
"iso_url": &b.config.RawSingleISOUrl,
"vm_name": &b.config.VMName,
}
for n, ptr := range templates {
var err error
*ptr, err = b.config.tpl.Process(*ptr, nil)
if err != nil {
errs = packer.MultiErrorAppend(
errs, fmt.Errorf("Error processing %s: %s", n, err))
}
}
for i, url := range b.config.ISOUrls {
var err error
b.config.ISOUrls[i], err = b.config.tpl.Process(url, nil)
if err != nil {
errs = packer.MultiErrorAppend(
errs, fmt.Errorf("Error processing iso_urls[%d]: %s", i, err))
}
}
validates := map[string]*string{
"guest_additions_path": &b.config.GuestAdditionsPath,
"guest_additions_url": &b.config.GuestAdditionsURL,
}
for n, ptr := range validates {
if err := b.config.tpl.Validate(*ptr); err != nil {
errs = packer.MultiErrorAppend(
errs, fmt.Errorf("Error parsing %s: %s", n, err))
}
}
for i, command := range b.config.BootCommand {
if err := b.config.tpl.Validate(command); err != nil {
errs = packer.MultiErrorAppend(errs,
fmt.Errorf("Error processing boot_command[%d]: %s", i, err))
}
}
if b.config.HardDriveInterface != "ide" && b.config.HardDriveInterface != "sata" && b.config.HardDriveInterface != "scsi" { if b.config.HardDriveInterface != "ide" && b.config.HardDriveInterface != "sata" && b.config.HardDriveInterface != "scsi" {
errs = packer.MultiErrorAppend( errs = packer.MultiErrorAppend(
errs, errors.New("hard_drive_interface can only be ide, sata, or scsi")) errs, errors.New("hard_drive_interface can only be ide, sata, or scsi"))
...@@ -265,7 +222,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe ...@@ -265,7 +222,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
GuestAdditionsMode: b.config.GuestAdditionsMode, GuestAdditionsMode: b.config.GuestAdditionsMode,
GuestAdditionsURL: b.config.GuestAdditionsURL, GuestAdditionsURL: b.config.GuestAdditionsURL,
GuestAdditionsSHA256: b.config.GuestAdditionsSHA256, GuestAdditionsSHA256: b.config.GuestAdditionsSHA256,
Tpl: b.config.tpl, Ctx: b.config.ctx,
}, },
&common.StepDownload{ &common.StepDownload{
Checksum: b.config.ISOChecksum, Checksum: b.config.ISOChecksum,
...@@ -301,7 +258,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe ...@@ -301,7 +258,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
}, },
&vboxcommon.StepVBoxManage{ &vboxcommon.StepVBoxManage{
Commands: b.config.VBoxManage, Commands: b.config.VBoxManage,
Tpl: b.config.tpl, Ctx: b.config.ctx,
}, },
&vboxcommon.StepRun{ &vboxcommon.StepRun{
BootWait: b.config.BootWait, BootWait: b.config.BootWait,
...@@ -310,7 +267,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe ...@@ -310,7 +267,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
&vboxcommon.StepTypeBootCommand{ &vboxcommon.StepTypeBootCommand{
BootCommand: b.config.BootCommand, BootCommand: b.config.BootCommand,
VMName: b.config.VMName, VMName: b.config.VMName,
Tpl: b.config.tpl, Ctx: b.config.ctx,
}, },
&common.StepConnectSSH{ &common.StepConnectSSH{
SSHAddress: vboxcommon.SSHAddress, SSHAddress: vboxcommon.SSHAddress,
...@@ -323,7 +280,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe ...@@ -323,7 +280,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
&vboxcommon.StepUploadGuestAdditions{ &vboxcommon.StepUploadGuestAdditions{
GuestAdditionsMode: b.config.GuestAdditionsMode, GuestAdditionsMode: b.config.GuestAdditionsMode,
GuestAdditionsPath: b.config.GuestAdditionsPath, GuestAdditionsPath: b.config.GuestAdditionsPath,
Tpl: b.config.tpl, Ctx: b.config.ctx,
}, },
new(common.StepProvision), new(common.StepProvision),
&vboxcommon.StepShutdown{ &vboxcommon.StepShutdown{
...@@ -333,7 +290,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe ...@@ -333,7 +290,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
new(vboxcommon.StepRemoveDevices), new(vboxcommon.StepRemoveDevices),
&vboxcommon.StepVBoxManage{ &vboxcommon.StepVBoxManage{
Commands: b.config.VBoxManagePost, Commands: b.config.VBoxManagePost,
Tpl: b.config.tpl, Ctx: b.config.ctx,
}, },
&vboxcommon.StepExport{ &vboxcommon.StepExport{
Format: b.config.Format, Format: b.config.Format,
......
...@@ -17,7 +17,7 @@ type stepAttachISO struct { ...@@ -17,7 +17,7 @@ type stepAttachISO struct {
} }
func (s *stepAttachISO) Run(state multistep.StateBag) multistep.StepAction { func (s *stepAttachISO) Run(state multistep.StateBag) multistep.StepAction {
config := state.Get("config").(*config) config := state.Get("config").(*Config)
driver := state.Get("driver").(vboxcommon.Driver) driver := state.Get("driver").(vboxcommon.Driver)
isoPath := state.Get("iso_path").(string) isoPath := state.Get("iso_path").(string)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)
...@@ -65,7 +65,7 @@ func (s *stepAttachISO) Cleanup(state multistep.StateBag) { ...@@ -65,7 +65,7 @@ func (s *stepAttachISO) Cleanup(state multistep.StateBag) {
return return
} }
config := state.Get("config").(*config) config := state.Get("config").(*Config)
driver := state.Get("driver").(vboxcommon.Driver) driver := state.Get("driver").(vboxcommon.Driver)
vmName := state.Get("vmName").(string) vmName := state.Get("vmName").(string)
......
...@@ -15,7 +15,7 @@ import ( ...@@ -15,7 +15,7 @@ import (
type stepCreateDisk struct{} type stepCreateDisk struct{}
func (s *stepCreateDisk) Run(state multistep.StateBag) multistep.StepAction { func (s *stepCreateDisk) Run(state multistep.StateBag) multistep.StepAction {
config := state.Get("config").(*config) config := state.Get("config").(*Config)
driver := state.Get("driver").(vboxcommon.Driver) driver := state.Get("driver").(vboxcommon.Driver)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)
vmName := state.Get("vmName").(string) vmName := state.Get("vmName").(string)
......
...@@ -17,7 +17,7 @@ type stepCreateVM struct { ...@@ -17,7 +17,7 @@ type stepCreateVM struct {
} }
func (s *stepCreateVM) Run(state multistep.StateBag) multistep.StepAction { func (s *stepCreateVM) Run(state multistep.StateBag) multistep.StepAction {
config := state.Get("config").(*config) config := state.Get("config").(*Config)
driver := state.Get("driver").(vboxcommon.Driver) driver := state.Get("driver").(vboxcommon.Driver)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)
......
...@@ -25,7 +25,7 @@ type stepHTTPServer struct { ...@@ -25,7 +25,7 @@ type stepHTTPServer struct {
} }
func (s *stepHTTPServer) Run(state multistep.StateBag) multistep.StepAction { func (s *stepHTTPServer) Run(state multistep.StateBag) multistep.StepAction {
config := state.Get("config").(*config) config := state.Get("config").(*Config)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)
var httpPort uint = 0 var httpPort uint = 0
......
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