vsphere/internal/virtualdevice/virtual_machine_cdrom_subresource.go
func (r *CdromSubresource) Read(l object.VirtualDeviceList) error {
	log.Printf("[DEBUG] %s: Reading state", r)
	d, err := r.FindVirtualDevice(l)
	if err != nil {
		return fmt.Errorf("cannot find disk device: %s", err)
	}
	device, ok := d.(*types.VirtualCdrom)
	if !ok {
		return fmt.Errorf("device at %q is not a virtual CDROM device", l.Name(d))
	}
	// Only read backing info if it's available.
	switch backing := device.Backing.(type) {
	case *types.VirtualCdromRemoteAtapiBackingInfo:
		r.Set("client_device", true)
	case *types.VirtualCdromIsoBackingInfo:
		dp := &object.DatastorePath{}
		if ok := dp.FromString(backing.FileName); !ok {
			return fmt.Errorf("could not read datastore path in backing %q", backing.FileName)
		}
		// If a vApp ISO was inserted, it will be removed if the VM is powered off
		// and cause backing.Datastore to be nil.
		if backing.Datastore != nil {
			r.Set("datastore_id", backing.Datastore.Value)
		}
		r.Set("path", dp.Path)
	default:
		// This is an unsupported entry, so we clear all attributes in the
		// subresource (except for the device address and key, of course).  In
		// addition to making sure correct diffs get created for these kinds of
		// devices, this ensures we don't fail on CDROM device types we don't
		// support right now, such as passthrough devices. We might support these
		// later.
		log.Printf("%s: [DEBUG] Unknown CDROM type %T, clearing all attributes", r, backing)
		r.Set("datastore_id", "")
		r.Set("path", "")
		r.Set("client_device", false)
	}
	// Save the device key and address data
	ctlr, err := findControllerForDevice(l, d)
	if err != nil {
		return err
	}
	if err := r.SaveDevIDs(d, ctlr); err != nil {
		return err
	}
	log.Printf("[DEBUG] %s: Read finished (key and device address may have changed)", r)
	return nil
}
func (r *CdromSubresource) Read(l object.VirtualDeviceList) error {
	log.Printf("[DEBUG] %s: Reading state", r)
	d, err := r.FindVirtualDevice(l)
	if err != nil {
		return fmt.Errorf("cannot find disk device: %s", err)
	}
	device, ok := d.(*types.VirtualCdrom)
	if !ok {
		return fmt.Errorf("device at %q is not a virtual CDROM device", l.Name(d))
	}
	// Only read backing info if it's available.
	switch backing := device.Backing.(type) {
	case *types.VirtualCdromRemoteAtapiBackingInfo:
		r.Set("client_device", true)
	case *types.VirtualCdromIsoBackingInfo:
		dp := &object.DatastorePath{}
		if ok := dp.FromString(backing.FileName); !ok {
			return fmt.Errorf("could not read datastore path in backing %q", backing.FileName)
		}
		// If a vApp ISO was inserted, it will be removed if the VM is powered off
		// and cause backing.Datastore to be nil.
		if backing.Datastore != nil {
			r.Set("datastore_id", backing.Datastore.Value)
		}
		r.Set("path", dp.Path)
	default:
		// This is an unsupported entry, so we clear all attributes in the
		// subresource (except for the device address and key, of course).  In
		// addition to making sure correct diffs get created for these kinds of
		// devices, this ensures we don't fail on CDROM device types we don't
		// support right now, such as passthrough devices. We might support these
		// later.
		log.Printf("%s: [DEBUG] Unknown CDROM type %T, clearing all attributes", r, backing)
		r.Set("datastore_id", "")
		r.Set("path", "")
		r.Set("client_device", false)
	}
	// Save the device key and address data
	ctlr, err := findControllerForDevice(l, d)
	if err != nil {
		return err
	}
	if err := r.SaveDevIDs(d, ctlr); err != nil {
		return err
	}
	log.Printf("[DEBUG] %s: Read finished (key and device address may have changed)", r)
	return nil
}
// Read reads a vsphere_virtual_machine cdrom sub-resource.