Skip to content

Commit 71c694c

Browse files
dkallegstack72
authored andcommitted
Additional SCSI controller types support (hashicorp#7525)
This allows the user to specify new controller types. Before when specifying 'scsi', govmomi defaults to lsilogic-parallel. This patch allows the user to now specify 'scsi-lsi-parallel', 'scsi-buslogic', scsi-paravirtual', and 'scsi-lsi-sas'. Resolves issue hashicorp#7202
1 parent 8fa75ea commit 71c694c

1 file changed

Lines changed: 63 additions & 8 deletions

File tree

builtin/providers/vsphere/resource_vsphere_virtual_machine.go

Lines changed: 63 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ var DefaultDNSServers = []string{
2626
"8.8.4.4",
2727
}
2828

29+
var DiskControllerTypes = []string{
30+
"scsi",
31+
"scsi-lsi-parallel",
32+
"scsi-buslogic",
33+
"scsi-paravirtual",
34+
"scsi-lsi-sas",
35+
"ide",
36+
}
37+
2938
type networkInterface struct {
3039
deviceName string
3140
label string
@@ -421,9 +430,15 @@ func resourceVSphereVirtualMachine() *schema.Resource {
421430
Default: "scsi",
422431
ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) {
423432
value := v.(string)
424-
if value != "scsi" && value != "ide" {
433+
found := false
434+
for _, t := range DiskControllerTypes {
435+
if t == value {
436+
found = true
437+
}
438+
}
439+
if !found {
425440
errors = append(errors, fmt.Errorf(
426-
"only 'scsi' and 'ide' are supported values for 'controller_type'"))
441+
"Supported values for 'controller_type' are %v", strings.Join(DiskControllerTypes, ", ")))
427442
}
428443
return
429444
},
@@ -1160,8 +1175,24 @@ func addHardDisk(vm *object.VirtualMachine, size, iops int64, diskType string, d
11601175
log.Printf("[DEBUG] vm devices: %#v\n", devices)
11611176

11621177
var controller types.BaseVirtualController
1163-
controller, err = devices.FindDiskController(controller_type)
1164-
if err != nil {
1178+
switch controller_type {
1179+
case "scsi":
1180+
controller, err = devices.FindDiskController(controller_type)
1181+
case "scsi-lsi-parallel":
1182+
controller = devices.PickController(&types.VirtualLsiLogicController{})
1183+
case "scsi-buslogic":
1184+
controller = devices.PickController(&types.VirtualBusLogicController{})
1185+
case "scsi-paravirtual":
1186+
controller = devices.PickController(&types.ParaVirtualSCSIController{})
1187+
case "scsi-lsi-sas":
1188+
controller = devices.PickController(&types.VirtualLsiLogicSASController{})
1189+
case "ide":
1190+
controller, err = devices.FindDiskController(controller_type)
1191+
default:
1192+
return fmt.Errorf("[ERROR] Unsupported disk controller provided: %v", controller_type)
1193+
}
1194+
1195+
if err != nil || controller == nil {
11651196
log.Printf("[DEBUG] Couldn't find a %v controller. Creating one..", controller_type)
11661197

11671198
var c types.BaseVirtualDevice
@@ -1172,6 +1203,30 @@ func addHardDisk(vm *object.VirtualMachine, size, iops int64, diskType string, d
11721203
if err != nil {
11731204
return fmt.Errorf("[ERROR] Failed creating SCSI controller: %v", err)
11741205
}
1206+
case "scsi-lsi-parallel":
1207+
// Create scsi controller
1208+
c, err = devices.CreateSCSIController("lsilogic")
1209+
if err != nil {
1210+
return fmt.Errorf("[ERROR] Failed creating SCSI controller: %v", err)
1211+
}
1212+
case "scsi-buslogic":
1213+
// Create scsi controller
1214+
c, err = devices.CreateSCSIController("buslogic")
1215+
if err != nil {
1216+
return fmt.Errorf("[ERROR] Failed creating SCSI controller: %v", err)
1217+
}
1218+
case "scsi-paravirtual":
1219+
// Create scsi controller
1220+
c, err = devices.CreateSCSIController("pvscsi")
1221+
if err != nil {
1222+
return fmt.Errorf("[ERROR] Failed creating SCSI controller: %v", err)
1223+
}
1224+
case "scsi-lsi-sas":
1225+
// Create scsi controller
1226+
c, err = devices.CreateSCSIController("lsilogic-sas")
1227+
if err != nil {
1228+
return fmt.Errorf("[ERROR] Failed creating SCSI controller: %v", err)
1229+
}
11751230
case "ide":
11761231
// Create ide controller
11771232
c, err = devices.CreateIDEController()
@@ -1188,10 +1243,10 @@ func addHardDisk(vm *object.VirtualMachine, size, iops int64, diskType string, d
11881243
if err != nil {
11891244
return err
11901245
}
1191-
controller, err = devices.FindDiskController(controller_type)
1192-
if err != nil {
1193-
log.Printf("[ERROR] Could not find the new %v controller: %v", controller_type, err)
1194-
return err
1246+
controller = devices.PickController(c.(types.BaseVirtualController))
1247+
if controller == nil {
1248+
log.Printf("[ERROR] Could not find the new %v controller", controller_type)
1249+
return fmt.Errorf("Could not find the new %v controller", controller_type)
11951250
}
11961251
}
11971252

0 commit comments

Comments
 (0)