mirror of
https://github.com/hashicorp/packer.git
synced 2026-02-27 03:51:20 -05:00
This commit adds a new option, `vmx_remove_ethernet_interfaces`, to both
of the VMWare builders. This is useful when building Vagrant boxes,
since Vagrant now produces output such as:
```
WARNING: The VMX file for this box contains a setting that is
automatically overwritten by Vagrant when started. Vagrant will stop
overwriting this setting in an upcoming release which may pre vent
proper networking setup. Below is the detected VMX setting:
ethernet0.pcislotnumber = "33"
If networking fails to properly configure, it may require this VMX
setting. It can be manually applied via the Vagrantfile:
Vagrant.configure(2) do |config|
config.vm.provider :vmware_fusion do |vmware|
vmware.vmx["ethernet0.pcislotnumber"] = "33"
end
end
```
This can be avoided entirely by removing the ethernet adapters from the
VMX file prior to packaging as a Vagrant box, in which case adapters are
created as expected according to the Vagrantfile specification.
154 lines
4 KiB
Go
154 lines
4 KiB
Go
package vmx
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"log"
|
|
"time"
|
|
|
|
vmwcommon "github.com/hashicorp/packer/builder/vmware/common"
|
|
"github.com/hashicorp/packer/common"
|
|
"github.com/hashicorp/packer/helper/communicator"
|
|
"github.com/hashicorp/packer/packer"
|
|
"github.com/mitchellh/multistep"
|
|
)
|
|
|
|
// Builder implements packer.Builder and builds the actual VMware
|
|
// images.
|
|
type Builder struct {
|
|
config *Config
|
|
runner multistep.Runner
|
|
}
|
|
|
|
// Prepare processes the build configuration parameters.
|
|
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
|
|
c, warnings, errs := NewConfig(raws...)
|
|
if errs != nil {
|
|
return warnings, errs
|
|
}
|
|
b.config = c
|
|
|
|
return warnings, nil
|
|
}
|
|
|
|
// Run executes a Packer build and returns a packer.Artifact representing
|
|
// a VirtualBox appliance.
|
|
func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) {
|
|
driver, err := vmwcommon.NewDriver(&b.config.DriverConfig, &b.config.SSHConfig)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("Failed creating VMware driver: %s", err)
|
|
}
|
|
|
|
// Setup the directory
|
|
dir := new(vmwcommon.LocalOutputDir)
|
|
dir.SetOutputDir(b.config.OutputDir)
|
|
|
|
// Set up the state.
|
|
state := new(multistep.BasicStateBag)
|
|
state.Put("config", b.config)
|
|
state.Put("debug", b.config.PackerDebug)
|
|
state.Put("dir", dir)
|
|
state.Put("driver", driver)
|
|
state.Put("hook", hook)
|
|
state.Put("ui", ui)
|
|
|
|
// Build the steps.
|
|
steps := []multistep.Step{
|
|
&vmwcommon.StepPrepareTools{
|
|
RemoteType: b.config.RemoteType,
|
|
ToolsUploadFlavor: b.config.ToolsUploadFlavor,
|
|
},
|
|
&vmwcommon.StepOutputDir{
|
|
Force: b.config.PackerForce,
|
|
},
|
|
&common.StepCreateFloppy{
|
|
Files: b.config.FloppyConfig.FloppyFiles,
|
|
Directories: b.config.FloppyConfig.FloppyDirectories,
|
|
},
|
|
&StepCloneVMX{
|
|
OutputDir: b.config.OutputDir,
|
|
Path: b.config.SourcePath,
|
|
VMName: b.config.VMName,
|
|
},
|
|
&vmwcommon.StepConfigureVMX{
|
|
CustomData: b.config.VMXData,
|
|
},
|
|
&vmwcommon.StepSuppressMessages{},
|
|
&common.StepHTTPServer{
|
|
HTTPDir: b.config.HTTPDir,
|
|
HTTPPortMin: b.config.HTTPPortMin,
|
|
HTTPPortMax: b.config.HTTPPortMax,
|
|
},
|
|
&vmwcommon.StepConfigureVNC{
|
|
VNCBindAddress: b.config.VNCBindAddress,
|
|
VNCPortMin: b.config.VNCPortMin,
|
|
VNCPortMax: b.config.VNCPortMax,
|
|
VNCDisablePassword: b.config.VNCDisablePassword,
|
|
},
|
|
&vmwcommon.StepRun{
|
|
BootWait: b.config.BootWait,
|
|
DurationBeforeStop: 5 * time.Second,
|
|
Headless: b.config.Headless,
|
|
},
|
|
&vmwcommon.StepTypeBootCommand{
|
|
BootCommand: b.config.BootCommand,
|
|
VMName: b.config.VMName,
|
|
Ctx: b.config.ctx,
|
|
},
|
|
&communicator.StepConnect{
|
|
Config: &b.config.SSHConfig.Comm,
|
|
Host: driver.CommHost,
|
|
SSHConfig: vmwcommon.SSHConfigFunc(&b.config.SSHConfig),
|
|
},
|
|
&vmwcommon.StepUploadTools{
|
|
RemoteType: b.config.RemoteType,
|
|
ToolsUploadFlavor: b.config.ToolsUploadFlavor,
|
|
ToolsUploadPath: b.config.ToolsUploadPath,
|
|
Ctx: b.config.ctx,
|
|
},
|
|
&common.StepProvision{},
|
|
&vmwcommon.StepShutdown{
|
|
Command: b.config.ShutdownCommand,
|
|
Timeout: b.config.ShutdownTimeout,
|
|
},
|
|
&vmwcommon.StepCleanFiles{},
|
|
&vmwcommon.StepCompactDisk{
|
|
Skip: b.config.SkipCompaction,
|
|
},
|
|
&vmwcommon.StepConfigureVMX{
|
|
CustomData: b.config.VMXDataPost,
|
|
SkipFloppy: true,
|
|
},
|
|
&vmwcommon.StepCleanVMX{
|
|
RemoveEthernetInterfaces: b.config.VMXConfig.VMXRemoveEthernet,
|
|
},
|
|
}
|
|
|
|
// Run the steps.
|
|
b.runner = common.NewRunnerWithPauseFn(steps, b.config.PackerConfig, ui, state)
|
|
b.runner.Run(state)
|
|
|
|
// Report any errors.
|
|
if rawErr, ok := state.GetOk("error"); ok {
|
|
return nil, rawErr.(error)
|
|
}
|
|
|
|
// If we were interrupted or cancelled, then just exit.
|
|
if _, ok := state.GetOk(multistep.StateCancelled); ok {
|
|
return nil, errors.New("Build was cancelled.")
|
|
}
|
|
|
|
if _, ok := state.GetOk(multistep.StateHalted); ok {
|
|
return nil, errors.New("Build was halted.")
|
|
}
|
|
|
|
return vmwcommon.NewLocalArtifact(b.config.OutputDir)
|
|
}
|
|
|
|
// Cancel.
|
|
func (b *Builder) Cancel() {
|
|
if b.runner != nil {
|
|
log.Println("Cancelling the step runner...")
|
|
b.runner.Cancel()
|
|
}
|
|
}
|