Added support for specifying the disk adapter type to the vmware builders. This was squashed from the vmware-diskAdapterType branch (#2968) as submitted by Rami Abughazaleh <icnocop@users.noreply.github.com>. This closes #5671 and possibly #4885.
arizvisa: Updated icnocop's documentation to include the possible disk adapter types that one can specify. arizvisa: Tweaked icnocop's support for the `disk_adapter_type` option to the VMWare builder that caused conflicts due to version skew. icnocop: Updated links to the Virtual Disk Manager User's Guide PDF to open in a new window and also added the Adobe PDF icon icnocop: Added support for vmware to specify the disk adapter type, ide or scsi (lsilogic or buslogic)
This commit is contained in:
parent
594ed950c7
commit
74946071d2
|
@ -29,7 +29,7 @@ type Driver interface {
|
||||||
CompactDisk(string) error
|
CompactDisk(string) error
|
||||||
|
|
||||||
// CreateDisk creates a virtual disk with the given size.
|
// CreateDisk creates a virtual disk with the given size.
|
||||||
CreateDisk(string, string, string) error
|
CreateDisk(string, string, string, string) error
|
||||||
|
|
||||||
// Checks if the VMX file at the given path is running.
|
// Checks if the VMX file at the given path is running.
|
||||||
IsRunning(string) (bool, error)
|
IsRunning(string) (bool, error)
|
||||||
|
|
|
@ -41,8 +41,8 @@ func (d *Fusion5Driver) CompactDisk(diskPath string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Fusion5Driver) CreateDisk(output string, size string, type_id string) error {
|
func (d *Fusion5Driver) CreateDisk(output string, size string, adapter_type string, type_id string) error {
|
||||||
cmd := exec.Command(d.vdiskManagerPath(), "-c", "-s", size, "-a", "lsilogic", "-t", type_id, output)
|
cmd := exec.Command(d.vdiskManagerPath(), "-c", "-s", size, "-a", adapter_type, "-t", type_id, output)
|
||||||
if _, _, err := runAndLog(cmd); err != nil {
|
if _, _, err := runAndLog(cmd); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,11 +19,12 @@ type DriverMock struct {
|
||||||
CompactDiskPath string
|
CompactDiskPath string
|
||||||
CompactDiskErr error
|
CompactDiskErr error
|
||||||
|
|
||||||
CreateDiskCalled bool
|
CreateDiskCalled bool
|
||||||
CreateDiskOutput string
|
CreateDiskOutput string
|
||||||
CreateDiskSize string
|
CreateDiskSize string
|
||||||
CreateDiskTypeId string
|
CreateDiskAdapterType string
|
||||||
CreateDiskErr error
|
CreateDiskTypeId string
|
||||||
|
CreateDiskErr error
|
||||||
|
|
||||||
IsRunningCalled bool
|
IsRunningCalled bool
|
||||||
IsRunningPath string
|
IsRunningPath string
|
||||||
|
@ -119,10 +120,11 @@ func (d *DriverMock) CompactDisk(path string) error {
|
||||||
return d.CompactDiskErr
|
return d.CompactDiskErr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DriverMock) CreateDisk(output string, size string, typeId string) error {
|
func (d *DriverMock) CreateDisk(output string, size string, adapterType string, typeId string) error {
|
||||||
d.CreateDiskCalled = true
|
d.CreateDiskCalled = true
|
||||||
d.CreateDiskOutput = output
|
d.CreateDiskOutput = output
|
||||||
d.CreateDiskSize = size
|
d.CreateDiskSize = size
|
||||||
|
d.CreateDiskAdapterType = adapterType
|
||||||
d.CreateDiskTypeId = typeId
|
d.CreateDiskTypeId = typeId
|
||||||
return d.CreateDiskErr
|
return d.CreateDiskErr
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,12 +64,12 @@ func (d *Player5Driver) qemuCompactDisk(diskPath string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Player5Driver) CreateDisk(output string, size string, type_id string) error {
|
func (d *Player5Driver) CreateDisk(output string, size string, adapter_type string, type_id string) error {
|
||||||
var cmd *exec.Cmd
|
var cmd *exec.Cmd
|
||||||
if d.QemuImgPath != "" {
|
if d.QemuImgPath != "" {
|
||||||
cmd = exec.Command(d.QemuImgPath, "create", "-f", "vmdk", "-o", "compat6", output, size)
|
cmd = exec.Command(d.QemuImgPath, "create", "-f", "vmdk", "-o", "compat6", output, size)
|
||||||
} else {
|
} else {
|
||||||
cmd = exec.Command(d.VdiskManagerPath, "-c", "-s", size, "-a", "lsilogic", "-t", type_id, output)
|
cmd = exec.Command(d.VdiskManagerPath, "-c", "-s", size, "-a", adapter_type, "-t", type_id, output)
|
||||||
}
|
}
|
||||||
if _, _, err := runAndLog(cmd); err != nil {
|
if _, _, err := runAndLog(cmd); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -42,8 +42,8 @@ func (d *Workstation9Driver) CompactDisk(diskPath string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Workstation9Driver) CreateDisk(output string, size string, type_id string) error {
|
func (d *Workstation9Driver) CreateDisk(output string, size string, adapter_type string, type_id string) error {
|
||||||
cmd := exec.Command(d.VdiskManagerPath, "-c", "-s", size, "-a", "lsilogic", "-t", type_id, output)
|
cmd := exec.Command(d.VdiskManagerPath, "-c", "-s", size, "-a", adapter_type, "-t", type_id, output)
|
||||||
if _, _, err := runAndLog(cmd); err != nil {
|
if _, _, err := runAndLog(cmd); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,7 @@ type Config struct {
|
||||||
|
|
||||||
// disk drives
|
// disk drives
|
||||||
AdditionalDiskSize []uint `mapstructure:"disk_additional_size"`
|
AdditionalDiskSize []uint `mapstructure:"disk_additional_size"`
|
||||||
|
DiskAdapterType string `mapstructure:"disk_adapter_type"`
|
||||||
DiskName string `mapstructure:"vmdk_name"`
|
DiskName string `mapstructure:"vmdk_name"`
|
||||||
DiskSize uint `mapstructure:"disk_size"`
|
DiskSize uint `mapstructure:"disk_size"`
|
||||||
DiskTypeId string `mapstructure:"disk_type_id"`
|
DiskTypeId string `mapstructure:"disk_type_id"`
|
||||||
|
@ -126,6 +127,11 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
|
||||||
b.config.DiskSize = 40000
|
b.config.DiskSize = 40000
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if b.config.DiskAdapterType == "" {
|
||||||
|
// Default is lsilogic
|
||||||
|
b.config.DiskAdapterType = "lsilogic"
|
||||||
|
}
|
||||||
|
|
||||||
if b.config.DiskTypeId == "" {
|
if b.config.DiskTypeId == "" {
|
||||||
// Default is growable virtual disk split in 2GB files.
|
// Default is growable virtual disk split in 2GB files.
|
||||||
b.config.DiskTypeId = "1"
|
b.config.DiskTypeId = "1"
|
||||||
|
|
|
@ -50,9 +50,9 @@ func (d *ESX5Driver) CompactDisk(diskPathLocal string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *ESX5Driver) CreateDisk(diskPathLocal string, size string, typeId string) error {
|
func (d *ESX5Driver) CreateDisk(diskPathLocal string, size string, adapter_type string, typeId string) error {
|
||||||
diskPath := d.datastorePath(diskPathLocal)
|
diskPath := d.datastorePath(diskPathLocal)
|
||||||
return d.sh("vmkfstools", "-c", size, "-d", typeId, "-a", "lsilogic", diskPath)
|
return d.sh("vmkfstools", "-c", size, "-d", typeId, "-a", adapter_type, diskPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *ESX5Driver) IsRunning(string) (bool, error) {
|
func (d *ESX5Driver) IsRunning(string) (bool, error) {
|
||||||
|
|
|
@ -28,7 +28,7 @@ func (stepCreateDisk) Run(_ context.Context, state multistep.StateBag) multistep
|
||||||
|
|
||||||
ui.Say("Creating virtual machine disk")
|
ui.Say("Creating virtual machine disk")
|
||||||
full_disk_path := filepath.Join(config.OutputDir, config.DiskName+".vmdk")
|
full_disk_path := filepath.Join(config.OutputDir, config.DiskName+".vmdk")
|
||||||
if err := driver.CreateDisk(full_disk_path, fmt.Sprintf("%dM", config.DiskSize), config.DiskTypeId); err != nil {
|
if err := driver.CreateDisk(full_disk_path, fmt.Sprintf("%dM", config.DiskSize), config.DiskAdapterType, config.DiskTypeId); err != nil {
|
||||||
err := fmt.Errorf("Error creating disk: %s", err)
|
err := fmt.Errorf("Error creating disk: %s", err)
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
ui.Error(err.Error())
|
ui.Error(err.Error())
|
||||||
|
@ -46,7 +46,7 @@ func (stepCreateDisk) Run(_ context.Context, state multistep.StateBag) multistep
|
||||||
additionalpath := filepath.Join(config.OutputDir, fmt.Sprintf("%s-%d.vmdk", config.DiskName, i+1))
|
additionalpath := filepath.Join(config.OutputDir, fmt.Sprintf("%s-%d.vmdk", config.DiskName, i+1))
|
||||||
size := fmt.Sprintf("%dM", uint64(additionalsize))
|
size := fmt.Sprintf("%dM", uint64(additionalsize))
|
||||||
|
|
||||||
if err := driver.CreateDisk(additionalpath, size, config.DiskTypeId); err != nil {
|
if err := driver.CreateDisk(additionalpath, size, config.DiskAdapterType, config.DiskTypeId); err != nil {
|
||||||
err := fmt.Errorf("Error creating additional disk: %s", err)
|
err := fmt.Errorf("Error creating additional disk: %s", err)
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
ui.Error(err.Error())
|
ui.Error(err.Error())
|
||||||
|
|
|
@ -16,11 +16,20 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type vmxTemplateData struct {
|
type vmxTemplateData struct {
|
||||||
Name string
|
Name string
|
||||||
GuestOS string
|
GuestOS string
|
||||||
DiskName string
|
ISOPath string
|
||||||
ISOPath string
|
Version string
|
||||||
Version string
|
|
||||||
|
SCSI_Present string
|
||||||
|
SCSI_diskAdapterType string
|
||||||
|
SATA_Present string
|
||||||
|
NVME_Present string
|
||||||
|
|
||||||
|
DiskName string
|
||||||
|
DiskType string
|
||||||
|
CDROMType string
|
||||||
|
CDROMType_MasterSlave string
|
||||||
|
|
||||||
Network_Type string
|
Network_Type string
|
||||||
Network_Device string
|
Network_Device string
|
||||||
|
@ -287,6 +296,11 @@ func (s *stepCreateVMX) Run(_ context.Context, state multistep.StateBag) multist
|
||||||
isoPath := state.Get("iso_path").(string)
|
isoPath := state.Get("iso_path").(string)
|
||||||
ui := state.Get("ui").(packer.Ui)
|
ui := state.Get("ui").(packer.Ui)
|
||||||
|
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
|
||||||
ui.Say("Building and writing VMX file")
|
ui.Say("Building and writing VMX file")
|
||||||
|
|
||||||
vmxTemplate := DefaultVMXTemplate
|
vmxTemplate := DefaultVMXTemplate
|
||||||
|
@ -361,6 +375,15 @@ func (s *stepCreateVMX) Run(_ context.Context, state multistep.StateBag) multist
|
||||||
Version: config.Version,
|
Version: config.Version,
|
||||||
ISOPath: isoPath,
|
ISOPath: isoPath,
|
||||||
|
|
||||||
|
SCSI_Present: "FALSE",
|
||||||
|
SCSI_diskAdapterType: "lsilogic",
|
||||||
|
SATA_Present: "FALSE",
|
||||||
|
NVME_Present: "FALSE",
|
||||||
|
|
||||||
|
DiskType: "scsi",
|
||||||
|
CDROMType: "ide",
|
||||||
|
CDROMType_MasterSlave: "0",
|
||||||
|
|
||||||
Sound_Present: map[bool]string{true: "TRUE", false: "FALSE"}[bool(config.Sound)],
|
Sound_Present: map[bool]string{true: "TRUE", false: "FALSE"}[bool(config.Sound)],
|
||||||
Usb_Present: map[bool]string{true: "TRUE", false: "FALSE"}[bool(config.USB)],
|
Usb_Present: map[bool]string{true: "TRUE", false: "FALSE"}[bool(config.USB)],
|
||||||
|
|
||||||
|
@ -368,6 +391,36 @@ func (s *stepCreateVMX) Run(_ context.Context, state multistep.StateBag) multist
|
||||||
Parallel_Present: "FALSE",
|
Parallel_Present: "FALSE",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 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.
|
||||||
|
diskAdapterType := strings.ToLower(config.DiskAdapterType)
|
||||||
|
switch diskAdapterType {
|
||||||
|
case "ide":
|
||||||
|
templateData.DiskType = "ide"
|
||||||
|
templateData.CDROMType = "ide"
|
||||||
|
templateData.CDROMType_MasterSlave = "1"
|
||||||
|
case "sata":
|
||||||
|
templateData.SATA_Present = "TRUE"
|
||||||
|
templateData.DiskType = "sata"
|
||||||
|
templateData.CDROMType = "sata"
|
||||||
|
templateData.CDROMType_MasterSlave = "1"
|
||||||
|
case "nvme":
|
||||||
|
templateData.NVME_Present = "TRUE"
|
||||||
|
templateData.DiskType = "nvme"
|
||||||
|
templateData.SATA_Present = "TRUE"
|
||||||
|
templateData.CDROMType = "sata"
|
||||||
|
templateData.CDROMType_MasterSlave = "0"
|
||||||
|
case "scsi":
|
||||||
|
diskAdapterType = "lsilogic"
|
||||||
|
fallthrough
|
||||||
|
default:
|
||||||
|
templateData.SCSI_Present = "TRUE"
|
||||||
|
templateData.SCSI_diskAdapterType = diskAdapterType
|
||||||
|
templateData.DiskType = "scsi"
|
||||||
|
templateData.CDROMType = "ide"
|
||||||
|
templateData.CDROMType_MasterSlave = "0"
|
||||||
|
}
|
||||||
|
|
||||||
/// Check the network type that the user specified
|
/// Check the network type that the user specified
|
||||||
network := config.Network
|
network := config.Network
|
||||||
driver := state.Get("driver").(vmwcommon.Driver).GetVmwareDriver()
|
driver := state.Get("driver").(vmwcommon.Driver).GetVmwareDriver()
|
||||||
|
@ -556,9 +609,21 @@ gui.fullScreenAtPowerOn = "FALSE"
|
||||||
gui.viewModeAtPowerOn = "windowed"
|
gui.viewModeAtPowerOn = "windowed"
|
||||||
hgfs.linkRootShare = "TRUE"
|
hgfs.linkRootShare = "TRUE"
|
||||||
hgfs.mapRootShare = "TRUE"
|
hgfs.mapRootShare = "TRUE"
|
||||||
ide1:0.present = "TRUE"
|
|
||||||
ide1:0.fileName = "{{ .ISOPath }}"
|
scsi0.present = "{{ .SCSI_Present }}"
|
||||||
ide1:0.deviceType = "cdrom-image"
|
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_MasterSlave }}.present = "TRUE"
|
||||||
|
{{ .CDROMType }}0:{{ .CDROMType_MasterSlave }}.fileName = "{{ .ISOPath }}"
|
||||||
|
{{ .CDROMType }}0:{{ .CDROMType_MasterSlave }}.deviceType = "cdrom-image"
|
||||||
|
|
||||||
isolation.tools.hgfs.disable = "FALSE"
|
isolation.tools.hgfs.disable = "FALSE"
|
||||||
memsize = "512"
|
memsize = "512"
|
||||||
nvram = "{{ .Name }}.nvram"
|
nvram = "{{ .Name }}.nvram"
|
||||||
|
@ -587,12 +652,6 @@ powerType.suspend = "soft"
|
||||||
proxyApps.publishToHost = "FALSE"
|
proxyApps.publishToHost = "FALSE"
|
||||||
replay.filename = ""
|
replay.filename = ""
|
||||||
replay.supported = "FALSE"
|
replay.supported = "FALSE"
|
||||||
scsi0.pciSlotNumber = "16"
|
|
||||||
scsi0.present = "TRUE"
|
|
||||||
scsi0.virtualDev = "lsilogic"
|
|
||||||
scsi0:0.fileName = "{{ .DiskName }}.vmdk"
|
|
||||||
scsi0:0.present = "TRUE"
|
|
||||||
scsi0:0.redo = ""
|
|
||||||
|
|
||||||
// Sound
|
// Sound
|
||||||
sound.startConnected = "{{ .Sound_Present }}"
|
sound.startConnected = "{{ .Sound_Present }}"
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
|
@ -131,7 +131,16 @@ builder.
|
||||||
Guide](https://www.vmware.com/pdf/VirtualDiskManager.pdf) for desktop
|
Guide](https://www.vmware.com/pdf/VirtualDiskManager.pdf) for desktop
|
||||||
VMware clients. For ESXi, refer to the proper ESXi documentation.
|
VMware clients. For ESXi, refer to the proper ESXi documentation.
|
||||||
|
|
||||||
* `disable_vnc` (boolean) - Whether to create a VNC connection or not.
|
- `disk_adapter_type` (string) - The adapter type of the VMware virtual disk
|
||||||
|
to create. This option is for advanced usage, modify only if you know what
|
||||||
|
you're doing. Some of the options you can specify are "ide", "sata", "nvme"
|
||||||
|
or "scsi" (which uses the "lsilogic" scsi interface by default). If you
|
||||||
|
specify another option, Packer will assume that you're specifying a "scsi"
|
||||||
|
interface of that specified type. For more information, please consult the
|
||||||
|
<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.
|
||||||
|
|
||||||
|
- `disable_vnc` (boolean) - Whether to create a VNC connection or not.
|
||||||
A `boot_command` cannot be used when this is `false`. Defaults to `false`.
|
A `boot_command` cannot be used when this is `false`. Defaults to `false`.
|
||||||
|
|
||||||
- `floppy_files` (array of strings) - A list of files to place onto a floppy
|
- `floppy_files` (array of strings) - A list of files to place onto a floppy
|
||||||
|
|
Loading…
Reference in New Issue