mirror of
https://github.com/hashicorp/packer.git
synced 2026-10-25 15:38:22 -04:00
builder/vmware/{iso,vmx}:
Added the specific configuration options that get parsed.
Normalize paths when pulling them from the json template so that they'll work on Windows too.
Added some improved error checking when parsing these options.
Stash the vm's network connection type so that other steps can figure out addressing information
Modified the esx5 driver to support the new addressing logic.
Modified the template in step_create_vmx to include the new options.
builder/vmware/common:
Implemented a parser for vmware's configuration files to the vmware builder.
Modified the driver's interface to include support for resolving both guest/host hw and ip addresses
Implemented a base structure with some methods that implement these features.
Rewrote all ip and mac address dependent code to utilize these new methods.
Removed host_ip and guest_ip due to their logic being moved directly into a
base-structure used by each driver. The code was explicitly checking runtime.GOOS
instead of portably using net.Interfaces() anyways.
Updated driver_mock to support the new addressing methods
74 lines
1.8 KiB
Go
74 lines
1.8 KiB
Go
package vmx
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"log"
|
|
"path/filepath"
|
|
|
|
vmwcommon "github.com/hashicorp/packer/builder/vmware/common"
|
|
"github.com/hashicorp/packer/helper/multistep"
|
|
"github.com/hashicorp/packer/packer"
|
|
)
|
|
|
|
// StepCloneVMX takes a VMX file and clones the VM into the output directory.
|
|
type StepCloneVMX struct {
|
|
OutputDir string
|
|
Path string
|
|
VMName string
|
|
}
|
|
|
|
func (s *StepCloneVMX) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
|
driver := state.Get("driver").(vmwcommon.Driver)
|
|
ui := state.Get("ui").(packer.Ui)
|
|
|
|
vmxPath := filepath.Join(s.OutputDir, s.VMName+".vmx")
|
|
|
|
ui.Say("Cloning source VM...")
|
|
log.Printf("Cloning from: %s", s.Path)
|
|
log.Printf("Cloning to: %s", vmxPath)
|
|
if err := driver.Clone(vmxPath, s.Path); err != nil {
|
|
state.Put("error", err)
|
|
return multistep.ActionHalt
|
|
}
|
|
|
|
vmxData, err := vmwcommon.ReadVMX(vmxPath)
|
|
if err != nil {
|
|
state.Put("error", err)
|
|
return multistep.ActionHalt
|
|
}
|
|
|
|
var diskName string
|
|
if _, ok := vmxData["scsi0:0.filename"]; ok {
|
|
diskName = vmxData["scsi0:0.filename"]
|
|
}
|
|
if _, ok := vmxData["sata0:0.filename"]; ok {
|
|
diskName = vmxData["sata0:0.filename"]
|
|
}
|
|
if _, ok := vmxData["ide0:0.filename"]; ok {
|
|
diskName = vmxData["ide0:0.filename"]
|
|
}
|
|
if diskName == "" {
|
|
err := fmt.Errorf("Root disk filename could not be found!")
|
|
state.Put("error", err)
|
|
return multistep.ActionHalt
|
|
}
|
|
|
|
var networkType string
|
|
if _, ok := vmxData["ethernet0.connectionType"]; ok {
|
|
networkType = vmxData["ethernet0.connectionType"]
|
|
}
|
|
if networkType == "" {
|
|
networkType = "nat"
|
|
log.Printf("Defaulting to network type : nat")
|
|
}
|
|
|
|
state.Put("vmnetwork", networkType)
|
|
state.Put("full_disk_path", filepath.Join(s.OutputDir, diskName))
|
|
state.Put("vmx_path", vmxPath)
|
|
return multistep.ActionContinue
|
|
}
|
|
|
|
func (s *StepCloneVMX) Cleanup(state multistep.StateBag) {
|
|
}
|