2014-04-06 13:21:22 -04:00
|
|
|
package pvm
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2014-08-12 08:52:27 -04:00
|
|
|
"os"
|
|
|
|
|
2017-04-04 16:39:01 -04:00
|
|
|
parallelscommon "github.com/hashicorp/packer/builder/parallels/common"
|
|
|
|
"github.com/hashicorp/packer/common"
|
2018-04-18 17:53:59 -04:00
|
|
|
"github.com/hashicorp/packer/common/bootcommand"
|
2017-04-04 16:39:01 -04:00
|
|
|
"github.com/hashicorp/packer/helper/config"
|
|
|
|
"github.com/hashicorp/packer/packer"
|
|
|
|
"github.com/hashicorp/packer/template/interpolate"
|
2014-04-06 13:21:22 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// Config is the configuration structure for the builder.
|
|
|
|
type Config struct {
|
|
|
|
common.PackerConfig `mapstructure:",squash"`
|
2016-07-26 15:42:04 -04:00
|
|
|
common.FloppyConfig `mapstructure:",squash"`
|
2014-04-06 13:21:22 -04:00
|
|
|
parallelscommon.OutputConfig `mapstructure:",squash"`
|
2014-09-02 03:53:21 -04:00
|
|
|
parallelscommon.PrlctlConfig `mapstructure:",squash"`
|
2015-05-03 05:18:48 -04:00
|
|
|
parallelscommon.PrlctlPostConfig `mapstructure:",squash"`
|
2014-09-02 03:53:21 -04:00
|
|
|
parallelscommon.PrlctlVersionConfig `mapstructure:",squash"`
|
2014-04-06 13:21:22 -04:00
|
|
|
parallelscommon.SSHConfig `mapstructure:",squash"`
|
|
|
|
parallelscommon.ShutdownConfig `mapstructure:",squash"`
|
2018-04-18 17:20:34 -04:00
|
|
|
bootcommand.BootConfig `mapstructure:",squash"`
|
2014-09-02 03:53:21 -04:00
|
|
|
parallelscommon.ToolsConfig `mapstructure:",squash"`
|
2014-04-06 13:21:22 -04:00
|
|
|
|
2018-04-26 08:09:17 -04:00
|
|
|
SourcePath string `mapstructure:"source_path"`
|
|
|
|
SkipCompaction bool `mapstructure:"skip_compaction"`
|
|
|
|
VMName string `mapstructure:"vm_name"`
|
|
|
|
ReassignMAC bool `mapstructure:"reassign_mac"`
|
2014-04-06 13:21:22 -04:00
|
|
|
|
2015-05-27 16:51:24 -04:00
|
|
|
ctx interpolate.Context
|
2014-04-06 13:21:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewConfig(raws ...interface{}) (*Config, []string, error) {
|
|
|
|
c := new(Config)
|
2015-06-12 17:00:59 -04:00
|
|
|
err := config.Decode(c, &config.DecodeOpts{
|
2015-06-22 12:22:42 -04:00
|
|
|
Interpolate: true,
|
|
|
|
InterpolateContext: &c.ctx,
|
2015-05-27 16:51:24 -04:00
|
|
|
InterpolateFilter: &interpolate.RenderFilter{
|
|
|
|
Exclude: []string{
|
|
|
|
"boot_command",
|
|
|
|
"prlctl",
|
2015-10-15 03:26:11 -04:00
|
|
|
"prlctl_post",
|
2015-08-12 04:28:06 -04:00
|
|
|
"parallels_tools_guest_path",
|
2015-05-27 16:51:24 -04:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}, raws...)
|
2014-04-06 13:21:22 -04:00
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.VMName == "" {
|
|
|
|
c.VMName = fmt.Sprintf("packer-%s-{{timestamp}}", c.PackerBuildName)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prepare the errors
|
2015-05-27 16:51:24 -04:00
|
|
|
var errs *packer.MultiError
|
|
|
|
errs = packer.MultiErrorAppend(errs, c.FloppyConfig.Prepare(&c.ctx)...)
|
|
|
|
errs = packer.MultiErrorAppend(errs, c.OutputConfig.Prepare(&c.ctx, &c.PackerConfig)...)
|
|
|
|
errs = packer.MultiErrorAppend(errs, c.PrlctlConfig.Prepare(&c.ctx)...)
|
2015-06-22 15:46:13 -04:00
|
|
|
errs = packer.MultiErrorAppend(errs, c.PrlctlPostConfig.Prepare(&c.ctx)...)
|
2015-05-27 16:51:24 -04:00
|
|
|
errs = packer.MultiErrorAppend(errs, c.PrlctlVersionConfig.Prepare(&c.ctx)...)
|
2018-04-18 17:20:34 -04:00
|
|
|
errs = packer.MultiErrorAppend(errs, c.BootConfig.Prepare(&c.ctx)...)
|
2015-05-27 16:51:24 -04:00
|
|
|
errs = packer.MultiErrorAppend(errs, c.ShutdownConfig.Prepare(&c.ctx)...)
|
|
|
|
errs = packer.MultiErrorAppend(errs, c.SSHConfig.Prepare(&c.ctx)...)
|
|
|
|
errs = packer.MultiErrorAppend(errs, c.ToolsConfig.Prepare(&c.ctx)...)
|
2014-05-13 17:39:00 -04:00
|
|
|
|
2014-04-06 13:21:22 -04:00
|
|
|
if c.SourcePath == "" {
|
|
|
|
errs = packer.MultiErrorAppend(errs, fmt.Errorf("source_path is required"))
|
|
|
|
} else {
|
|
|
|
if _, err := os.Stat(c.SourcePath); err != nil {
|
|
|
|
errs = packer.MultiErrorAppend(errs,
|
|
|
|
fmt.Errorf("source_path is invalid: %s", err))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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.")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for any errors.
|
|
|
|
if errs != nil && len(errs.Errors) > 0 {
|
|
|
|
return nil, warnings, errs
|
|
|
|
}
|
|
|
|
|
|
|
|
return c, warnings, nil
|
|
|
|
}
|