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 {
|
|
|
|
ParallelsToolsFlavor string `mapstructure:"parallels_tools_flavor"`
|
|
|
|
ParallelsToolsGuestPath string `mapstructure:"parallels_tools_guest_path"`
|
|
|
|
ParallelsToolsMode string `mapstructure:"parallels_tools_mode"`
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|