Skip to content
New issue

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

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

Already on GitHub? # to your account

fix: Update DiskCloneValidateOperation and DiskImportOperation #1629

Merged
merged 2 commits into from
Mar 22, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -794,14 +794,13 @@ func DiskCloneValidateOperation(d *schema.ResourceDiff, c *govmomi.Client, l obj
}
}

// Finally, we don't support non-SCSI (ie: SATA, IDE, NVMe) disks, so kick
// back an error if we see one of those.
// The provider does not support all controllers, return an error if unsupported.
ct, _, _, err := splitDevAddr(r.DevAddr())
if err != nil {
return fmt.Errorf("%s: error parsing device address after reading disk %q: %s", tr.Addr(), targetPath, err)
}
if ct != SubresourceControllerTypeSCSI {
return fmt.Errorf("%s: unsupported controller type %s for disk %q. Please use a template with SCSI disks only", tr.Addr(), ct, targetPath)
if ct != SubresourceControllerTypeSCSI && ct != SubresourceControllerTypeSATA && ct != SubresourceControllerTypeIDE {
return fmt.Errorf("%s: unsupported controller type %s for disk %q", tr.Addr(), ct, targetPath)
}
}
log.Printf("[DEBUG] DiskCloneValidateOperation: All disks in source validated successfully")
Expand Down Expand Up @@ -1060,7 +1059,7 @@ func DiskPostCloneOperation(d *schema.ResourceData, c *govmomi.Client, l object.
// DiskImportOperation validates the disk configuration of the virtual
// machine's VirtualDeviceList to ensure it will be imported properly, and also
// saves device addresses into state for disks defined in config. Both the
// imported device list is sorted by the device's unit number on the SCSI bus.
// imported device list is sorted by the device's unit number on the controller bus.
func DiskImportOperation(d *schema.ResourceData, l object.VirtualDeviceList) error {
log.Printf("[DEBUG] DiskImportOperation: Performing pre-read import and validation of virtual disks")
devices := SelectDisks(l, d.Get("scsi_controller_count").(int), d.Get("sata_controller_count").(int), d.Get("ide_controller_count").(int))
Expand All @@ -1074,8 +1073,8 @@ func DiskImportOperation(d *schema.ResourceData, l object.VirtualDeviceList) err
devices = devSort.Sort
log.Printf("[DEBUG] DiskImportOperation: Disk devices order after sort: %s", DeviceListString(devices))

// Read in the disks. We don't do anything with the results here other than
// validate that the disks are SCSI disks. The read operation validates the rest.
// Read in the disks and validate.
// The provider does not support all controllers, return an error if unsupported.
var curSet []interface{}
log.Printf("[DEBUG] DiskImportOperation: Validating disk type and saving ")
for i, device := range devices {
Expand All @@ -1092,8 +1091,8 @@ func DiskImportOperation(d *schema.ResourceData, l object.VirtualDeviceList) err
if err != nil {
return fmt.Errorf("disk.%d: error parsing device address %s: %s", i, addr, err)
}
if ct != SubresourceControllerTypeSCSI {
return fmt.Errorf("disk.%d: unsupported controller type %s for disk %s. The VM resource supports SCSI disks only", i, ct, addr)
if ct != SubresourceControllerTypeSCSI && ct != SubresourceControllerTypeSATA && ct != SubresourceControllerTypeIDE {
return fmt.Errorf("disk.%d: unsupported controller type %s for disk %s", i, ct, addr)
}
// As one final validation, as we are no longer reading here, validate that
// this is a VMDK-backed virtual disk to make sure we aren't importing RDM
Expand Down