packer-cn/builder/vsphere/iso/config.go

93 lines
3.1 KiB
Go
Raw Normal View History

//go:generate struct-markdown
//go:generate mapstructure-to-hcl2 -type Config
package iso
import (
"github.com/hashicorp/packer/builder/vsphere/common"
packerCommon "github.com/hashicorp/packer/common"
"github.com/hashicorp/packer/helper/communicator"
2018-10-31 17:42:24 -04:00
"github.com/hashicorp/packer/helper/config"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer/template/interpolate"
)
type Config struct {
2018-05-06 17:26:04 -04:00
packerCommon.PackerConfig `mapstructure:",squash"`
2018-05-30 07:59:44 -04:00
packerCommon.HTTPConfig `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"`
packerCommon.ISOConfig `mapstructure:",squash"`
CDRomConfig `mapstructure:",squash"`
2020-02-05 10:25:49 -05:00
RemoveCDRomConfig `mapstructure:",squash"`
FloppyConfig `mapstructure:",squash"`
common.RunConfig `mapstructure:",squash"`
BootConfig `mapstructure:",squash"`
common.WaitIpConfig `mapstructure:",squash"`
Comm communicator.Config `mapstructure:",squash"`
2018-10-31 17:42:24 -04:00
common.ShutdownConfig `mapstructure:",squash"`
2018-05-06 17:26:04 -04:00
// Create a snapshot when set to `true`, so the VM can be used as a base
// for linked clones. Defaults to `false`.
CreateSnapshot bool `mapstructure:"create_snapshot"`
// Convert VM to a template. Defaults to `false`.
2018-05-06 17:26:04 -04:00
ConvertToTemplate bool `mapstructure:"convert_to_template"`
// Configuration for exporting VM to an ovf file.
// The VM will not be exported if no [Export Configuration](#export-configuration) is specified.
Export *common.ExportConfig `mapstructure:"export"`
2018-05-06 17:26:04 -04:00
ctx interpolate.Context
}
2020-01-13 14:51:36 -05:00
func (c *Config) Prepare(raws ...interface{}) ([]string, error) {
2018-05-06 17:26:04 -04:00
err := config.Decode(c, &config.DecodeOpts{
Interpolate: true,
InterpolateContext: &c.ctx,
InterpolateFilter: &interpolate.RenderFilter{
Exclude: []string{
"boot_command",
},
},
2018-05-06 17:26:04 -04:00
}, raws...)
if err != nil {
2020-01-13 14:51:36 -05:00
return nil, err
}
warnings := make([]string, 0)
errs := new(packer.MultiError)
if c.ISOUrls != nil || c.RawSingleISOUrl != "" {
isoWarnings, isoErrs := c.ISOConfig.Prepare(&c.ctx)
warnings = append(warnings, isoWarnings...)
errs = packer.MultiErrorAppend(errs, isoErrs...)
}
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-30 07:59:44 -04:00
errs = packer.MultiErrorAppend(errs, c.HTTPConfig.Prepare(&c.ctx)...)
2018-05-06 17:26:04 -04:00
errs = packer.MultiErrorAppend(errs, c.CDRomConfig.Prepare()...)
errs = packer.MultiErrorAppend(errs, c.BootConfig.Prepare(&c.ctx)...)
errs = packer.MultiErrorAppend(errs, c.WaitIpConfig.Prepare()...)
2018-05-06 17:26:04 -04:00
errs = packer.MultiErrorAppend(errs, c.Comm.Prepare(&c.ctx)...)
errs = packer.MultiErrorAppend(errs, c.ShutdownConfig.Prepare()...)
if c.Export != nil {
errs = packer.MultiErrorAppend(errs, c.Export.Prepare(&c.ctx, &c.LocationConfig, &c.PackerConfig)...)
}
if len(errs.Errors) > 0 {
2020-01-13 18:52:05 -05:00
return warnings, errs
}
2020-01-13 18:52:05 -05:00
return warnings, nil
}