2013-12-24 00:58:41 -05:00
|
|
|
package iso
|
2013-06-04 19:52:59 -04:00
|
|
|
|
|
|
|
import (
|
2018-01-22 18:32:33 -05:00
|
|
|
"context"
|
2013-06-04 19:52:59 -04:00
|
|
|
"fmt"
|
2013-08-27 20:23:22 -04:00
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
2013-06-04 19:52:59 -04:00
|
|
|
"path/filepath"
|
2018-11-17 02:23:28 -05:00
|
|
|
"strconv"
|
2015-11-11 07:39:06 -05:00
|
|
|
"strings"
|
2015-05-27 17:16:28 -04:00
|
|
|
|
2017-04-04 16:39:01 -04:00
|
|
|
vmwcommon "github.com/hashicorp/packer/builder/vmware/common"
|
2018-01-19 19:18:44 -05:00
|
|
|
"github.com/hashicorp/packer/helper/multistep"
|
2017-04-04 16:39:01 -04:00
|
|
|
"github.com/hashicorp/packer/packer"
|
2018-12-12 09:45:00 -05:00
|
|
|
"github.com/hashicorp/packer/packer/tmp"
|
2017-04-04 16:39:01 -04:00
|
|
|
"github.com/hashicorp/packer/template/interpolate"
|
2013-06-04 19:52:59 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
type vmxTemplateData struct {
|
2017-12-25 15:08:08 -05:00
|
|
|
Name string
|
|
|
|
GuestOS string
|
|
|
|
ISOPath string
|
|
|
|
Version string
|
|
|
|
|
2018-11-17 02:23:28 -05:00
|
|
|
CpuCount string
|
|
|
|
MemorySize string
|
|
|
|
|
2017-12-25 15:08:08 -05:00
|
|
|
SCSI_Present string
|
|
|
|
SCSI_diskAdapterType string
|
|
|
|
SATA_Present string
|
|
|
|
NVME_Present string
|
|
|
|
|
2018-11-09 17:00:07 -05:00
|
|
|
DiskName string
|
|
|
|
DiskType string
|
|
|
|
CDROMType string
|
|
|
|
CDROMType_PrimarySecondary string
|
2015-11-11 07:39:06 -05:00
|
|
|
|
2018-01-16 14:17:37 -05:00
|
|
|
Network_Type string
|
|
|
|
Network_Device string
|
|
|
|
Network_Adapter string
|
2016-10-05 22:51:42 -04:00
|
|
|
|
2015-11-11 07:39:06 -05:00
|
|
|
Sound_Present string
|
2017-02-27 16:34:53 -05:00
|
|
|
Usb_Present string
|
2015-11-11 07:39:06 -05:00
|
|
|
|
2017-02-27 16:34:53 -05:00
|
|
|
Serial_Present string
|
|
|
|
Serial_Type string
|
2015-11-11 07:39:06 -05:00
|
|
|
Serial_Endpoint string
|
2017-02-27 16:34:53 -05:00
|
|
|
Serial_Host string
|
|
|
|
Serial_Yield string
|
2015-11-11 07:39:06 -05:00
|
|
|
Serial_Filename string
|
2017-02-27 16:34:53 -05:00
|
|
|
Serial_Auto string
|
2015-11-11 07:39:06 -05:00
|
|
|
|
2017-02-27 16:34:53 -05:00
|
|
|
Parallel_Present string
|
2015-11-11 07:39:06 -05:00
|
|
|
Parallel_Bidirectional string
|
2017-02-27 16:34:53 -05:00
|
|
|
Parallel_Filename string
|
|
|
|
Parallel_Auto string
|
2013-06-04 19:52:59 -04:00
|
|
|
}
|
|
|
|
|
2014-03-04 13:23:07 -05:00
|
|
|
type additionalDiskTemplateData struct {
|
2014-03-04 15:00:24 -05:00
|
|
|
DiskNumber int
|
|
|
|
DiskName string
|
2014-03-04 13:23:07 -05:00
|
|
|
}
|
|
|
|
|
2013-06-05 17:47:19 -04:00
|
|
|
// This step creates the VMX file for the VM.
|
|
|
|
//
|
|
|
|
// Uses:
|
|
|
|
// config *config
|
2013-06-10 00:50:15 -04:00
|
|
|
// iso_path string
|
2013-06-05 17:47:19 -04:00
|
|
|
// ui packer.Ui
|
|
|
|
//
|
|
|
|
// Produces:
|
2013-06-05 17:49:04 -04:00
|
|
|
// vmx_path string - The path to the VMX file.
|
2013-11-08 00:02:12 -05:00
|
|
|
type stepCreateVMX struct {
|
|
|
|
tempDir string
|
|
|
|
}
|
2013-06-04 19:52:59 -04:00
|
|
|
|
2015-11-11 07:39:06 -05:00
|
|
|
/* regular steps */
|
2019-03-29 11:50:02 -04:00
|
|
|
func (s *stepCreateVMX) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
2015-05-27 17:16:28 -04:00
|
|
|
config := state.Get("config").(*Config)
|
2013-08-31 15:50:25 -04:00
|
|
|
isoPath := state.Get("iso_path").(string)
|
|
|
|
ui := state.Get("ui").(packer.Ui)
|
2013-06-04 19:52:59 -04:00
|
|
|
|
2017-12-25 15:08:08 -05:00
|
|
|
// Convert the iso_path into a path relative to the .vmx file if possible
|
|
|
|
if relativeIsoPath, err := filepath.Rel(config.VMXTemplatePath, filepath.FromSlash(isoPath)); err == nil {
|
|
|
|
isoPath = relativeIsoPath
|
|
|
|
}
|
|
|
|
|
2013-06-07 19:20:58 -04:00
|
|
|
ui.Say("Building and writing VMX file")
|
2013-06-04 19:52:59 -04:00
|
|
|
|
2013-08-27 20:23:22 -04:00
|
|
|
vmxTemplate := DefaultVMXTemplate
|
|
|
|
if config.VMXTemplatePath != "" {
|
|
|
|
f, err := os.Open(config.VMXTemplatePath)
|
|
|
|
if err != nil {
|
|
|
|
err := fmt.Errorf("Error reading VMX template: %s", err)
|
2013-08-31 15:50:25 -04:00
|
|
|
state.Put("error", err)
|
2013-08-27 20:23:22 -04:00
|
|
|
ui.Error(err.Error())
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
defer f.Close()
|
2013-06-07 19:20:58 -04:00
|
|
|
|
2013-08-27 20:23:22 -04:00
|
|
|
rawBytes, err := ioutil.ReadAll(f)
|
|
|
|
if err != nil {
|
|
|
|
err := fmt.Errorf("Error reading VMX template: %s", err)
|
2013-08-31 15:50:25 -04:00
|
|
|
state.Put("error", err)
|
2013-08-27 20:23:22 -04:00
|
|
|
ui.Error(err.Error())
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
|
|
|
vmxTemplate = string(rawBytes)
|
|
|
|
}
|
2014-03-04 15:00:24 -05:00
|
|
|
|
2019-03-29 11:50:02 -04:00
|
|
|
ictx := config.ctx
|
2015-06-04 14:44:07 -04:00
|
|
|
|
2014-03-04 13:23:07 -05:00
|
|
|
if len(config.AdditionalDiskSize) > 0 {
|
2016-11-01 17:08:04 -04:00
|
|
|
for i := range config.AdditionalDiskSize {
|
2019-03-29 11:50:02 -04:00
|
|
|
ictx.Data = &additionalDiskTemplateData{
|
2014-03-04 15:00:24 -05:00
|
|
|
DiskNumber: i + 1,
|
|
|
|
DiskName: config.DiskName,
|
2014-03-04 13:23:07 -05:00
|
|
|
}
|
2014-03-04 15:00:24 -05:00
|
|
|
|
2015-06-15 15:40:34 -04:00
|
|
|
diskTemplate := DefaultAdditionalDiskTemplate
|
|
|
|
if config.VMXDiskTemplatePath != "" {
|
|
|
|
f, err := os.Open(config.VMXDiskTemplatePath)
|
|
|
|
if err != nil {
|
|
|
|
err := fmt.Errorf("Error reading VMX disk template: %s", err)
|
|
|
|
state.Put("error", err)
|
|
|
|
ui.Error(err.Error())
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
defer f.Close()
|
|
|
|
|
|
|
|
rawBytes, err := ioutil.ReadAll(f)
|
|
|
|
if err != nil {
|
|
|
|
err := fmt.Errorf("Error reading VMX disk template: %s", err)
|
|
|
|
state.Put("error", err)
|
|
|
|
ui.Error(err.Error())
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
|
|
|
diskTemplate = string(rawBytes)
|
|
|
|
}
|
|
|
|
|
2019-03-29 11:50:02 -04:00
|
|
|
diskContents, err := interpolate.Render(diskTemplate, &ictx)
|
2014-03-04 13:23:07 -05:00
|
|
|
if err != nil {
|
|
|
|
err := fmt.Errorf("Error preparing VMX template for additional disk: %s", err)
|
|
|
|
state.Put("error", err)
|
|
|
|
ui.Error(err.Error())
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
2014-03-04 15:00:24 -05:00
|
|
|
|
2015-06-15 15:40:34 -04:00
|
|
|
vmxTemplate += diskContents
|
2014-03-04 13:23:07 -05:00
|
|
|
}
|
|
|
|
}
|
2013-08-27 20:23:22 -04:00
|
|
|
|
2015-11-11 07:39:06 -05:00
|
|
|
templateData := vmxTemplateData{
|
2015-06-04 14:44:07 -04:00
|
|
|
Name: config.VMName,
|
|
|
|
GuestOS: config.GuestOSType,
|
|
|
|
DiskName: config.DiskName,
|
|
|
|
Version: config.Version,
|
|
|
|
ISOPath: isoPath,
|
2015-11-11 07:39:06 -05:00
|
|
|
|
2017-12-25 15:08:08 -05:00
|
|
|
SCSI_Present: "FALSE",
|
|
|
|
SCSI_diskAdapterType: "lsilogic",
|
|
|
|
SATA_Present: "FALSE",
|
|
|
|
NVME_Present: "FALSE",
|
|
|
|
|
2018-11-09 17:00:07 -05:00
|
|
|
DiskType: "scsi",
|
|
|
|
CDROMType: "ide",
|
|
|
|
CDROMType_PrimarySecondary: "0",
|
2017-12-25 15:08:08 -05:00
|
|
|
|
2018-01-16 14:17:37 -05:00
|
|
|
Network_Adapter: "e1000",
|
|
|
|
|
2018-11-17 02:23:28 -05:00
|
|
|
Sound_Present: map[bool]string{true: "TRUE", false: "FALSE"}[bool(config.HWConfig.Sound)],
|
|
|
|
Usb_Present: map[bool]string{true: "TRUE", false: "FALSE"}[bool(config.HWConfig.USB)],
|
2015-11-11 07:39:06 -05:00
|
|
|
|
2017-02-27 16:34:53 -05:00
|
|
|
Serial_Present: "FALSE",
|
|
|
|
Parallel_Present: "FALSE",
|
2015-11-11 07:39:06 -05:00
|
|
|
}
|
|
|
|
|
2017-12-25 15:08:08 -05:00
|
|
|
/// Use the disk adapter type that the user specified to tweak the .vmx
|
|
|
|
// Also sync the cdrom adapter type according to what's common for that disk type.
|
2018-04-26 15:01:58 -04:00
|
|
|
// XXX: If the cdrom type is modified, make sure to update common/step_clean_vmx.go
|
|
|
|
// so that it will regex the correct cdrom device for removal.
|
2017-12-25 15:08:08 -05:00
|
|
|
diskAdapterType := strings.ToLower(config.DiskAdapterType)
|
|
|
|
switch diskAdapterType {
|
|
|
|
case "ide":
|
|
|
|
templateData.DiskType = "ide"
|
|
|
|
templateData.CDROMType = "ide"
|
2018-11-09 17:00:07 -05:00
|
|
|
templateData.CDROMType_PrimarySecondary = "1"
|
2017-12-25 15:08:08 -05:00
|
|
|
case "sata":
|
|
|
|
templateData.SATA_Present = "TRUE"
|
|
|
|
templateData.DiskType = "sata"
|
|
|
|
templateData.CDROMType = "sata"
|
2018-11-09 17:00:07 -05:00
|
|
|
templateData.CDROMType_PrimarySecondary = "1"
|
2017-12-25 15:08:08 -05:00
|
|
|
case "nvme":
|
|
|
|
templateData.NVME_Present = "TRUE"
|
|
|
|
templateData.DiskType = "nvme"
|
|
|
|
templateData.SATA_Present = "TRUE"
|
|
|
|
templateData.CDROMType = "sata"
|
2018-11-09 17:00:07 -05:00
|
|
|
templateData.CDROMType_PrimarySecondary = "0"
|
2017-12-25 15:08:08 -05:00
|
|
|
case "scsi":
|
|
|
|
diskAdapterType = "lsilogic"
|
|
|
|
fallthrough
|
|
|
|
default:
|
|
|
|
templateData.SCSI_Present = "TRUE"
|
|
|
|
templateData.SCSI_diskAdapterType = diskAdapterType
|
|
|
|
templateData.DiskType = "scsi"
|
|
|
|
templateData.CDROMType = "ide"
|
2018-11-09 17:00:07 -05:00
|
|
|
templateData.CDROMType_PrimarySecondary = "0"
|
2017-12-25 15:08:08 -05:00
|
|
|
}
|
|
|
|
|
2018-01-16 14:17:37 -05:00
|
|
|
/// Handle the cdrom adapter type. If the disk adapter type and the
|
|
|
|
// cdrom adapter type are the same, then ensure that the cdrom is the
|
2018-11-09 18:46:52 -05:00
|
|
|
// secondary device on whatever bus the disk adapter is on.
|
2018-01-16 14:17:37 -05:00
|
|
|
cdromAdapterType := strings.ToLower(config.CdromAdapterType)
|
2018-01-16 14:27:21 -05:00
|
|
|
if cdromAdapterType == "" {
|
|
|
|
cdromAdapterType = templateData.CDROMType
|
|
|
|
} else if cdromAdapterType == diskAdapterType {
|
2018-11-09 17:00:07 -05:00
|
|
|
templateData.CDROMType_PrimarySecondary = "1"
|
2018-01-16 14:17:37 -05:00
|
|
|
} else {
|
2018-11-09 17:00:07 -05:00
|
|
|
templateData.CDROMType_PrimarySecondary = "0"
|
2018-01-16 14:17:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
switch cdromAdapterType {
|
|
|
|
case "ide":
|
|
|
|
templateData.CDROMType = "ide"
|
|
|
|
case "sata":
|
|
|
|
templateData.SATA_Present = "TRUE"
|
|
|
|
templateData.CDROMType = "sata"
|
|
|
|
case "scsi":
|
|
|
|
templateData.SCSI_Present = "TRUE"
|
|
|
|
templateData.CDROMType = "scsi"
|
|
|
|
default:
|
2018-03-13 22:17:22 -04:00
|
|
|
err := fmt.Errorf("Error processing VMX template: %s", cdromAdapterType)
|
2018-01-16 14:17:37 -05:00
|
|
|
state.Put("error", err)
|
|
|
|
ui.Error(err.Error())
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
2018-12-03 18:46:02 -05:00
|
|
|
/// Now that we figured out the CDROM device to add, store it
|
|
|
|
/// to the list of temporary build devices in our statebag
|
|
|
|
tmpBuildDevices := state.Get("temporaryDevices").([]string)
|
|
|
|
tmpCdromDevice := fmt.Sprintf("%s0:%s", templateData.CDROMType, templateData.CDROMType_PrimarySecondary)
|
|
|
|
tmpBuildDevices = append(tmpBuildDevices, tmpCdromDevice)
|
|
|
|
state.Put("temporaryDevices", tmpBuildDevices)
|
|
|
|
|
2018-01-16 14:17:37 -05:00
|
|
|
/// Assign the network adapter type into the template if one was specified.
|
2018-11-17 02:23:28 -05:00
|
|
|
network_adapter := strings.ToLower(config.HWConfig.NetworkAdapterType)
|
2018-01-16 14:17:37 -05:00
|
|
|
if network_adapter != "" {
|
|
|
|
templateData.Network_Adapter = network_adapter
|
|
|
|
}
|
|
|
|
|
2016-10-05 22:51:42 -04:00
|
|
|
/// Check the network type that the user specified
|
2018-11-17 02:23:28 -05:00
|
|
|
network := config.HWConfig.Network
|
2017-04-13 18:39:55 -04:00
|
|
|
driver := state.Get("driver").(vmwcommon.Driver).GetVmwareDriver()
|
2016-10-05 22:51:42 -04:00
|
|
|
|
2018-02-20 20:42:45 -05:00
|
|
|
// check to see if the driver implements a network mapper for mapping
|
|
|
|
// the network-type to its device-name.
|
|
|
|
if driver.NetworkMapper != nil {
|
|
|
|
|
|
|
|
// read network map configuration into a NetworkNameMapper.
|
|
|
|
netmap, err := driver.NetworkMapper()
|
|
|
|
if err != nil {
|
|
|
|
state.Put("error", err)
|
|
|
|
ui.Error(err.Error())
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
|
|
|
// try and convert the specified network to a device.
|
2018-03-07 04:59:55 -05:00
|
|
|
devices, err := netmap.NameIntoDevices(network)
|
|
|
|
|
|
|
|
if err == nil && len(devices) > 0 {
|
|
|
|
// If multiple devices exist, for example for network "nat", VMware chooses
|
|
|
|
// the actual device. Only type "custom" allows the exact choice of a
|
|
|
|
// specific virtual network (see below). We allow VMware to choose the device
|
|
|
|
// and for device-specific operations like GuestIP, try to go over all
|
|
|
|
// devices that match a name (e.g. "nat").
|
|
|
|
// https://pubs.vmware.com/workstation-9/index.jsp?topic=%2Fcom.vmware.ws.using.doc%2FGUID-3B504F2F-7A0B-415F-AE01-62363A95D052.html
|
2018-02-20 20:42:45 -05:00
|
|
|
templateData.Network_Type = network
|
2018-03-07 04:59:55 -05:00
|
|
|
templateData.Network_Device = ""
|
2018-02-20 20:42:45 -05:00
|
|
|
} else {
|
2018-03-07 04:59:55 -05:00
|
|
|
// otherwise, we were unable to find the type, so assume it's a custom device
|
2018-02-20 20:42:45 -05:00
|
|
|
templateData.Network_Type = "custom"
|
|
|
|
templateData.Network_Device = network
|
|
|
|
}
|
2016-10-05 22:51:42 -04:00
|
|
|
|
2018-02-20 20:42:45 -05:00
|
|
|
// if NetworkMapper is nil, then we're using something like ESX, so fall
|
|
|
|
// back to the previous logic of using "nat" despite it not mattering to ESX.
|
2016-10-05 22:51:42 -04:00
|
|
|
} else {
|
2018-02-20 20:42:45 -05:00
|
|
|
templateData.Network_Type = "nat"
|
2016-10-05 22:51:42 -04:00
|
|
|
templateData.Network_Device = network
|
2018-02-20 20:42:45 -05:00
|
|
|
|
|
|
|
network = "nat"
|
2016-10-05 22:51:42 -04:00
|
|
|
}
|
2018-02-20 20:42:45 -05:00
|
|
|
|
2015-11-11 07:39:06 -05:00
|
|
|
// store the network so that we can later figure out what ip address to bind to
|
2016-10-05 22:51:42 -04:00
|
|
|
state.Put("vmnetwork", network)
|
2015-11-11 07:39:06 -05:00
|
|
|
|
2016-10-05 22:51:42 -04:00
|
|
|
/// check if serial port has been configured
|
2018-11-17 02:23:28 -05:00
|
|
|
if !config.HWConfig.HasSerial() {
|
2017-04-13 21:01:10 -04:00
|
|
|
templateData.Serial_Present = "FALSE"
|
|
|
|
} else {
|
2018-11-17 02:23:28 -05:00
|
|
|
// FIXME
|
|
|
|
serial, err := config.HWConfig.ReadSerial()
|
2015-11-11 07:39:06 -05:00
|
|
|
if err != nil {
|
2018-03-13 22:17:22 -04:00
|
|
|
err := fmt.Errorf("Error processing VMX template: %s", err)
|
2015-11-11 07:39:06 -05:00
|
|
|
state.Put("error", err)
|
|
|
|
ui.Error(err.Error())
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
|
|
|
templateData.Serial_Present = "TRUE"
|
|
|
|
templateData.Serial_Filename = ""
|
|
|
|
templateData.Serial_Yield = ""
|
|
|
|
templateData.Serial_Endpoint = ""
|
|
|
|
templateData.Serial_Host = ""
|
2016-10-05 22:51:42 -04:00
|
|
|
templateData.Serial_Auto = "FALSE"
|
2015-11-11 07:39:06 -05:00
|
|
|
|
2018-11-27 18:43:48 -05:00
|
|
|
// Set the number of cpus if it was specified
|
|
|
|
if config.HWConfig.CpuCount > 0 {
|
|
|
|
templateData.CpuCount = strconv.Itoa(config.HWConfig.CpuCount)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Apply the memory size that was specified
|
|
|
|
if config.HWConfig.MemorySize > 0 {
|
|
|
|
templateData.MemorySize = strconv.Itoa(config.HWConfig.MemorySize)
|
|
|
|
} else {
|
|
|
|
templateData.MemorySize = "512"
|
|
|
|
}
|
|
|
|
|
2018-11-17 02:23:28 -05:00
|
|
|
switch serial.Union.(type) {
|
|
|
|
case *vmwcommon.SerialConfigPipe:
|
2017-02-27 16:34:53 -05:00
|
|
|
templateData.Serial_Type = "pipe"
|
2018-11-17 02:23:28 -05:00
|
|
|
templateData.Serial_Endpoint = serial.Pipe.Endpoint
|
|
|
|
templateData.Serial_Host = serial.Pipe.Host
|
|
|
|
templateData.Serial_Yield = serial.Pipe.Yield
|
|
|
|
templateData.Serial_Filename = filepath.FromSlash(serial.Pipe.Filename)
|
|
|
|
case *vmwcommon.SerialConfigFile:
|
2017-02-27 16:34:53 -05:00
|
|
|
templateData.Serial_Type = "file"
|
2018-11-17 02:23:28 -05:00
|
|
|
templateData.Serial_Filename = filepath.FromSlash(serial.File.Filename)
|
|
|
|
case *vmwcommon.SerialConfigDevice:
|
2017-02-27 16:34:53 -05:00
|
|
|
templateData.Serial_Type = "device"
|
2018-11-17 02:23:28 -05:00
|
|
|
templateData.Serial_Filename = filepath.FromSlash(serial.Device.Devicename)
|
|
|
|
case *vmwcommon.SerialConfigAuto:
|
2017-02-27 16:34:53 -05:00
|
|
|
templateData.Serial_Type = "device"
|
2018-11-17 02:23:28 -05:00
|
|
|
templateData.Serial_Filename = filepath.FromSlash(serial.Auto.Devicename)
|
|
|
|
templateData.Serial_Yield = serial.Auto.Yield
|
2017-02-27 16:34:53 -05:00
|
|
|
templateData.Serial_Auto = "TRUE"
|
2017-04-12 18:41:36 -04:00
|
|
|
case nil:
|
2017-04-13 21:01:10 -04:00
|
|
|
templateData.Serial_Present = "FALSE"
|
2017-04-12 18:41:36 -04:00
|
|
|
break
|
2016-10-05 22:51:42 -04:00
|
|
|
|
2017-02-27 16:34:53 -05:00
|
|
|
default:
|
2018-03-13 22:17:22 -04:00
|
|
|
err := fmt.Errorf("Error processing VMX template: %v", serial)
|
2017-02-27 16:34:53 -05:00
|
|
|
state.Put("error", err)
|
|
|
|
ui.Error(err.Error())
|
|
|
|
return multistep.ActionHalt
|
2015-11-11 07:39:06 -05:00
|
|
|
}
|
2015-06-04 14:44:07 -04:00
|
|
|
}
|
|
|
|
|
2016-10-05 22:51:42 -04:00
|
|
|
/// check if parallel port has been configured
|
2018-11-17 02:23:28 -05:00
|
|
|
if !config.HWConfig.HasParallel() {
|
2017-04-13 21:01:10 -04:00
|
|
|
templateData.Parallel_Present = "FALSE"
|
|
|
|
} else {
|
2018-11-17 02:23:28 -05:00
|
|
|
// FIXME
|
|
|
|
parallel, err := config.HWConfig.ReadParallel()
|
2015-11-11 07:39:06 -05:00
|
|
|
if err != nil {
|
2018-03-13 22:17:22 -04:00
|
|
|
err := fmt.Errorf("Error processing VMX template: %s", err)
|
2015-11-11 07:39:06 -05:00
|
|
|
state.Put("error", err)
|
|
|
|
ui.Error(err.Error())
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
2016-10-05 22:51:42 -04:00
|
|
|
templateData.Parallel_Auto = "FALSE"
|
2018-11-17 02:23:28 -05:00
|
|
|
switch parallel.Union.(type) {
|
|
|
|
case *vmwcommon.ParallelPortFile:
|
2017-02-27 16:34:53 -05:00
|
|
|
templateData.Parallel_Present = "TRUE"
|
2018-11-17 02:23:28 -05:00
|
|
|
templateData.Parallel_Filename = filepath.FromSlash(parallel.File.Filename)
|
|
|
|
case *vmwcommon.ParallelPortDevice:
|
2017-02-27 16:34:53 -05:00
|
|
|
templateData.Parallel_Present = "TRUE"
|
2018-11-17 02:23:28 -05:00
|
|
|
templateData.Parallel_Bidirectional = parallel.Device.Bidirectional
|
|
|
|
templateData.Parallel_Filename = filepath.FromSlash(parallel.Device.Devicename)
|
|
|
|
case *vmwcommon.ParallelPortAuto:
|
2017-02-27 16:34:53 -05:00
|
|
|
templateData.Parallel_Present = "TRUE"
|
|
|
|
templateData.Parallel_Auto = "TRUE"
|
2018-11-17 02:23:28 -05:00
|
|
|
templateData.Parallel_Bidirectional = parallel.Auto.Bidirectional
|
2017-04-12 18:41:36 -04:00
|
|
|
case nil:
|
2017-04-13 21:01:10 -04:00
|
|
|
templateData.Parallel_Present = "FALSE"
|
2017-04-12 18:41:36 -04:00
|
|
|
break
|
|
|
|
|
2017-02-27 16:34:53 -05:00
|
|
|
default:
|
2018-03-13 22:17:22 -04:00
|
|
|
err := fmt.Errorf("Error processing VMX template: %v", parallel)
|
2017-02-27 16:34:53 -05:00
|
|
|
state.Put("error", err)
|
|
|
|
ui.Error(err.Error())
|
|
|
|
return multistep.ActionHalt
|
2015-11-11 07:39:06 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-29 11:50:02 -04:00
|
|
|
ictx.Data = &templateData
|
2015-11-11 07:39:06 -05:00
|
|
|
|
2016-10-05 22:51:42 -04:00
|
|
|
/// render the .vmx template
|
2019-03-29 11:50:02 -04:00
|
|
|
vmxContents, err := interpolate.Render(vmxTemplate, &ictx)
|
2013-08-27 20:23:22 -04:00
|
|
|
if err != nil {
|
2018-03-13 22:17:22 -04:00
|
|
|
err := fmt.Errorf("Error processing VMX template: %s", err)
|
2013-08-31 15:50:25 -04:00
|
|
|
state.Put("error", err)
|
2013-08-27 20:23:22 -04:00
|
|
|
ui.Error(err.Error())
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
2013-11-08 00:02:12 -05:00
|
|
|
vmxDir := config.OutputDir
|
|
|
|
if config.RemoteType != "" {
|
|
|
|
// For remote builds, we just put the VMX in a temporary
|
|
|
|
// directory since it just gets uploaded anyways.
|
2018-12-12 09:45:00 -05:00
|
|
|
vmxDir, err = tmp.Dir("vmw-iso")
|
2013-11-08 00:02:12 -05:00
|
|
|
if err != nil {
|
|
|
|
err := fmt.Errorf("Error preparing VMX template: %s", err)
|
|
|
|
state.Put("error", err)
|
|
|
|
ui.Error(err.Error())
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the tempDir so we clean it up
|
|
|
|
s.tempDir = vmxDir
|
|
|
|
}
|
|
|
|
|
2019-01-11 20:00:54 -05:00
|
|
|
/// Now to handle options that will modify the template without using "vmxTemplateData"
|
2018-11-21 01:43:14 -05:00
|
|
|
vmxData := vmwcommon.ParseVMX(vmxContents)
|
2019-01-11 20:00:54 -05:00
|
|
|
|
|
|
|
// If no cpus were specified, then remove the entry to use the default
|
2018-11-27 18:43:48 -05:00
|
|
|
if vmxData["numvcpus"] == "" {
|
|
|
|
delete(vmxData, "numvcpus")
|
2018-11-21 01:43:14 -05:00
|
|
|
}
|
|
|
|
|
2019-01-11 20:00:54 -05:00
|
|
|
// If some number of cores were specified, then update "cpuid.coresPerSocket" with the requested value
|
|
|
|
if config.HWConfig.CoreCount > 0 {
|
|
|
|
vmxData["cpuid.corespersocket"] = strconv.Itoa(config.HWConfig.CoreCount)
|
|
|
|
}
|
|
|
|
|
2018-11-21 01:43:14 -05:00
|
|
|
/// Write the vmxData to the vmxPath
|
2013-11-08 00:02:12 -05:00
|
|
|
vmxPath := filepath.Join(vmxDir, config.VMName+".vmx")
|
2018-11-21 01:43:14 -05:00
|
|
|
if err := vmwcommon.WriteVMX(vmxPath, vmxData); err != nil {
|
2013-06-20 00:20:48 -04:00
|
|
|
err := fmt.Errorf("Error creating VMX file: %s", err)
|
2013-08-31 15:50:25 -04:00
|
|
|
state.Put("error", err)
|
2013-06-20 00:20:48 -04:00
|
|
|
ui.Error(err.Error())
|
2013-06-07 19:20:58 -04:00
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
2013-06-04 19:52:59 -04:00
|
|
|
|
2013-08-31 15:50:25 -04:00
|
|
|
state.Put("vmx_path", vmxPath)
|
2013-06-05 16:17:56 -04:00
|
|
|
|
2013-06-04 19:52:59 -04:00
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
2013-11-08 00:02:12 -05:00
|
|
|
func (s *stepCreateVMX) Cleanup(multistep.StateBag) {
|
|
|
|
if s.tempDir != "" {
|
|
|
|
os.RemoveAll(s.tempDir)
|
|
|
|
}
|
2013-06-04 19:52:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// This is the default VMX template used if no other template is given.
|
|
|
|
// This is hardcoded here. If you wish to use a custom template please
|
|
|
|
// do so by specifying in the builder configuration.
|
|
|
|
const DefaultVMXTemplate = `
|
|
|
|
.encoding = "UTF-8"
|
2018-11-16 23:20:00 -05:00
|
|
|
|
|
|
|
displayName = "{{ .Name }}"
|
|
|
|
|
|
|
|
// Hardware
|
2018-11-17 02:23:28 -05:00
|
|
|
numvcpus = "{{ .CpuCount }}"
|
|
|
|
memsize = "{{ .MemorySize }}"
|
2018-11-16 23:20:00 -05:00
|
|
|
|
|
|
|
config.version = "8"
|
|
|
|
virtualHW.productCompatibility = "hosted"
|
|
|
|
virtualHW.version = "{{ .Version }}"
|
|
|
|
|
|
|
|
// Bootup
|
|
|
|
nvram = "{{ .Name }}.nvram"
|
|
|
|
|
|
|
|
floppy0.present = "FALSE"
|
2018-04-26 15:16:50 -04:00
|
|
|
bios.bootOrder = "hdd,cdrom"
|
2018-11-16 23:20:00 -05:00
|
|
|
|
|
|
|
// Configuration
|
2013-06-04 19:52:59 -04:00
|
|
|
extendedConfigFile = "{{ .Name }}.vmxf"
|
|
|
|
gui.fullScreenAtPowerOn = "FALSE"
|
|
|
|
gui.viewModeAtPowerOn = "windowed"
|
|
|
|
hgfs.linkRootShare = "TRUE"
|
|
|
|
hgfs.mapRootShare = "TRUE"
|
2018-11-16 23:20:00 -05:00
|
|
|
isolation.tools.hgfs.disable = "FALSE"
|
|
|
|
proxyApps.publishToHost = "FALSE"
|
|
|
|
replay.filename = ""
|
|
|
|
replay.supported = "FALSE"
|
2017-12-25 15:08:08 -05:00
|
|
|
|
2018-11-16 23:20:00 -05:00
|
|
|
checkpoint.vmState = ""
|
|
|
|
vmotion.checkpointFBSize = "65536000"
|
2017-12-25 15:08:08 -05:00
|
|
|
|
2018-11-16 23:20:00 -05:00
|
|
|
// Power control
|
|
|
|
cleanShutdown = "TRUE"
|
|
|
|
powerType.powerOff = "soft"
|
|
|
|
powerType.powerOn = "soft"
|
|
|
|
powerType.reset = "soft"
|
|
|
|
powerType.suspend = "soft"
|
2017-12-25 15:08:08 -05:00
|
|
|
|
2018-11-16 23:20:00 -05:00
|
|
|
// Tools
|
|
|
|
guestOS = "{{ .GuestOS }}"
|
|
|
|
tools.syncTime = "TRUE"
|
|
|
|
tools.upgrade.policy = "upgradeAtPowerCycle"
|
2017-12-25 15:08:08 -05:00
|
|
|
|
2018-11-16 23:20:00 -05:00
|
|
|
// Bus
|
2013-06-04 19:52:59 -04:00
|
|
|
pciBridge0.pciSlotNumber = "17"
|
|
|
|
pciBridge0.present = "TRUE"
|
|
|
|
pciBridge4.functions = "8"
|
|
|
|
pciBridge4.pciSlotNumber = "21"
|
|
|
|
pciBridge4.present = "TRUE"
|
|
|
|
pciBridge4.virtualDev = "pcieRootPort"
|
|
|
|
pciBridge5.functions = "8"
|
|
|
|
pciBridge5.pciSlotNumber = "22"
|
|
|
|
pciBridge5.present = "TRUE"
|
|
|
|
pciBridge5.virtualDev = "pcieRootPort"
|
|
|
|
pciBridge6.functions = "8"
|
|
|
|
pciBridge6.pciSlotNumber = "23"
|
|
|
|
pciBridge6.present = "TRUE"
|
|
|
|
pciBridge6.virtualDev = "pcieRootPort"
|
|
|
|
pciBridge7.functions = "8"
|
|
|
|
pciBridge7.pciSlotNumber = "24"
|
|
|
|
pciBridge7.present = "TRUE"
|
|
|
|
pciBridge7.virtualDev = "pcieRootPort"
|
2018-11-16 23:20:00 -05:00
|
|
|
|
|
|
|
ehci.present = "TRUE"
|
|
|
|
ehci.pciSlotNumber = "34"
|
|
|
|
|
|
|
|
vmci0.present = "TRUE"
|
|
|
|
vmci0.id = "1861462627"
|
|
|
|
vmci0.pciSlotNumber = "35"
|
|
|
|
|
|
|
|
// Network Adapter
|
|
|
|
ethernet0.addressType = "generated"
|
|
|
|
ethernet0.bsdName = "en0"
|
|
|
|
ethernet0.connectionType = "{{ .Network_Type }}"
|
|
|
|
ethernet0.vnet = "{{ .Network_Device }}"
|
|
|
|
ethernet0.displayName = "Ethernet"
|
|
|
|
ethernet0.linkStatePropagation.enable = "FALSE"
|
|
|
|
ethernet0.pciSlotNumber = "33"
|
|
|
|
ethernet0.present = "TRUE"
|
|
|
|
ethernet0.virtualDev = "{{ .Network_Adapter }}"
|
|
|
|
ethernet0.wakeOnPcktRcv = "FALSE"
|
|
|
|
|
|
|
|
// Hard disks
|
|
|
|
scsi0.present = "{{ .SCSI_Present }}"
|
|
|
|
scsi0.virtualDev = "{{ .SCSI_diskAdapterType }}"
|
|
|
|
scsi0.pciSlotNumber = "16"
|
|
|
|
scsi0:0.redo = ""
|
|
|
|
sata0.present = "{{ .SATA_Present }}"
|
|
|
|
nvme0.present = "{{ .NVME_Present }}"
|
|
|
|
|
|
|
|
{{ .DiskType }}0:0.present = "TRUE"
|
|
|
|
{{ .DiskType }}0:0.fileName = "{{ .DiskName }}.vmdk"
|
|
|
|
|
|
|
|
{{ .CDROMType }}0:{{ .CDROMType_PrimarySecondary }}.present = "TRUE"
|
|
|
|
{{ .CDROMType }}0:{{ .CDROMType_PrimarySecondary }}.fileName = "{{ .ISOPath }}"
|
|
|
|
{{ .CDROMType }}0:{{ .CDROMType_PrimarySecondary }}.deviceType = "cdrom-image"
|
2015-11-11 07:39:06 -05:00
|
|
|
|
|
|
|
// Sound
|
|
|
|
sound.startConnected = "{{ .Sound_Present }}"
|
|
|
|
sound.present = "{{ .Sound_Present }}"
|
|
|
|
sound.fileName = "-1"
|
|
|
|
sound.autodetect = "TRUE"
|
|
|
|
|
|
|
|
// USB
|
2013-06-04 19:52:59 -04:00
|
|
|
usb.pciSlotNumber = "32"
|
2015-11-11 07:39:06 -05:00
|
|
|
usb.present = "{{ .Usb_Present }}"
|
|
|
|
|
|
|
|
// Serial
|
|
|
|
serial0.present = "{{ .Serial_Present }}"
|
|
|
|
serial0.startConnected = "{{ .Serial_Present }}"
|
|
|
|
serial0.fileName = "{{ .Serial_Filename }}"
|
2016-10-05 22:51:42 -04:00
|
|
|
serial0.autodetect = "{{ .Serial_Auto }}"
|
2015-11-11 07:39:06 -05:00
|
|
|
serial0.fileType = "{{ .Serial_Type }}"
|
|
|
|
serial0.yieldOnMsrRead = "{{ .Serial_Yield }}"
|
|
|
|
serial0.pipe.endPoint = "{{ .Serial_Endpoint }}"
|
|
|
|
serial0.tryNoRxLoss = "{{ .Serial_Host }}"
|
|
|
|
|
|
|
|
// Parallel
|
|
|
|
parallel0.present = "{{ .Parallel_Present }}"
|
|
|
|
parallel0.startConnected = "{{ .Parallel_Present }}"
|
|
|
|
parallel0.fileName = "{{ .Parallel_Filename }}"
|
2016-10-05 22:51:42 -04:00
|
|
|
parallel0.autodetect = "{{ .Parallel_Auto }}"
|
2015-11-11 07:39:06 -05:00
|
|
|
parallel0.bidirectional = "{{ .Parallel_Bidirectional }}"
|
2013-06-04 19:52:59 -04:00
|
|
|
`
|
2014-03-04 13:23:07 -05:00
|
|
|
|
|
|
|
const DefaultAdditionalDiskTemplate = `
|
|
|
|
scsi0:{{ .DiskNumber }}.fileName = "{{ .DiskName}}-{{ .DiskNumber }}.vmdk"
|
|
|
|
scsi0:{{ .DiskNumber }}.present = "TRUE"
|
|
|
|
scsi0:{{ .DiskNumber }}.redo = ""
|
|
|
|
`
|