Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional SCSI controller types support #7525

Merged
merged 1 commit into from
Jul 12, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 63 additions & 8 deletions builtin/providers/vsphere/resource_vsphere_virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ var DefaultDNSServers = []string{
"8.8.4.4",
}

var DiskControllerTypes = []string{
"scsi",
"scsi-lsi-parallel",
"scsi-buslogic",
"scsi-paravirtual",
"scsi-lsi-sas",
"ide",
}

type networkInterface struct {
deviceName string
label string
Expand Down Expand Up @@ -421,9 +430,15 @@ func resourceVSphereVirtualMachine() *schema.Resource {
Default: "scsi",
ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) {
value := v.(string)
if value != "scsi" && value != "ide" {
found := false
for _, t := range DiskControllerTypes {
if t == value {
found = true
}
}
if !found {
errors = append(errors, fmt.Errorf(
"only 'scsi' and 'ide' are supported values for 'controller_type'"))
"Supported values for 'controller_type' are %v", strings.Join(DiskControllerTypes, ", ")))
}
return
},
Expand Down Expand Up @@ -1135,8 +1150,24 @@ func addHardDisk(vm *object.VirtualMachine, size, iops int64, diskType string, d
log.Printf("[DEBUG] vm devices: %#v\n", devices)

var controller types.BaseVirtualController
controller, err = devices.FindDiskController(controller_type)
if err != nil {
switch controller_type {
case "scsi":
controller, err = devices.FindDiskController(controller_type)
case "scsi-lsi-parallel":
controller = devices.PickController(&types.VirtualLsiLogicController{})
case "scsi-buslogic":
controller = devices.PickController(&types.VirtualBusLogicController{})
case "scsi-paravirtual":
controller = devices.PickController(&types.ParaVirtualSCSIController{})
case "scsi-lsi-sas":
controller = devices.PickController(&types.VirtualLsiLogicSASController{})
case "ide":
controller, err = devices.FindDiskController(controller_type)
default:
return fmt.Errorf("[ERROR] Unsupported disk controller provided: %v", controller_type)
}

if err != nil || controller == nil {
log.Printf("[DEBUG] Couldn't find a %v controller. Creating one..", controller_type)

var c types.BaseVirtualDevice
Expand All @@ -1147,6 +1178,30 @@ func addHardDisk(vm *object.VirtualMachine, size, iops int64, diskType string, d
if err != nil {
return fmt.Errorf("[ERROR] Failed creating SCSI controller: %v", err)
}
case "scsi-lsi-parallel":
// Create scsi controller
c, err = devices.CreateSCSIController("lsilogic")
if err != nil {
return fmt.Errorf("[ERROR] Failed creating SCSI controller: %v", err)
}
case "scsi-buslogic":
// Create scsi controller
c, err = devices.CreateSCSIController("buslogic")
if err != nil {
return fmt.Errorf("[ERROR] Failed creating SCSI controller: %v", err)
}
case "scsi-paravirtual":
// Create scsi controller
c, err = devices.CreateSCSIController("pvscsi")
if err != nil {
return fmt.Errorf("[ERROR] Failed creating SCSI controller: %v", err)
}
case "scsi-lsi-sas":
// Create scsi controller
c, err = devices.CreateSCSIController("lsilogic-sas")
if err != nil {
return fmt.Errorf("[ERROR] Failed creating SCSI controller: %v", err)
}
case "ide":
// Create ide controller
c, err = devices.CreateIDEController()
Expand All @@ -1163,10 +1218,10 @@ func addHardDisk(vm *object.VirtualMachine, size, iops int64, diskType string, d
if err != nil {
return err
}
controller, err = devices.FindDiskController(controller_type)
if err != nil {
log.Printf("[ERROR] Could not find the new %v controller: %v", controller_type, err)
return err
controller = devices.PickController(c.(types.BaseVirtualController))
if controller == nil {
log.Printf("[ERROR] Could not find the new %v controller", controller_type)
return fmt.Errorf("Could not find the new %v controller", controller_type)
}
}

Expand Down