2013-12-21 20:38:06 -05:00
|
|
|
package ovf
|
|
|
|
|
|
|
|
import (
|
|
|
|
vboxcommon "github.com/mitchellh/packer/builder/virtualbox/common"
|
|
|
|
"github.com/mitchellh/packer/common"
|
|
|
|
"github.com/mitchellh/packer/packer"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Config is the configuration structure for the builder.
|
|
|
|
type Config struct {
|
2013-12-22 14:55:01 -05:00
|
|
|
common.PackerConfig `mapstructure:",squash"`
|
|
|
|
vboxcommon.ExportConfig `mapstructure:",squash"`
|
|
|
|
vboxcommon.FloppyConfig `mapstructure:",squash"`
|
|
|
|
vboxcommon.OutputConfig `mapstructure:",squash"`
|
|
|
|
vboxcommon.RunConfig `mapstructure:",squash"`
|
|
|
|
vboxcommon.SSHConfig `mapstructure:",squash"`
|
|
|
|
vboxcommon.ShutdownConfig `mapstructure:",squash"`
|
|
|
|
vboxcommon.VBoxManageConfig `mapstructure:",squash"`
|
2013-12-22 14:50:29 -05:00
|
|
|
vboxcommon.VBoxVersionConfig `mapstructure:",squash"`
|
2013-12-21 20:38:06 -05:00
|
|
|
|
2013-12-22 18:19:19 -05:00
|
|
|
SourcePath string `mapstructure:"source_path"`
|
|
|
|
|
2013-12-21 20:38:06 -05:00
|
|
|
tpl *packer.ConfigTemplate
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewConfig(raws ...interface{}) (*Config, []string, error) {
|
|
|
|
c := new(Config)
|
|
|
|
md, err := common.DecodeConfig(c, 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
|
|
|
|
|
|
|
|
// Prepare the errors
|
|
|
|
errs := common.CheckUnusedConfig(md)
|
2013-12-22 13:40:39 -05:00
|
|
|
errs = packer.MultiErrorAppend(errs, c.ExportConfig.Prepare(c.tpl)...)
|
2013-12-22 12:08:09 -05:00
|
|
|
errs = packer.MultiErrorAppend(errs, c.FloppyConfig.Prepare(c.tpl)...)
|
2013-12-21 20:38:06 -05:00
|
|
|
errs = packer.MultiErrorAppend(errs, c.OutputConfig.Prepare(c.tpl, &c.PackerConfig)...)
|
2013-12-22 13:30:12 -05:00
|
|
|
errs = packer.MultiErrorAppend(errs, c.RunConfig.Prepare(c.tpl)...)
|
2013-12-22 12:08:09 -05:00
|
|
|
errs = packer.MultiErrorAppend(errs, c.SSHConfig.Prepare(c.tpl)...)
|
2013-12-22 12:24:29 -05:00
|
|
|
errs = packer.MultiErrorAppend(errs, c.VBoxManageConfig.Prepare(c.tpl)...)
|
2013-12-22 14:50:29 -05:00
|
|
|
errs = packer.MultiErrorAppend(errs, c.VBoxVersionConfig.Prepare(c.tpl)...)
|
2013-12-21 20:38:06 -05:00
|
|
|
|
2013-12-22 12:37:27 -05:00
|
|
|
// Warnings
|
|
|
|
var warnings []string
|
|
|
|
if c.ShutdownCommand == "" {
|
|
|
|
warnings = append(warnings,
|
|
|
|
"A shutdown_command was not specified. Without a shutdown command, Packer\n"+
|
|
|
|
"will forcibly halt the virtual machine, which may result in data loss.")
|
|
|
|
}
|
|
|
|
|
2013-12-21 20:38:06 -05:00
|
|
|
// Check for any errors.
|
|
|
|
if errs != nil && len(errs.Errors) > 0 {
|
2013-12-22 12:37:27 -05:00
|
|
|
return nil, warnings, errs
|
2013-12-21 20:38:06 -05:00
|
|
|
}
|
|
|
|
|
2013-12-22 12:37:27 -05:00
|
|
|
return c, warnings, nil
|
2013-12-21 20:38:06 -05:00
|
|
|
}
|