vsphere/internal/virtualdevice/virtual_machine_cdrom_subresource.go
func (r *CdromSubresource) mapCdrom(device *types.VirtualCdrom, l object.VirtualDeviceList) error {
	dsID := r.Get("datastore_id").(string)
	path := r.Get("path").(string)
	clientDevice := r.Get("client_device").(bool)
	switch {
	case dsID != "" && path != "":
		// If the datastore ID and path are both set, the CDROM will be mapped to a file on a datastore.
		ds, err := datastore.FromID(r.client, dsID)
		if err != nil {
			return fmt.Errorf("cannot find datastore: %s", err)
		}
		dsProps, err := datastore.Properties(ds)
		if err != nil {
			return fmt.Errorf("could not get properties for datastore: %s", err)
		}
		dsName := dsProps.Name
		dsPath := &object.DatastorePath{
			Datastore: dsName,
			Path:      path,
		}
		device = l.InsertIso(device, dsPath.String())
		l.Connect(device)
		return nil
	case clientDevice == true:
		// If set to use the client device, then the CDROM will be mapped to a remote device.
		device.Backing = &types.VirtualCdromRemoteAtapiBackingInfo{
			VirtualDeviceRemoteDeviceBackingInfo: types.VirtualDeviceRemoteDeviceBackingInfo{},
		}
		return nil
	}
	panic(fmt.Sprintf("%s: no CDROM types specified", r))
}
func (r *CdromSubresource) mapCdrom(device *types.VirtualCdrom, l object.VirtualDeviceList) error {
	dsID := r.Get("datastore_id").(string)
	path := r.Get("path").(string)
	clientDevice := r.Get("client_device").(bool)
	switch {
	case dsID != "" && path != "":
		// If the datastore ID and path are both set, the CDROM will be mapped to a file on a datastore.
		ds, err := datastore.FromID(r.client, dsID)
		if err != nil {
			return fmt.Errorf("cannot find datastore: %s", err)
		}
		dsProps, err := datastore.Properties(ds)
		if err != nil {
			return fmt.Errorf("could not get properties for datastore: %s", err)
		}
		dsName := dsProps.Name
		dsPath := &object.DatastorePath{
			Datastore: dsName,
			Path:      path,
		}
		device = l.InsertIso(device, dsPath.String())
		l.Connect(device)
		return nil
	case clientDevice == true:
		// If set to use the client device, then the CDROM will be mapped to a remote device.
		device.Backing = &types.VirtualCdromRemoteAtapiBackingInfo{
			VirtualDeviceRemoteDeviceBackingInfo: types.VirtualDeviceRemoteDeviceBackingInfo{},
		}
		return nil
	}
	panic(fmt.Sprintf("%s: no CDROM types specified", r))
}
// mapCdrom takes a CdromSubresource and attaches either a client device or a datastore ISO.