packer-cn/iso/config.go

60 lines
1.9 KiB
Go
Raw Normal View History

package iso
import (
packerCommon "github.com/hashicorp/packer/common"
"github.com/hashicorp/packer/helper/communicator"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer/template/interpolate"
"github.com/jetbrains-infra/packer-builder-vsphere/common"
2018-05-06 17:26:04 -04:00
"github.com/hashicorp/packer/helper/config"
)
type Config struct {
2018-05-06 17:26:04 -04:00
packerCommon.PackerConfig `mapstructure:",squash"`
2018-05-06 17:26:04 -04:00
common.ConnectConfig `mapstructure:",squash"`
CreateConfig `mapstructure:",squash"`
2018-05-06 17:26:04 -04:00
common.LocationConfig `mapstructure:",squash"`
2018-05-05 17:41:14 -04:00
common.HardwareConfig `mapstructure:",squash"`
common.ConfigParamsConfig `mapstructure:",squash"`
2018-05-06 17:26:04 -04:00
CDRomConfig `mapstructure:",squash"`
FloppyConfig `mapstructure:",squash"`
common.RunConfig `mapstructure:",squash"`
BootConfig `mapstructure:",squash"`
Comm communicator.Config `mapstructure:",squash"`
common.ShutdownConfig `mapstructure:",squash"`
CreateSnapshot bool `mapstructure:"create_snapshot"`
ConvertToTemplate bool `mapstructure:"convert_to_template"`
ctx interpolate.Context
}
func NewConfig(raws ...interface{}) (*Config, []string, error) {
c := new(Config)
2018-05-06 17:26:04 -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.ConnectConfig.Prepare()...)
2018-05-06 17:26:04 -04:00
errs = packer.MultiErrorAppend(errs, c.CreateConfig.Prepare()...)
errs = packer.MultiErrorAppend(errs, c.LocationConfig.Prepare()...)
errs = packer.MultiErrorAppend(errs, c.HardwareConfig.Prepare()...)
2018-05-06 17:26:04 -04:00
errs = packer.MultiErrorAppend(errs, c.BootConfig.Prepare()...)
errs = packer.MultiErrorAppend(errs, c.Comm.Prepare(&c.ctx)...)
errs = packer.MultiErrorAppend(errs, c.ShutdownConfig.Prepare()...)
if len(errs.Errors) > 0 {
return nil, nil, errs
}
return c, nil, nil
}