virtualbox merge vbpx manage configs

This commit is contained in:
Adrien Delorme 2019-06-19 17:07:23 +02:00
parent 01eff9472a
commit 74f0d56cfc
7 changed files with 63 additions and 85 deletions

View File

@ -7,17 +7,21 @@ import (
)
type VBoxManageConfig struct {
// Custom VBoxManage commands to
// execute in order to further customize the virtual machine being created. The
// value of this is an array of commands to execute. The commands are executed
// in the order defined in the template. For each command, the command is
// defined itself as an array of strings, where each string represents a single
// argument on the command-line to VBoxManage (but excluding
// VBoxManage itself). Each arg is treated as a configuration
// template, where the Name
// variable is replaced with the VM name. More details on how to use
// VBoxManage are below.
// Custom `VBoxManage` commands to execute in order to further customize
// the virtual machine being created. The value of this is an array of
// commands to execute. The commands are executed in the order defined in
// the template. For each command, the command is defined itself as an
// array of strings, where each string represents a single argument on the
// command-line to `VBoxManage` (but excluding `VBoxManage` itself). Each
// arg is treated as a [configuration
// template](/docs/templates/engine.html), where the `Name` variable is
// replaced with the VM name. More details on how to use `VBoxManage` are
// below.
VBoxManage [][]string `mapstructure:"vboxmanage" required:"false"`
// Identical to vboxmanage,
// except that it is run after the virtual machine is shutdown, and before the
// virtual machine is exported.
VBoxManagePost [][]string `mapstructure:"vboxmanage_post" required:"false"`
}
func (c *VBoxManageConfig) Prepare(ctx *interpolate.Context) []error {
@ -25,5 +29,9 @@ func (c *VBoxManageConfig) Prepare(ctx *interpolate.Context) []error {
c.VBoxManage = make([][]string, 0)
}
if c.VBoxManagePost == nil {
c.VBoxManagePost = make([][]string, 0)
}
return nil
}

View File

@ -37,3 +37,34 @@ func TestVBoxManageConfigPrepare_VBoxManage(t *testing.T) {
t.Fatalf("bad: %#v", c.VBoxManage)
}
}
func TestVBoxManageConfigPrepare_PostVBoxManage(t *testing.T) {
// Test with empty
c := new(VBoxManageConfig)
errs := c.Prepare(interpolate.NewContext())
if len(errs) > 0 {
t.Fatalf("err: %#v", errs)
}
if !reflect.DeepEqual(c.VBoxManagePost, [][]string{}) {
t.Fatalf("bad: %#v", c.VBoxManagePost)
}
// Test with a good one
c = new(VBoxManageConfig)
c.VBoxManagePost = [][]string{
{"foo", "bar", "baz"},
}
errs = c.Prepare(interpolate.NewContext())
if len(errs) > 0 {
t.Fatalf("err: %#v", errs)
}
expected := [][]string{
{"foo", "bar", "baz"},
}
if !reflect.DeepEqual(c.VBoxManagePost, expected) {
t.Fatalf("bad: %#v", c.VBoxManagePost)
}
}

View File

@ -1,22 +0,0 @@
//go:generate struct-markdown
package common
import (
"github.com/hashicorp/packer/template/interpolate"
)
type VBoxManagePostConfig struct {
// Identical to vboxmanage,
// except that it is run after the virtual machine is shutdown, and before the
// virtual machine is exported.
VBoxManagePost [][]string `mapstructure:"vboxmanage_post" required:"false"`
}
func (c *VBoxManagePostConfig) Prepare(ctx *interpolate.Context) []error {
if c.VBoxManagePost == nil {
c.VBoxManagePost = make([][]string, 0)
}
return nil
}

View File

