builder/virtualbox-ovf: import_flags [GH-1383]
This commit is contained in:
parent
863e06a614
commit
9b2039121f
|
@ -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 {
|
||||||
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) {
|
||||||
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 {
|
||||||
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 {
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -68,9 +68,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
||||||
Tpl: b.config.tpl,
|
Tpl: b.config.tpl,
|
||||||
},
|
},
|
||||||
&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,
|
||||||
|
|
|
@ -24,13 +24,14 @@ type Config struct {
|
||||||
vboxcommon.VBoxManagePostConfig `mapstructure:",squash"`
|
vboxcommon.VBoxManagePostConfig `mapstructure:",squash"`
|
||||||
vboxcommon.VBoxVersionConfig `mapstructure:",squash"`
|
vboxcommon.VBoxVersionConfig `mapstructure:",squash"`
|
||||||
|
|
||||||
SourcePath string `mapstructure:"source_path"`
|
SourcePath string `mapstructure:"source_path"`
|
||||||
GuestAdditionsMode string `mapstructure:"guest_additions_mode"`
|
GuestAdditionsMode string `mapstructure:"guest_additions_mode"`
|
||||||
GuestAdditionsPath string `mapstructure:"guest_additions_path"`
|
GuestAdditionsPath string `mapstructure:"guest_additions_path"`
|
||||||
GuestAdditionsURL string `mapstructure:"guest_additions_url"`
|
GuestAdditionsURL string `mapstructure:"guest_additions_url"`
|
||||||
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) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,9 +9,9 @@ import (
|
||||||
|
|
||||||
// This step imports an OVF VM into VirtualBox.
|
// This step imports an OVF VM into VirtualBox.
|
||||||
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 {
|
||||||
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.
|
||||||
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.
|
||||||
|
|
Loading…
Reference in New Issue