github.com/emate/packer@v0.8.1-0.20150625195101-fe0fde195dc6/builder/parallels/pvm/config.go (about) 1 package pvm 2 3 import ( 4 "fmt" 5 "os" 6 7 parallelscommon "github.com/mitchellh/packer/builder/parallels/common" 8 "github.com/mitchellh/packer/common" 9 "github.com/mitchellh/packer/helper/config" 10 "github.com/mitchellh/packer/packer" 11 "github.com/mitchellh/packer/template/interpolate" 12 ) 13 14 // Config is the configuration structure for the builder. 15 type Config struct { 16 common.PackerConfig `mapstructure:",squash"` 17 parallelscommon.FloppyConfig `mapstructure:",squash"` 18 parallelscommon.OutputConfig `mapstructure:",squash"` 19 parallelscommon.PrlctlConfig `mapstructure:",squash"` 20 parallelscommon.PrlctlPostConfig `mapstructure:",squash"` 21 parallelscommon.PrlctlVersionConfig `mapstructure:",squash"` 22 parallelscommon.RunConfig `mapstructure:",squash"` 23 parallelscommon.SSHConfig `mapstructure:",squash"` 24 parallelscommon.ShutdownConfig `mapstructure:",squash"` 25 parallelscommon.ToolsConfig `mapstructure:",squash"` 26 27 BootCommand []string `mapstructure:"boot_command"` 28 SourcePath string `mapstructure:"source_path"` 29 VMName string `mapstructure:"vm_name"` 30 ReassignMac bool `mapstructure:"reassign_mac"` 31 32 ctx interpolate.Context 33 } 34 35 func NewConfig(raws ...interface{}) (*Config, []string, error) { 36 c := new(Config) 37 err := config.Decode(c, &config.DecodeOpts{ 38 Interpolate: true, 39 InterpolateContext: &c.ctx, 40 InterpolateFilter: &interpolate.RenderFilter{ 41 Exclude: []string{ 42 "boot_command", 43 "prlctl", 44 "parallel_tools_guest_path", 45 }, 46 }, 47 }, raws...) 48 if err != nil { 49 return nil, nil, err 50 } 51 52 if c.VMName == "" { 53 c.VMName = fmt.Sprintf("packer-%s-{{timestamp}}", c.PackerBuildName) 54 } 55 56 // Prepare the errors 57 var errs *packer.MultiError 58 errs = packer.MultiErrorAppend(errs, c.FloppyConfig.Prepare(&c.ctx)...) 59 errs = packer.MultiErrorAppend(errs, c.OutputConfig.Prepare(&c.ctx, &c.PackerConfig)...) 60 errs = packer.MultiErrorAppend(errs, c.PrlctlConfig.Prepare(&c.ctx)...) 61 errs = packer.MultiErrorAppend(errs, c.PrlctlPostConfig.Prepare(&c.ctx)...) 62 errs = packer.MultiErrorAppend(errs, c.PrlctlVersionConfig.Prepare(&c.ctx)...) 63 errs = packer.MultiErrorAppend(errs, c.RunConfig.Prepare(&c.ctx)...) 64 errs = packer.MultiErrorAppend(errs, c.ShutdownConfig.Prepare(&c.ctx)...) 65 errs = packer.MultiErrorAppend(errs, c.SSHConfig.Prepare(&c.ctx)...) 66 errs = packer.MultiErrorAppend(errs, c.ToolsConfig.Prepare(&c.ctx)...) 67 68 if c.SourcePath == "" { 69 errs = packer.MultiErrorAppend(errs, fmt.Errorf("source_path is required")) 70 } else { 71 if _, err := os.Stat(c.SourcePath); err != nil { 72 errs = packer.MultiErrorAppend(errs, 73 fmt.Errorf("source_path is invalid: %s", err)) 74 } 75 } 76 77 // Warnings 78 var warnings []string 79 if c.ShutdownCommand == "" { 80 warnings = append(warnings, 81 "A shutdown_command was not specified. Without a shutdown command, Packer\n"+ 82 "will forcibly halt the virtual machine, which may result in data loss.") 83 } 84 85 // Check for any errors. 86 if errs != nil && len(errs.Errors) > 0 { 87 return nil, warnings, errs 88 } 89 90 return c, warnings, nil 91 }