@ -1,39 +0,0 @@
package common
import (
"reflect"
"testing"
"github.com/hashicorp/packer/template/interpolate"
)
func TestVBoxManagePostConfigPrepare_VBoxManage(t *testing.T) {
// Test with empty
c := new(VBoxManagePostConfig)
errs := c.Prepare(interpolate.NewContext())
if len(errs) > 0 {
t.Fatalf("err: %#v", errs)
}
if !reflect.DeepEqual(c.VBoxManagePost, [][]string{}) {
t.Fatalf("bad: %#v", c.VBoxManagePost)
}
// Test with a good one
c = new(VBoxManagePostConfig)
c.VBoxManagePost = [][]string{
{"foo", "bar", "baz"},
}
errs = c.Prepare(interpolate.NewContext())
if len(errs) > 0 {
t.Fatalf("err: %#v", errs)
}
expected := [][]string{
{"foo", "bar", "baz"},
}
if !reflect.DeepEqual(c.VBoxManagePost, expected) {
t.Fatalf("bad: %#v", c.VBoxManagePost)
}
}

View File

@ -38,7 +38,6 @@ type Config struct {
vboxcommon.SSHConfig `mapstructure:",squash"`
vboxcommon.HWConfig `mapstructure:",squash"`
vboxcommon.VBoxManageConfig `mapstructure:",squash"`
vboxcommon.VBoxManagePostConfig `mapstructure:",squash"`
vboxcommon.VBoxVersionConfig `mapstructure:",squash"`
vboxcommon.VBoxBundleConfig `mapstructure:",squash"`
vboxcommon.GuestAdditionsConfig `mapstructure:",squash"`
@ -156,7 +155,6 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
errs = packer.MultiErrorAppend(errs, b.config.HWConfig.Prepare(&b.config.ctx)...)
errs = packer.MultiErrorAppend(errs, b.config.VBoxBundleConfig.Prepare(&b.config.ctx)...)
errs = packer.MultiErrorAppend(errs, b.config.VBoxManageConfig.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.BootConfig.Prepare(&b.config.ctx)...)
errs = packer.MultiErrorAppend(errs, b.config.GuestAdditionsConfig.Prepare(&b.config.ctx)...)

View File

@ -27,7 +27,6 @@ type Config struct {
vboxcommon.SSHConfig `mapstructure:",squash"`
vboxcommon.ShutdownConfig `mapstructure:",squash"`
vboxcommon.VBoxManageConfig `mapstructure:",squash"`
vboxcommon.VBoxManagePostConfig `mapstructure:",squash"`
vboxcommon.VBoxVersionConfig `mapstructure:",squash"`
vboxcommon.GuestAdditionsConfig `mapstructure:",squash"`
// The checksum for the source_path file. The
@ -152,7 +151,6 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
errs = packer.MultiErrorAppend(errs, c.ShutdownConfig.Prepare(&c.ctx)...)
errs = packer.MultiErrorAppend(errs, c.SSHConfig.Prepare(&c.ctx)...)
errs = packer.MultiErrorAppend(errs, c.VBoxManageConfig.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.BootConfig.Prepare(&c.ctx)...)
errs = packer.MultiErrorAppend(errs, c.GuestAdditionsConfig.Prepare(&c.ctx)...)

View File

@ -1,13 +1,17 @@
<!-- Code generated from the comments of the VBoxManageConfig struct in builder/virtualbox/common/vboxmanage_config.go; DO NOT EDIT MANUALLY -->
- `vboxmanage` ([][]string) - Custom VBoxManage commands to
execute in order to further customize the virtual machine being created. The
value of this is an array of commands to execute. The commands are executed
in the order defined in the template. For each command, the command is
defined itself as an array of strings, where each string represents a single
argument on the command-line to VBoxManage (but excluding
VBoxManage itself). Each arg is treated as a configuration
template, where the Name
variable is replaced with the VM name. More details on how to use
VBoxManage are below.
- `vboxmanage` ([][]string) - Custom `VBoxManage` commands to execute in order to further customize
the virtual machine being created. The value of this is an array of
commands to execute. The commands are executed in the order defined in
the template. For each command, the command is defined itself as an
array of strings, where each string represents a single argument on the
command-line to `VBoxManage` (but excluding `VBoxManage` itself). Each
arg is treated as a [configuration
template](/docs/templates/engine.html), where the `Name` variable is
replaced with the VM name. More details on how to use `VBoxManage` are
below.
- `vboxmanage_post` ([][]string) - Identical to vboxmanage,
except that it is run after the virtual machine is shutdown, and before the
virtual machine is exported.