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

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

parent 863e06a6
...@@ -15,6 +15,9 @@ FEATURES: ...@@ -15,6 +15,9 @@ FEATURES:
Packer will look in the PWD and the directory with `packer` for Packer will look in the PWD and the directory with `packer` for
binaries named `packer-TYPE-NAME`. binaries named `packer-TYPE-NAME`.
* builder/docker: Images can now be committed instead of exported. [GH-1198] * 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] * builder/vmware: VMware Player 6 is now supported. [GH-1168]
IMPROVEMENTS: IMPROVEMENTS:
......
...@@ -23,7 +23,7 @@ type Driver interface { ...@@ -23,7 +23,7 @@ type Driver interface {
Delete(string) error Delete(string) error
// Import a VM // Import a VM
Import(string, string, string) error Import(string, string, []string) error
// The complete path to the Guest Additions ISO // The complete path to the Guest Additions ISO
Iso() (string, error) Iso() (string, error)
......
...@@ -69,13 +69,13 @@ func (d *VBox42Driver) 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") 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{ args := []string{
"import", path, "import", path,
"--vsys", "0", "--vsys", "0",
"--vmname", name, "--vmname", name,
"--options", opts,
} }
args = append(args, flags...)
return d.VBoxManage(args...) return d.VBoxManage(args...)
} }
......
...@@ -16,7 +16,7 @@ type DriverMock struct { ...@@ -16,7 +16,7 @@ type DriverMock struct {
ImportCalled bool ImportCalled bool
ImportName string ImportName string
ImportPath string ImportPath string
ImportOpts string ImportFlags []string
ImportErr error ImportErr error
IsoCalled bool IsoCalled bool
...@@ -55,11 +55,11 @@ func (d *DriverMock) Delete(name string) error { ...@@ -55,11 +55,11 @@ func (d *DriverMock) Delete(name string) error {
return d.DeleteErr 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.ImportCalled = true
d.ImportName = name d.ImportName = name
d.ImportPath = path d.ImportPath = path
d.ImportOpts = opts d.ImportFlags = flags
return d.ImportErr return d.ImportErr
} }
......
...@@ -70,7 +70,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe ...@@ -70,7 +70,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
&StepImport{ &StepImport{
Name: b.config.VMName, Name: b.config.VMName,
SourcePath: b.config.SourcePath, SourcePath: b.config.SourcePath,
ImportOpts: b.config.ImportOpts, ImportFlags: b.config.ImportFlags,
}, },
&vboxcommon.StepAttachGuestAdditions{ &vboxcommon.StepAttachGuestAdditions{
GuestAdditionsMode: b.config.GuestAdditionsMode, GuestAdditionsMode: b.config.GuestAdditionsMode,
......
...@@ -31,6 +31,7 @@ type Config struct { ...@@ -31,6 +31,7 @@ type Config struct {
GuestAdditionsSHA256 string `mapstructure:"guest_additions_sha256"` GuestAdditionsSHA256 string `mapstructure:"guest_additions_sha256"`
VMName string `mapstructure:"vm_name"` VMName string `mapstructure:"vm_name"`
ImportOpts string `mapstructure:"import_opts"` ImportOpts string `mapstructure:"import_opts"`
ImportFlags []string `mapstructure:"import_flags"`
tpl *packer.ConfigTemplate tpl *packer.ConfigTemplate
} }
...@@ -90,6 +91,21 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) { ...@@ -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 == "" { if c.SourcePath == "" {
errs = packer.MultiErrorAppend(errs, fmt.Errorf("source_path is required")) errs = packer.MultiErrorAppend(errs, fmt.Errorf("source_path is required"))
} else { } else {
...@@ -147,5 +163,10 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) { ...@@ -147,5 +163,10 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
return nil, warnings, errs 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 return c, warnings, nil
} }
...@@ -11,7 +11,7 @@ import ( ...@@ -11,7 +11,7 @@ import (
type StepImport struct { type StepImport struct {
Name string Name string
SourcePath string SourcePath string
ImportOpts string ImportFlags []string
vmName string vmName string
} }
...@@ -21,7 +21,7 @@ func (s *StepImport) Run(state multistep.StateBag) multistep.StepAction { ...@@ -21,7 +21,7 @@ func (s *StepImport) Run(state multistep.StateBag) multistep.StepAction {
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)
ui.Say(fmt.Sprintf("Importing VM: %s", s.SourcePath)) 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) err := fmt.Errorf("Error importing VM: %s", err)
state.Put("error", err) state.Put("error", err)
ui.Error(err.Error()) ui.Error(err.Error())
......
...@@ -96,6 +96,10 @@ each category, the available options are alphabetized and described. ...@@ -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 machine being built. When this value is set to true, the machine will
start without a console. 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`. * `import_opts` (string) - Additional options to pass to the `VBoxManage import`.
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.
......
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