packer-cn/config.go

49 lines
1.4 KiB
Go
Raw Normal View History

package main
import (
"github.com/hashicorp/packer/common"
"github.com/hashicorp/packer/helper/communicator"
"github.com/hashicorp/packer/helper/config"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer/template/interpolate"
)
type Config struct {
common.PackerConfig `mapstructure:",squash"`
ConnectConfig `mapstructure:",squash"`
CloneConfig `mapstructure:",squash"`
HardwareConfig `mapstructure:",squash"`
communicator.Config `mapstructure:",squash"`
ShutdownConfig `mapstructure:",squash"`
CreateSnapshot bool `mapstructure:"create_snapshot"`
ConvertToTemplate bool `mapstructure:"convert_to_template"`
2017-07-01 11:32:16 -04:00
ctx interpolate.Context
}
func NewConfig(raws ...interface{}) (*Config, []string, error) {
c := new(Config)
2017-07-01 11:32:16 -04:00
{
err := config.Decode(c, &config.DecodeOpts{
Interpolate: true,
InterpolateContext: &c.ctx,
}, raws...)
if err != nil {
return nil, nil, err
}
}
errs := new(packer.MultiError)
errs = packer.MultiErrorAppend(errs, c.Config.Prepare(&c.ctx)...)
errs = packer.MultiErrorAppend(errs, c.ConnectConfig.Prepare()...)
errs = packer.MultiErrorAppend(errs, c.CloneConfig.Prepare()...)
2017-07-01 17:50:01 -04:00
errs = packer.MultiErrorAppend(errs, c.HardwareConfig.Prepare()...)
2017-07-01 20:06:02 -04:00
errs = packer.MultiErrorAppend(errs, c.ShutdownConfig.Prepare()...)
if len(errs.Errors) > 0 {
return nil, nil, errs
}
return c, nil, nil
}