Commit 9b203912 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

builder/virtualbox-ovf: import_flags [GH-1383]

parent 863e06a6
......@@ -15,6 +15,9 @@ FEATURES:
Packer will look in the PWD and the directory with `packer` for
binaries named `packer-TYPE-NAME`.
* builder/docker: Images can now be committed instead of exported. [GH-1198]
* builder/virtualbox-ovf: New `import_flags` setting can be used to add
new command line flags to `VBoxManage import` to allow things such
as EULAs to be accepted. [GH-1383]
* builder/vmware: VMware Player 6 is now supported. [GH-1168]
IMPROVEMENTS:
......
......@@ -23,7 +23,7 @@ type Driver interface {
Delete(string) error
// Import a VM
Import(string, string, string) error
Import(string, string, []string) error
// The complete path to the Guest Additions ISO
Iso() (string, error)
......
......@@ -69,13 +69,13 @@ func (d *VBox42Driver) Iso() (string, error) {
return "", fmt.Errorf("Cannot find \"Default Guest Additions ISO\" in vboxmanage output")
}
func (d *VBox42Driver) Import(name, path, opts string) error {
func (d *VBox42Driver) Import(name string, path string, flags []string) error {
args := []string{
"import", path,
"--vsys", "0",
"--vmname", name,
"--options", opts,
}
args = append(args, flags...)
return d.VBoxManage(args...)
}
......
......@@ -16,7 +16,7 @@ type DriverMock struct {
ImportCalled bool
ImportName string
ImportPath string
ImportOpts string
ImportFlags []string
ImportErr error
IsoCalled bool
......@@ -55,11 +55,11 @@ func (d *DriverMock) Delete(name string) error {
return d.DeleteErr
}
func (d *DriverMock) Import(name, path, opts string) error {
func (d *DriverMock) Import(name string, path string, flags []string) error {
d.ImportCalled = true
d.ImportName = name
d.ImportPath = path
d.ImportOpts = opts
d.ImportFlags = flags
return d.ImportErr
}
......
......@@ -70,7 +70,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
&StepImport{
Name: b.config.VMName,
SourcePath: b.config.SourcePath,
ImportOpts: b.config.ImportOpts,
ImportFlags: b.config.ImportFlags,
},
&vboxcommon.StepAttachGuestAdditions{
GuestAdditionsMode: b.config.GuestAdditionsMode,
......
......@@ -31,6 +31,7 @@ type Config struct {
GuestAdditionsSHA256 string `mapstructure:"guest_additions_sha256"`
VMName string `mapstructure:"vm_name"`
ImportOpts string `mapstructure:"import_opts"`
ImportFlags []string `mapstructure:"import_flags"`
tpl *packer.ConfigTemplate
}
......@@ -90,6 +91,21 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
}
}
sliceTemplates := map[string][]string{
"import_flags": c.ImportFlags,
}
for n, slice := range sliceTemplates {
for i, elem := range slice {
var err error
slice[i], err = c.tpl.Process(elem, nil)
if err != nil {
errs = packer.MultiErrorAppend(
errs, fmt.Errorf("Error processing %s[%d]: %s", n, i, err))
}
}
}
if c.SourcePath == "" {
errs = packer.MultiErrorAppend(errs, fmt.Errorf("source_path is required"))
} else {
......@@ -147,5 +163,10 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
return nil, warnings, errs
}
// TODO: Write a packer fix and just remove import_opts
if c.ImportOpts != "" {
c.ImportFlags = append(c.ImportFlags, "--options", c.ImportOpts)
}
return c, warnings, nil
}
......@@ -11,7 +11,7 @@ import (
type StepImport struct {
Name string
SourcePath string
ImportOpts string
ImportFlags []string
vmName string
}
......@@ -21,7 +21,7 @@ func (s *StepImport) Run(state multistep.StateBag) multistep.StepAction {
ui := state.Get("ui").(packer.Ui)
ui.Say(fmt.Sprintf("Importing VM: %s", s.SourcePath))
if err := driver.Import(s.Name, s.SourcePath, s.ImportOpts); err != nil {
if err := driver.Import(s.Name, s.SourcePath, s.ImportFlags); err != nil {
err := fmt.Errorf("Error importing VM: %s", err)
state.Put("error", err)
ui.Error(err.Error())
......
......@@ -96,6 +96,10 @@ each category, the available options are alphabetized and described.
machine being built. When this value is set to true, the machine will
start without a console.
* `import_flags` (array of strings) - Additional flags to pass to
`VBoxManage import`. This can be used to add additional command-line flags
such as `--eula-accept` to accept a EULA in the OVF.
* `import_opts` (string) - Additional options to pass to the `VBoxManage import`.
This can be useful for passing "keepallmacs" or "keepnatmacs" options for existing
ovf images.
......
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