2014-09-02 03:53:21 -04:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
2015-05-27 16:49:31 -04:00
|
|
|
|
2017-04-04 16:39:01 -04:00
|
|
|
"github.com/hashicorp/packer/template/interpolate"
|
2014-09-02 03:53:21 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// These are the different valid mode values for "parallels_tools_mode" which
|
|
|
|
// determine how guest additions are delivered to the guest.
|
|
|
|
const (
|
|
|
|
ParallelsToolsModeDisable string = "disable"
|
|
|
|
ParallelsToolsModeAttach = "attach"
|
|
|
|
ParallelsToolsModeUpload = "upload"
|
|
|
|
)
|
|
|
|
|
2016-12-16 14:51:55 -05:00
|
|
|
// ToolsConfig contains the builder configuration related to Parallels Tools.
|
2014-09-02 03:53:21 -04:00
|
|
|
type ToolsConfig struct {
|
2019-05-28 11:50:58 -04:00
|
|
|
// The flavor of the Parallels Tools ISO to
|
|
|
|
// install into the VM. Valid values are "win", "lin", "mac", "os2"
|
|
|
|
// and "other". This can be omitted only if parallels_tools_mode
|
|
|
|
// is "disable".
|
|
|
|
ParallelsToolsFlavor string `mapstructure:"parallels_tools_flavor" required:"true"`
|
|
|
|
// The path in the virtual machine to
|
|
|
|
// upload Parallels Tools. This only takes effect if parallels_tools_mode
|
|
|
|
// is "upload". This is a configuration
|
|
|
|
// template that has a single
|
|
|
|
// valid variable: Flavor, which will be the value of
|
|
|
|
// parallels_tools_flavor. By default this is "prl-tools-{{.Flavor}}.iso"
|
|
|
|
// which should upload into the login directory of the user.
|
|
|
|
ParallelsToolsGuestPath string `mapstructure:"parallels_tools_guest_path" required:"false"`
|
|
|
|
// The method by which Parallels Tools are
|
|
|
|
// made available to the guest for installation. Valid options are "upload",
|
|
|
|
// "attach", or "disable". If the mode is "attach" the Parallels Tools ISO will
|
|
|
|
// be attached as a CD device to the virtual machine. If the mode is "upload"
|
|
|
|
// the Parallels Tools ISO will be uploaded to the path specified by
|
|
|
|
// parallels_tools_guest_path. The default value is "upload".
|
|
|
|
ParallelsToolsMode string `mapstructure:"parallels_tools_mode" required:"false"`
|
2014-09-02 03:53:21 -04:00
|
|
|
}
|
|
|
|
|
2016-12-16 14:51:55 -05:00
|
|
|
// Prepare validates & sets up configuration options related to Parallels Tools.
|
2015-05-27 16:49:31 -04:00
|
|
|
func (c *ToolsConfig) Prepare(ctx *interpolate.Context) []error {
|
2014-09-02 03:53:21 -04:00
|
|
|
if c.ParallelsToolsMode == "" {
|
|
|
|
c.ParallelsToolsMode = ParallelsToolsModeUpload
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.ParallelsToolsGuestPath == "" {
|
|
|
|
c.ParallelsToolsGuestPath = "prl-tools-{{.Flavor}}.iso"
|
|
|
|
}
|
|
|
|
|
|
|
|
validMode := false
|
|
|
|
validModes := []string{
|
|
|
|
ParallelsToolsModeDisable,
|
|
|
|
ParallelsToolsModeAttach,
|
|
|
|
ParallelsToolsModeUpload,
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, mode := range validModes {
|
|
|
|
if c.ParallelsToolsMode == mode {
|
|
|
|
validMode = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-27 16:49:31 -04:00
|
|
|
var errs []error
|
2014-09-02 03:53:21 -04:00
|
|
|
if !validMode {
|
|
|
|
errs = append(errs,
|
|
|
|
fmt.Errorf("parallels_tools_mode is invalid. Must be one of: %v",
|
|
|
|
validModes))
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.ParallelsToolsFlavor == "" {
|
|
|
|
if c.ParallelsToolsMode != ParallelsToolsModeDisable {
|
2016-12-11 17:37:41 -05:00
|
|
|
errs = append(errs, errors.New("parallels_tools_flavor must be specified"))
|
2014-09-02 03:53:21 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return errs
|
|
|
|
}
|