Skip to content

Commit 4555b42

Browse files
LIV2nywilken
authored andcommitted
Fix configuration of additional disk
Additional disks would always get configured as scsi devices regardless of disk_adapter_type This change ensures that additional disks are always configured on the same bus as the primary disk This resolves #91
1 parent 18a4d17 commit 4555b42

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

builder/vmware/iso/step_create_vmx.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,10 @@ type vmxTemplateData struct {
5454
}
5555

5656
type additionalDiskTemplateData struct {
57+
DiskUnit int
5758
DiskNumber int
5859
DiskName string
60+
DiskType string
5961
}
6062

6163
// This step creates the VMX file for the VM.
@@ -98,19 +100,33 @@ func (s *stepCreateVMX) Run(ctx context.Context, state multistep.StateBag) multi
98100
vmxTemplate = string(rawBytes)
99101
}
100102

103+
diskAndCDConfigData := vmwcommon.DefaultDiskAndCDROMTypes(config.DiskAdapterType, config.CdromAdapterType)
101104
ictx := config.ctx
102105

103106
// Mount extra vmdks we created earlier.
104107
if len(config.AdditionalDiskSize) > 0 {
108+
105109
incrementer := 1
110+
111+
// Extra vmdks after Primary disk and CDROM
112+
unitSkip := 2
113+
114+
// If the CDROM is on a different bus we only have to skip the primary disk's unit.
115+
if diskAndCDConfigData.CDROMType != diskAndCDConfigData.DiskType {
116+
unitSkip = 1
117+
}
118+
106119
for i := range config.AdditionalDiskSize {
107120
// slot 7 is special and reserved, so we need to skip that index.
108121
if i+1 == 7 {
109122
incrementer = 2
123+
unitSkip += 1
110124
}
111125
ictx.Data = &additionalDiskTemplateData{
126+
DiskUnit: i + unitSkip,
112127
DiskNumber: i + incrementer,
113128
DiskName: config.DiskName,
129+
DiskType: diskAndCDConfigData.DiskType,
114130
}
115131

116132
diskTemplate := DefaultAdditionalDiskTemplate
@@ -163,7 +179,7 @@ func (s *stepCreateVMX) Run(ctx context.Context, state multistep.StateBag) multi
163179
Parallel_Present: "FALSE",
164180
}
165181

166-
templateData.DiskAndCDConfigData = vmwcommon.DefaultDiskAndCDROMTypes(config.DiskAdapterType, config.CdromAdapterType)
182+
templateData.DiskAndCDConfigData = diskAndCDConfigData
167183

168184
/// Now that we figured out the CDROM device to add, store it
169185
/// to the list of temporary build devices in our statebag
@@ -517,7 +533,7 @@ parallel0.bidirectional = "{{ .Parallel_Bidirectional }}"
517533
`
518534

519535
const DefaultAdditionalDiskTemplate = `
520-
scsi0:{{ .DiskNumber }}.fileName = "{{ .DiskName}}-{{ .DiskNumber }}.vmdk"
521-
scsi0:{{ .DiskNumber }}.present = "TRUE"
522-
scsi0:{{ .DiskNumber }}.redo = ""
536+
{{ .DiskType }}0:{{ .DiskUnit }}.fileName = "{{ .DiskName}}-{{ .DiskNumber }}.vmdk
537+
{{ .DiskType }}0:{{ .DiskUnit }}.present = "TRUE
538+
{{ .DiskType }}0:{{ .DiskUnit }}.redo = "
523539
`

0 commit comments

Comments
 (0)