Commit 0332901f authored by Ben Langfeld's avatar Ben Langfeld

builder/virtualbox: Add an `export_opts` option

Allows arbitrary arguments to VBoxManage export, such as product info (--product, --vendor, etc).
parent 3c59d0ef
...@@ -10,6 +10,8 @@ FEATURES: ...@@ -10,6 +10,8 @@ FEATURES:
IMPROVEMENTS: IMPROVEMENTS:
* builder/vmware: Workstation 10 support for Linux. [GH-900] * builder/vmware: Workstation 10 support for Linux. [GH-900]
* builder/virtualbox: Support an `export_opts` option which allows
specifying arbitrary arguments when exporting the VM.
BUG FIXES: BUG FIXES:
......
package common
import (
"fmt"
"github.com/mitchellh/packer/packer"
)
type ExportOpts struct {
ExportOpts string `mapstructure:"export_opts"`
}
func (c *ExportOpts) Prepare(t *packer.ConfigTemplate) []error {
templates := map[string]*string{
"export_opts": &c.ExportOpts,
}
errs := make([]error, 0)
for n, ptr := range templates {
var err error
*ptr, err = t.Process(*ptr, nil)
if err != nil {
errs = append(errs, fmt.Errorf("Error processing %s: %s", n, err))
}
}
return errs
}
package common
import (
"testing"
)
func TestExportOptsPrepare_BootWait(t *testing.T) {
var c *ExportOpts
var errs []error
// Good
c = new(ExportOpts)
c.ExportOpts = "ovf"
errs = c.Prepare(testConfigTemplate(t))
if len(errs) > 0 {
t.Fatalf("should not have error: %s", errs)
}
}
...@@ -18,6 +18,7 @@ import ( ...@@ -18,6 +18,7 @@ import (
type StepExport struct { type StepExport struct {
Format string Format string
OutputDir string OutputDir string
ExportOpts string
} }
func (s *StepExport) Run(state multistep.StateBag) multistep.StepAction { func (s *StepExport) Run(state multistep.StateBag) multistep.StepAction {
...@@ -50,6 +51,7 @@ func (s *StepExport) Run(state multistep.StateBag) multistep.StepAction { ...@@ -50,6 +51,7 @@ func (s *StepExport) Run(state multistep.StateBag) multistep.StepAction {
vmName, vmName,
"--output", "--output",
outputPath, outputPath,
s.ExportOpts,
} }
ui.Say("Exporting virtual machine...") ui.Say("Exporting virtual machine...")
......
...@@ -29,6 +29,7 @@ type Builder struct { ...@@ -29,6 +29,7 @@ type Builder struct {
type config struct { type config struct {
common.PackerConfig `mapstructure:",squash"` common.PackerConfig `mapstructure:",squash"`
vboxcommon.ExportConfig `mapstructure:",squash"` vboxcommon.ExportConfig `mapstructure:",squash"`
vboxcommon.ExportOpts `mapstructure:",squash"`
vboxcommon.FloppyConfig `mapstructure:",squash"` vboxcommon.FloppyConfig `mapstructure:",squash"`
vboxcommon.OutputConfig `mapstructure:",squash"` vboxcommon.OutputConfig `mapstructure:",squash"`
vboxcommon.RunConfig `mapstructure:",squash"` vboxcommon.RunConfig `mapstructure:",squash"`
...@@ -73,6 +74,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) { ...@@ -73,6 +74,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
// Accumulate any errors and warnings // Accumulate any errors and warnings
errs := common.CheckUnusedConfig(md) errs := common.CheckUnusedConfig(md)
errs = packer.MultiErrorAppend(errs, b.config.ExportConfig.Prepare(b.config.tpl)...) errs = packer.MultiErrorAppend(errs, b.config.ExportConfig.Prepare(b.config.tpl)...)
errs = packer.MultiErrorAppend(errs, b.config.ExportOpts.Prepare(b.config.tpl)...)
errs = packer.MultiErrorAppend(errs, b.config.FloppyConfig.Prepare(b.config.tpl)...) errs = packer.MultiErrorAppend(errs, b.config.FloppyConfig.Prepare(b.config.tpl)...)
errs = packer.MultiErrorAppend( errs = packer.MultiErrorAppend(
errs, b.config.OutputConfig.Prepare(b.config.tpl, &b.config.PackerConfig)...) errs, b.config.OutputConfig.Prepare(b.config.tpl, &b.config.PackerConfig)...)
...@@ -319,6 +321,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe ...@@ -319,6 +321,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
&vboxcommon.StepExport{ &vboxcommon.StepExport{
Format: b.config.Format, Format: b.config.Format,
OutputDir: b.config.OutputDir, OutputDir: b.config.OutputDir,
ExportOpts: b.config.ExportOpts.ExportOpts,
}, },
} }
......
...@@ -97,6 +97,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe ...@@ -97,6 +97,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
&vboxcommon.StepExport{ &vboxcommon.StepExport{
Format: b.config.Format, Format: b.config.Format,
OutputDir: b.config.OutputDir, OutputDir: b.config.OutputDir,
ExportOpts: b.config.ExportOpts.ExportOpts,
}, },
} }
......
...@@ -13,6 +13,7 @@ import ( ...@@ -13,6 +13,7 @@ import (
type Config struct { type Config struct {
common.PackerConfig `mapstructure:",squash"` common.PackerConfig `mapstructure:",squash"`
vboxcommon.ExportConfig `mapstructure:",squash"` vboxcommon.ExportConfig `mapstructure:",squash"`
vboxcommon.ExportOpts `mapstructure:",squash"`
vboxcommon.FloppyConfig `mapstructure:",squash"` vboxcommon.FloppyConfig `mapstructure:",squash"`
vboxcommon.OutputConfig `mapstructure:",squash"` vboxcommon.OutputConfig `mapstructure:",squash"`
vboxcommon.RunConfig `mapstructure:",squash"` vboxcommon.RunConfig `mapstructure:",squash"`
...@@ -49,6 +50,7 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) { ...@@ -49,6 +50,7 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
// Prepare the errors // Prepare the errors
errs := common.CheckUnusedConfig(md) errs := common.CheckUnusedConfig(md)
errs = packer.MultiErrorAppend(errs, c.ExportConfig.Prepare(c.tpl)...) errs = packer.MultiErrorAppend(errs, c.ExportConfig.Prepare(c.tpl)...)
errs = packer.MultiErrorAppend(errs, c.ExportOpts.Prepare(c.tpl)...)
errs = packer.MultiErrorAppend(errs, c.FloppyConfig.Prepare(c.tpl)...) errs = packer.MultiErrorAppend(errs, c.FloppyConfig.Prepare(c.tpl)...)
errs = packer.MultiErrorAppend(errs, c.OutputConfig.Prepare(c.tpl, &c.PackerConfig)...) errs = packer.MultiErrorAppend(errs, c.OutputConfig.Prepare(c.tpl, &c.PackerConfig)...)
errs = packer.MultiErrorAppend(errs, c.RunConfig.Prepare(c.tpl)...) errs = packer.MultiErrorAppend(errs, c.RunConfig.Prepare(c.tpl)...)
......
...@@ -211,6 +211,10 @@ Optional: ...@@ -211,6 +211,10 @@ Optional:
machine, without the file extension. By default this is "packer-BUILDNAME", machine, without the file extension. By default this is "packer-BUILDNAME",
where "BUILDNAME" is the name of the build. where "BUILDNAME" is the name of the build.
* `export_opts` (string) - Additional options to pass to the `VBoxManage export`.
This can be useful for passing product information to include in the resulting
appliance file.
## Boot Command ## Boot Command
The `boot_command` configuration is very important: it specifies the keys The `boot_command` configuration is very important: it specifies the keys
......
...@@ -151,6 +151,10 @@ Optional: ...@@ -151,6 +151,10 @@ Optional:
This can be useful for passing "keepallmacs" or "keepnatmacs" options for existing This can be useful for passing "keepallmacs" or "keepnatmacs" options for existing
ovf images. ovf images.
* `export_opts` (string) - Additional options to pass to the `VBoxManage export`.
This can be useful for passing product information to include in the resulting
appliance file.
## Guest Additions ## Guest Additions
Packer will automatically download the proper guest additions for the Packer will automatically download the proper guest additions for the
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment