From 74f0d56cfc8e93aec8ef381ca085c9f6e98e5b54 Mon Sep 17 00:00:00 2001 From: Adrien Delorme Date: Wed, 19 Jun 2019 17:07:23 +0200 Subject: [PATCH] virtualbox merge vbpx manage configs --- .../virtualbox/common/vboxmanage_config.go | 28 ++++++++----- .../common/vboxmanage_config_test.go | 31 +++++++++++++++ .../common/vboxmanage_post_config.go | 22 ----------- .../common/vboxmanage_post_config_test.go | 39 ------------------- builder/virtualbox/iso/builder.go | 2 - builder/virtualbox/ovf/config.go | 2 - .../_VBoxManageConfig-not-required.html.md | 24 +++++++----- 7 files changed, 63 insertions(+), 85 deletions(-) delete mode 100644 builder/virtualbox/common/vboxmanage_post_config.go delete mode 100644 builder/virtualbox/common/vboxmanage_post_config_test.go diff --git a/builder/virtualbox/common/vboxmanage_config.go b/builder/virtualbox/common/vboxmanage_config.go index c58f89601..75c845a29 100644 --- a/builder/virtualbox/common/vboxmanage_config.go +++ b/builder/virtualbox/common/vboxmanage_config.go @@ -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 } diff --git a/builder/virtualbox/common/vboxmanage_config_test.go b/builder/virtualbox/common/vboxmanage_config_test.go index 7a283384f..a35fe2cae 100644 --- a/builder/virtualbox/common/vboxmanage_config_test.go +++ b/builder/virtualbox/common/vboxmanage_config_test.go @@ -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) + } +} diff --git a/builder/virtualbox/common/vboxmanage_post_config.go b/builder/virtualbox/common/vboxmanage_post_config.go deleted file mode 100644 index 69b69933e..000000000 --- a/builder/virtualbox/common/vboxmanage_post_config.go +++ /dev/null @@ -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 -} diff --git a/builder/virtualbox/common/vboxmanage_post_config_test.go b/builder/virtualbox/common/vboxmanage_post_config_test.go deleted file mode 100644 index c6f7d3049..000000000 --- a/builder/virtualbox/common/vboxmanage_post_config_test.go +++ /dev/null @@ -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) - } -} diff --git a/builder/virtualbox/iso/builder.go b/builder/virtualbox/iso/builder.go index 71bdbae96..d59e0b679 100644 --- a/builder/virtualbox/iso/builder.go +++ b/builder/virtualbox/iso/builder.go @@ -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)...) diff --git a/builder/virtualbox/ovf/config.go b/builder/virtualbox/ovf/config.go index 313493657..b33607732 100644 --- a/builder/virtualbox/ovf/config.go +++ b/builder/virtualbox/ovf/config.go @@ -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)...) diff --git a/website/source/partials/builder/virtualbox/common/_VBoxManageConfig-not-required.html.md b/website/source/partials/builder/virtualbox/common/_VBoxManageConfig-not-required.html.md index 970f5281a..fb76e81b7 100644 --- a/website/source/partials/builder/virtualbox/common/_VBoxManageConfig-not-required.html.md +++ b/website/source/partials/builder/virtualbox/common/_VBoxManageConfig-not-required.html.md @@ -1,13 +1,17 @@ -- `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. \ No newline at end of file