Added support for specifying both the network adapter type and cdrom adapter type as requested by @night199uk. Also included the respective documentation for these new options.

This commit is contained in:
Ali Rizvi-Santiago 2018-01-16 13:17:37 -06:00
parent 74946071d2
commit eb0445ca96
3 changed files with 56 additions and 5 deletions

View File

@ -46,13 +46,17 @@ type Config struct {
DiskTypeId string `mapstructure:"disk_type_id"`
Format string `mapstructure:"format"`
// cdrom drive
CdromAdapterType string `mapstructure:"cdrom_adapter_type"`
// platform information
GuestOSType string `mapstructure:"guest_os_type"`
Version string `mapstructure:"version"`
VMName string `mapstructure:"vm_name"`
// Network type
Network string `mapstructure:"network"`
// Network adapter and type
NetworkAdapterType string `mapstructure:"network_adapter_type"`
Network string `mapstructure:"network"`
// device presence
Sound bool `mapstructure:"sound"`

View File

@ -31,8 +31,9 @@ type vmxTemplateData struct {
CDROMType string
CDROMType_MasterSlave string
Network_Type string
Network_Device string
Network_Type string
Network_Device string
Network_Adapter string
Sound_Present string
Usb_Present string
@ -384,6 +385,8 @@ func (s *stepCreateVMX) Run(_ context.Context, state multistep.StateBag) multist
CDROMType: "ide",
CDROMType_MasterSlave: "0",
Network_Adapter: "e1000",
Sound_Present: map[bool]string{true: "TRUE", false: "FALSE"}[bool(config.Sound)],
Usb_Present: map[bool]string{true: "TRUE", false: "FALSE"}[bool(config.USB)],
@ -421,6 +424,38 @@ func (s *stepCreateVMX) Run(_ context.Context, state multistep.StateBag) multist
templateData.CDROMType_MasterSlave = "0"
}
/// 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
// slave device on whatever bus the disk adapter is on.
cdromAdapterType := strings.ToLower(config.CdromAdapterType)
if cdromAdapterType == diskAdapterType {
templateData.CDROMType_MasterSlave = "1"
} else {
templateData.CDROMType_MasterSlave = "0"
}
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:
err := fmt.Errorf("Error procesing VMX template: %s", cdromAdapterType)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
/// Assign the network adapter type into the template if one was specified.
network_adapter := strings.ToLower(config.NetworkAdapterType)
if network_adapter != "" {
templateData.Network_Adapter = network_adapter
}
/// Check the network type that the user specified
network := config.Network
driver := state.Get("driver").(vmwcommon.Driver).GetVmwareDriver()
@ -600,7 +635,7 @@ ethernet0.displayName = "Ethernet"
ethernet0.linkStatePropagation.enable = "FALSE"
ethernet0.pciSlotNumber = "33"
ethernet0.present = "TRUE"
ethernet0.virtualDev = "e1000"
ethernet0.virtualDev = "{{ .Network_Adapter }}"
ethernet0.wakeOnPcktRcv = "FALSE"
extendedConfigFile = "{{ .Name }}.vmxf"
floppy0.present = "FALSE"

View File

@ -140,6 +140,12 @@ builder.
<a href="http://www.vmware.com/pdf/VirtualDiskManager.pdf" target="_blank"><img src="../../assets/images/Adobe_PDF_file_icon_24x24.png"/> Virtual Disk Manager User's Guide</a> for desktop VMware clients.
For ESXi, refer to the proper ESXi documentation.
- `cdrom_adapter_type` (string) - The adapter type (or bus) that will be used
by the cdrom device. This is chosen by default based on the disk adapter
type. VMware tends to lean towards "ide" for the cdrom device unless
"sata" is chosen for the disk adapter and so Packer attempts to mirror
this logic. This field can be specified as either "ide", "sata", or "scsi".
- `disable_vnc` (boolean) - Whether to create a VNC connection or not.
A `boot_command` cannot be used when this is `false`. Defaults to `false`.
@ -207,6 +213,12 @@ builder.
such as "hostonly", "nat", or "bridged". If the network is not one of these
values, then it is assumed to be a VMware network device. (VMnet0..x)
- `network_adapter_type` (string) - This is the ethernet adapter type the the
virtual machine will be created with. By default the "e1000" network adapter
type will be used by Packer. For more information, please consult the
<a href="https://kb.vmware.com/s/article/1001805" target="_blank">Choosing a network adapter for your virtual machine</a> for desktop VMware
clients. For ESXi, refer to the proper ESXi documentation.
- `output_directory` (string) - This is the path to the directory where the
resulting virtual machine will be created. This may be relative or absolute.
If relative, the path is relative to the working directory when `packer`