mirror of
https://github.com/hashicorp/packer.git
synced 2026-10-05 06:03:17 -04: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.
85 lines
1.9 KiB
Go
85 lines
1.9 KiB
Go
package common
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"regexp"
|
|
"strings"
|
|
|
|
"github.com/hashicorp/packer/packer"
|
|
"github.com/mitchellh/multistep"
|
|
)
|
|
|
|
// This step cleans up the VMX by removing or changing this prior to
|
|
// being ready for use.
|
|
//
|
|
// Uses:
|
|
// ui packer.Ui
|
|
// vmx_path string
|
|
//
|
|
// Produces:
|
|
// <nothing>
|
|
type StepCleanVMX struct {
|
|
RemoveEthernetInterfaces bool
|
|
}
|
|
|
|
func (s StepCleanVMX) Run(state multistep.StateBag) multistep.StepAction {
|
|
ui := state.Get("ui").(packer.Ui)
|
|
vmxPath := state.Get("vmx_path").(string)
|
|
|
|
ui.Say("Cleaning VMX prior to finishing up...")
|
|
|
|
vmxData, err := ReadVMX(vmxPath)
|
|
if err != nil {
|
|
state.Put("error", fmt.Errorf("Error reading VMX: %s", err))
|
|
return multistep.ActionHalt
|
|
}
|
|
|
|
// Delete the floppy0 entries so the floppy is no longer mounted
|
|
ui.Message("Unmounting floppy from VMX...")
|
|
for k := range vmxData {
|
|
if strings.HasPrefix(k, "floppy0.") {
|
|
log.Printf("Deleting key: %s", k)
|
|
delete(vmxData, k)
|
|
}
|
|
}
|
|
vmxData["floppy0.present"] = "FALSE"
|
|
|
|
devRe := regexp.MustCompile(`^ide\d:\d\.`)
|
|
for k, v := range vmxData {
|
|
ide := devRe.FindString(k)
|
|
if ide == "" || v != "cdrom-image" {
|
|
continue
|
|
}
|
|
|
|
ui.Message("Detaching ISO from CD-ROM device...")
|
|
|
|
vmxData[ide+"devicetype"] = "cdrom-raw"
|
|
vmxData[ide+"filename"] = "auto detect"
|
|
vmxData[ide+"clientdevice"] = "TRUE"
|
|
}
|
|
|
|
ui.Message("Disabling VNC server...")
|
|
vmxData["remotedisplay.vnc.enabled"] = "FALSE"
|
|
|
|
if s.RemoveEthernetInterfaces {
|
|
ui.Message("Removing Ethernet Interfaces...")
|
|
for k := range vmxData {
|
|
if strings.HasPrefix(k, "ethernet") {
|
|
log.Printf("Deleting key: %s", k)
|
|
delete(vmxData, k)
|
|
}
|
|
}
|
|
}
|
|
|
|
// Rewrite the VMX
|
|
if err := WriteVMX(vmxPath, vmxData); err != nil {
|
|
state.Put("error", fmt.Errorf("Error writing VMX: %s", err))
|
|
return multistep.ActionHalt
|
|
}
|
|
|
|
return multistep.ActionContinue
|
|
}
|
|
|
|
func (StepCleanVMX) Cleanup(multistep.StateBag) {}
|