Add import_opts to the virtualbox-ovf builder. My use case is that I
have existing virtualbox virtual machines where I need to keep the mac addresses so that the network interfaces come up when packer boots them. Otherwise I just get SSH timeout and I'm unable to configure the machines.
This commit is contained in:
parent
b4a57bd373
commit
ac2c4203a2
|
@ -23,7 +23,7 @@ type Driver interface {
|
|||
Delete(string) error
|
||||
|
||||
// Import a VM
|
||||
Import(string, string) error
|
||||
Import(string, string, string) error
|
||||
|
||||
// Checks if the VM with the given name is running.
|
||||
IsRunning(string) (bool, error)
|
||||
|
|
|
@ -40,11 +40,12 @@ func (d *VBox42Driver) Delete(name string) error {
|
|||
return d.VBoxManage("unregistervm", name, "--delete")
|
||||
}
|
||||
|
||||
func (d *VBox42Driver) Import(name, path string) error {
|
||||
func (d *VBox42Driver) Import(name, path, opts string) error {
|
||||
args := []string{
|
||||
"import", path,
|
||||
"--vsys", "0",
|
||||
"--vmname", name,
|
||||
"--options", opts,
|
||||
}
|
||||
|
||||
return d.VBoxManage(args...)
|
||||
|
|
|
@ -16,6 +16,7 @@ type DriverMock struct {
|
|||
ImportCalled bool
|
||||
ImportName string
|
||||
ImportPath string
|
||||
ImportOpts string
|
||||
ImportErr error
|
||||
|
||||
IsRunningName string
|
||||
|
@ -51,10 +52,11 @@ func (d *DriverMock) Delete(name string) error {
|
|||
return d.DeleteErr
|
||||
}
|
||||
|
||||
func (d *DriverMock) Import(name, path string) error {
|
||||
func (d *DriverMock) Import(name, path, opts string) error {
|
||||
d.ImportCalled = true
|
||||
d.ImportName = name
|
||||
d.ImportPath = path
|
||||
d.ImportOpts = opts
|
||||
return d.ImportErr
|
||||
}
|
||||
|
||||
|
|
|
@ -58,6 +58,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,
|
||||
},
|
||||
/*
|
||||
new(stepAttachGuestAdditions),
|
||||
|
|
|
@ -23,6 +23,7 @@ type Config struct {
|
|||
|
||||
SourcePath string `mapstructure:"source_path"`
|
||||
VMName string `mapstructure:"vm_name"`
|
||||
ImportOpts string `mapstructure:"import_opts"`
|
||||
|
||||
tpl *packer.ConfigTemplate
|
||||
}
|
||||
|
@ -59,6 +60,7 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
|
|||
templates := map[string]*string{
|
||||
"source_path": &c.SourcePath,
|
||||
"vm_name": &c.VMName,
|
||||
"import_opts": &c.ImportOpts,
|
||||
}
|
||||
|
||||
for n, ptr := range templates {
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
type StepImport struct {
|
||||
Name string
|
||||
SourcePath string
|
||||
ImportOpts string
|
||||
|
||||
vmName string
|
||||
}
|
||||
|
@ -20,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); err != nil {
|
||||
if err := driver.Import(s.Name, s.SourcePath, s.ImportOpts); err != nil {
|
||||
err := fmt.Errorf("Error importing VM: %s", err)
|
||||
state.Put("error", err)
|
||||
ui.Error(err.Error())
|
||||
|
|
|
@ -147,6 +147,10 @@ Optional:
|
|||
exported. By default this is "packer-BUILDNAME", where "BUILDNAME" is
|
||||
the name of the build.
|
||||
|
||||
* `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.
|
||||
|
||||
## Guest Additions
|
||||
|
||||
Packer will automatically download the proper guest additions for the
|
||||
|
|
Loading…
Reference in New Issue