Validate virtualbox_version_file and guest_additions_mode when communicator is none
This commit is contained in:
parent
8853fc1946
commit
0263503c45
|
@ -1,9 +0,0 @@
|
||||||
package common
|
|
||||||
|
|
||||||
// These are the different valid mode values for "guest_additions_mode" which
|
|
||||||
// determine how guest additions are delivered to the guest.
|
|
||||||
const (
|
|
||||||
GuestAdditionsModeDisable string = "disable"
|
|
||||||
GuestAdditionsModeAttach = "attach"
|
|
||||||
GuestAdditionsModeUpload = "upload"
|
|
||||||
)
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
package common
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/hashicorp/packer/template/interpolate"
|
||||||
|
)
|
||||||
|
|
||||||
|
// These are the different valid mode values for "guest_additions_mode" which
|
||||||
|
// determine how guest additions are delivered to the guest.
|
||||||
|
const (
|
||||||
|
GuestAdditionsModeDisable string = "disable"
|
||||||
|
GuestAdditionsModeAttach = "attach"
|
||||||
|
GuestAdditionsModeUpload = "upload"
|
||||||
|
)
|
||||||
|
|
||||||
|
type GuestAdditionsConfig struct {
|
||||||
|
Communicator string `mapstructure:"communicator"`
|
||||||
|
GuestAdditionsMode string `mapstructure:"guest_additions_mode"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *GuestAdditionsConfig) Prepare(ctx *interpolate.Context) []error {
|
||||||
|
var errs []error
|
||||||
|
|
||||||
|
if c.Communicator == "none" && c.GuestAdditionsMode != "disable" {
|
||||||
|
errs = append(errs, fmt.Errorf("guest_additions_mode has to be "+
|
||||||
|
"'disable' when communicator = 'none'."))
|
||||||
|
}
|
||||||
|
|
||||||
|
return errs
|
||||||
|
}
|
|
@ -1,18 +1,28 @@
|
||||||
package common
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/hashicorp/packer/template/interpolate"
|
"github.com/hashicorp/packer/template/interpolate"
|
||||||
)
|
)
|
||||||
|
|
||||||
type VBoxVersionConfig struct {
|
type VBoxVersionConfig struct {
|
||||||
|
Communicator string `mapstructure:"communicator"`
|
||||||
VBoxVersionFile *string `mapstructure:"virtualbox_version_file"`
|
VBoxVersionFile *string `mapstructure:"virtualbox_version_file"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *VBoxVersionConfig) Prepare(ctx *interpolate.Context) []error {
|
func (c *VBoxVersionConfig) Prepare(ctx *interpolate.Context) []error {
|
||||||
|
var errs []error
|
||||||
|
|
||||||
if c.VBoxVersionFile == nil {
|
if c.VBoxVersionFile == nil {
|
||||||
default_file := ".vbox_version"
|
default_file := ".vbox_version"
|
||||||
c.VBoxVersionFile = &default_file
|
c.VBoxVersionFile = &default_file
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
if c.Communicator == "none" && *c.VBoxVersionFile != "" {
|
||||||
|
errs = append(errs, fmt.Errorf("virtualbox_version_file has to be an "+
|
||||||
|
"empty string when communicator = 'none'."))
|
||||||
|
}
|
||||||
|
|
||||||
|
return errs
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,7 @@ type Config struct {
|
||||||
vboxcommon.VBoxManagePostConfig `mapstructure:",squash"`
|
vboxcommon.VBoxManagePostConfig `mapstructure:",squash"`
|
||||||
vboxcommon.VBoxVersionConfig `mapstructure:",squash"`
|
vboxcommon.VBoxVersionConfig `mapstructure:",squash"`
|
||||||
vboxcommon.VBoxBundleConfig `mapstructure:",squash"`
|
vboxcommon.VBoxBundleConfig `mapstructure:",squash"`
|
||||||
|
vboxcommon.GuestAdditionsConfig `mapstructure:",squash"`
|
||||||
|
|
||||||
DiskSize uint `mapstructure:"disk_size"`
|
DiskSize uint `mapstructure:"disk_size"`
|
||||||
GuestAdditionsMode string `mapstructure:"guest_additions_mode"`
|
GuestAdditionsMode string `mapstructure:"guest_additions_mode"`
|
||||||
|
@ -101,6 +102,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
|
||||||
errs = packer.MultiErrorAppend(errs, b.config.VBoxManagePostConfig.Prepare(&b.config.ctx)...)
|
errs = packer.MultiErrorAppend(errs, b.config.VBoxManagePostConfig.Prepare(&b.config.ctx)...)
|
||||||
errs = packer.MultiErrorAppend(errs, b.config.VBoxVersionConfig.Prepare(&b.config.ctx)...)
|
errs = packer.MultiErrorAppend(errs, b.config.VBoxVersionConfig.Prepare(&b.config.ctx)...)
|
||||||
errs = packer.MultiErrorAppend(errs, b.config.BootConfig.Prepare(&b.config.ctx)...)
|
errs = packer.MultiErrorAppend(errs, b.config.BootConfig.Prepare(&b.config.ctx)...)
|
||||||
|
errs = packer.MultiErrorAppend(errs, b.config.GuestAdditionsConfig.Prepare(&b.config.ctx)...)
|
||||||
|
|
||||||
if b.config.DiskSize == 0 {
|
if b.config.DiskSize == 0 {
|
||||||
b.config.DiskSize = 40000
|
b.config.DiskSize = 40000
|
||||||
|
|
|
@ -28,6 +28,7 @@ type Config struct {
|
||||||
vboxcommon.VBoxManageConfig `mapstructure:",squash"`
|
vboxcommon.VBoxManageConfig `mapstructure:",squash"`
|
||||||
vboxcommon.VBoxManagePostConfig `mapstructure:",squash"`
|
vboxcommon.VBoxManagePostConfig `mapstructure:",squash"`
|
||||||
vboxcommon.VBoxVersionConfig `mapstructure:",squash"`
|
vboxcommon.VBoxVersionConfig `mapstructure:",squash"`
|
||||||
|
vboxcommon.GuestAdditionsConfig `mapstructure:",squash"`
|
||||||
|
|
||||||
Checksum string `mapstructure:"checksum"`
|
Checksum string `mapstructure:"checksum"`
|
||||||
ChecksumType string `mapstructure:"checksum_type"`
|
ChecksumType string `mapstructure:"checksum_type"`
|
||||||
|
@ -97,6 +98,7 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
|
||||||
errs = packer.MultiErrorAppend(errs, c.VBoxManagePostConfig.Prepare(&c.ctx)...)
|
errs = packer.MultiErrorAppend(errs, c.VBoxManagePostConfig.Prepare(&c.ctx)...)
|
||||||
errs = packer.MultiErrorAppend(errs, c.VBoxVersionConfig.Prepare(&c.ctx)...)
|
errs = packer.MultiErrorAppend(errs, c.VBoxVersionConfig.Prepare(&c.ctx)...)
|
||||||
errs = packer.MultiErrorAppend(errs, c.BootConfig.Prepare(&c.ctx)...)
|
errs = packer.MultiErrorAppend(errs, c.BootConfig.Prepare(&c.ctx)...)
|
||||||
|
errs = packer.MultiErrorAppend(errs, c.GuestAdditionsConfig.Prepare(&c.ctx)...)
|
||||||
|
|
||||||
c.ChecksumType = strings.ToLower(c.ChecksumType)
|
c.ChecksumType = strings.ToLower(c.ChecksumType)
|
||||||
c.Checksum = strings.ToLower(c.Checksum)
|
c.Checksum = strings.ToLower(c.Checksum)
|
||||||
|
|
Loading…
Reference in New Issue