2018-01-24 09:56:14 -05:00
|
|
|
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-02-01 07:50:12 -05:00
|
|
|
"fmt"
|
2018-01-24 09:56:14 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
type Config struct {
|
2018-01-30 12:25:05 -05:00
|
|
|
packerCommon.PackerConfig `mapstructure:",squash"`
|
|
|
|
common.RunConfig `mapstructure:",squash"`
|
2018-02-17 21:13:56 -05:00
|
|
|
BootConfig `mapstructure:",squash"`
|
2018-01-30 12:25:05 -05:00
|
|
|
common.ConnectConfig `mapstructure:",squash"`
|
|
|
|
Comm communicator.Config `mapstructure:",squash"`
|
|
|
|
common.ShutdownConfig `mapstructure:",squash"`
|
|
|
|
CreateSnapshot bool `mapstructure:"create_snapshot"`
|
|
|
|
ConvertToTemplate bool `mapstructure:"convert_to_template"`
|
2018-01-24 09:56:14 -05:00
|
|
|
|
|
|
|
CreateConfig `mapstructure:",squash"`
|
|
|
|
CDRomConfig `mapstructure:",squash"`
|
2018-01-30 11:45:56 -05:00
|
|
|
FloppyConfig `mapstructure:",squash"`
|
2018-02-26 16:18:06 -05:00
|
|
|
ConfigParamsConfig `mapstructure:",squash"`
|
2018-01-24 09:56:14 -05:00
|
|
|
|
|
|
|
ctx interpolate.Context
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewConfig(raws ...interface{}) (*Config, []string, error) {
|
|
|
|
c := new(Config)
|
|
|
|
if err := common.DecodeConfig(c, &c.ctx, raws...); err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
errs := new(packer.MultiError)
|
|
|
|
errs = packer.MultiErrorAppend(errs, c.Comm.Prepare(&c.ctx)...)
|
2018-01-30 12:25:05 -05:00
|
|
|
errs = packer.MultiErrorAppend(errs, c.RunConfig.Prepare()...)
|
2018-01-24 09:56:14 -05:00
|
|
|
errs = packer.MultiErrorAppend(errs, c.ConnectConfig.Prepare()...)
|
|
|
|
errs = packer.MultiErrorAppend(errs, c.HardwareConfig.Prepare()...)
|
2018-02-01 07:50:12 -05:00
|
|
|
if c.DiskSize <= 0 {
|
|
|
|
errs = packer.MultiErrorAppend(errs, fmt.Errorf("'disk_size' must be provided"))
|
|
|
|
}
|
2018-01-24 09:56:14 -05:00
|
|
|
errs = packer.MultiErrorAppend(errs, c.ShutdownConfig.Prepare()...)
|
|
|
|
errs = packer.MultiErrorAppend(errs, c.CreateConfig.Prepare()...)
|
|
|
|
|
|
|
|
if len(errs.Errors) > 0 {
|
|
|
|
return nil, nil, errs
|
|
|
|
}
|
|
|
|
|
|
|
|
return c, nil, nil
|
|
|
|
}
|