2019-05-31 14:27:41 +02:00
|
|
|
//go:generate struct-markdown
|
2019-10-14 16:43:59 +02:00
|
|
|
//go:generate mapstructure-to-hcl2 -type Config
|
2019-05-31 14:27:41 +02:00
|
|
|
|
2014-04-06 19:21:22 +02:00
|
|
|
package pvm
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2014-08-12 14:52:27 +02:00
|
|
|
"os"
|
|
|
|
|
2017-04-04 13:39:01 -07:00
|
|
|
parallelscommon "github.com/hashicorp/packer/builder/parallels/common"
|
|
|
|
"github.com/hashicorp/packer/common"
|
2018-04-18 14:53:59 -07:00
|
|
|
"github.com/hashicorp/packer/common/bootcommand"
|
2019-06-13 17:23:21 +02:00
|
|
|
"github.com/hashicorp/packer/common/shutdowncommand"
|
2017-04-04 13:39:01 -07:00
|
|
|
"github.com/hashicorp/packer/helper/config"
|
|
|
|
"github.com/hashicorp/packer/packer"
|
|
|
|
"github.com/hashicorp/packer/template/interpolate"
|
2014-04-06 19:21:22 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// Config is the configuration structure for the builder.
|
|
|
|
type Config struct {
|
|
|
|
common.PackerConfig `mapstructure:",squash"`
|
2016-07-26 20:42:04 +01:00
|
|
|
common.FloppyConfig `mapstructure:",squash"`
|
2014-04-06 19:21:22 +02:00
|
|
|
parallelscommon.OutputConfig `mapstructure:",squash"`
|
2014-09-02 11:53:21 +04:00
|
|
|
parallelscommon.PrlctlConfig `mapstructure:",squash"`
|
2015-05-03 11:18:48 +02:00
|
|
|
parallelscommon.PrlctlPostConfig `mapstructure:",squash"`
|
2014-09-02 11:53:21 +04:00
|
|
|
parallelscommon.PrlctlVersionConfig `mapstructure:",squash"`
|
2014-04-06 19:21:22 +02:00
|
|
|
parallelscommon.SSHConfig `mapstructure:",squash"`
|
2019-06-13 17:23:21 +02:00
|
|
|
shutdowncommand.ShutdownConfig `mapstructure:",squash"`
|
2018-04-18 14:20:34 -07:00
|
|
|
bootcommand.BootConfig `mapstructure:",squash"`
|
2014-09-02 11:53:21 +04:00
|
|
|
parallelscommon.ToolsConfig `mapstructure:",squash"`
|
2019-05-28 17:50:58 +02:00
|
|
|
// The path to a PVM directory that acts as the source
|
2019-06-06 16:29:25 +02:00
|
|
|
// of this build.
|
|
|
|
SourcePath string `mapstructure:"source_path" required:"true"`
|
2019-05-28 17:50:58 +02:00
|
|
|
// Virtual disk image is compacted at the end of
|
2019-06-06 16:29:25 +02:00
|
|
|
// the build process using prl_disk_tool utility (except for the case that
|
|
|
|
// disk_type is set to plain). In certain rare cases, this might corrupt
|
|
|
|
// the resulting disk image. If you find this to be the case, you can disable
|
|
|
|
// compaction using this configuration value.
|
|
|
|
SkipCompaction bool `mapstructure:"skip_compaction" required:"false"`
|
2019-05-28 17:50:58 +02:00
|
|
|
// This is the name of the PVM directory for the new
|
2019-06-06 16:29:25 +02:00
|
|
|
// virtual machine, without the file extension. By default this is
|
|
|
|
// "packer-BUILDNAME", where "BUILDNAME" is the name of the build.
|
|
|
|
VMName string `mapstructure:"vm_name" required:"false"`
|
2019-05-28 17:50:58 +02:00
|
|
|
// If this is "false" the MAC address of the first
|
2019-06-06 16:29:25 +02:00
|
|
|
// NIC will reused when imported else a new MAC address will be generated
|
|
|
|
// by Parallels. Defaults to "false".
|
|
|
|
ReassignMAC bool `mapstructure:"reassign_mac" required:"false"`
|
2014-04-06 19:21:22 +02:00
|
|
|
|
2015-05-27 13:51:24 -07:00
|
|
|
ctx interpolate.Context
|
2014-04-06 19:21:22 +02:00
|
|
|
}
|
|
|
|
|
2019-12-17 11:25:56 +01:00
|
|
|
func (c *Config) Prepare(raws ...interface{}) ([]string, error) {
|
2015-06-12 14:00:59 -07:00
|
|
|
err := config.Decode(c, &config.DecodeOpts{
|
2020-10-21 16:07:18 -07:00
|
|
|
PluginType: parallelscommon.BuilderId,
|
2015-06-22 09:22:42 -07:00
|
|
|
Interpolate: true,
|
|
|
|
InterpolateContext: &c.ctx,
|
2015-05-27 13:51:24 -07:00
|
|
|
InterpolateFilter: &interpolate.RenderFilter{
|
|
|
|
Exclude: []string{
|
|
|
|
"boot_command",
|
|
|
|
"prlctl",
|
2015-10-15 09:26:11 +02:00
|
|
|
"prlctl_post",
|
2015-08-12 10:28:06 +02:00
|
|
|
"parallels_tools_guest_path",
|
2015-05-27 13:51:24 -07:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}, raws...)
|
2014-04-06 19:21:22 +02:00
|
|
|
if err != nil {
|
2019-12-17 11:25:56 +01:00
|
|
|
return nil, err
|
2014-04-06 19:21:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if c.VMName == "" {
|
|
|
|
c.VMName = fmt.Sprintf("packer-%s-{{timestamp}}", c.PackerBuildName)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prepare the errors
|
2015-05-27 13:51:24 -07: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 12:46:13 -07:00
|
|
|
errs = packer.MultiErrorAppend(errs, c.PrlctlPostConfig.Prepare(&c.ctx)...)
|
2015-05-27 13:51:24 -07:00
|
|
|
errs = packer.MultiErrorAppend(errs, c.PrlctlVersionConfig.Prepare(&c.ctx)...)
|
2018-04-18 14:20:34 -07:00
|
|
|
errs = packer.MultiErrorAppend(errs, c.BootConfig.Prepare(&c.ctx)...)
|
2015-05-27 13:51:24 -07: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 23:39:00 +02:00
|
|
|
|
2014-04-06 19:21:22 +02: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 {
|
2019-12-17 11:25:56 +01:00
|
|
|
return warnings, errs
|
2014-04-06 19:21:22 +02:00
|
|
|
}
|
|
|
|
|
2019-12-17 11:25:56 +01:00
|
|
|
return warnings, nil
|
2014-04-06 19:21:22 +02:00
|
|
|
}
|