'Attach cdrom to VM by reconfiguration.'

def _attach_cdrom_to_vm(self, vm_ref, instance, datastore, file_path):

    client_factory = self._session.vim.client.factory
    devices = self._session._call_method(vutil, 'get_object_property', vm_ref, 'config.hardware.device')
    (controller_key, unit_number, controller_spec) = vm_util.allocate_controller_key_and_unit_number(client_factory, devices, constants.ADAPTER_TYPE_IDE)
    cdrom_attach_config_spec = vm_util.get_cdrom_attach_config_spec(client_factory, datastore, file_path, controller_key, unit_number)
    if controller_spec:
        cdrom_attach_config_spec.deviceChange.append(controller_spec)
    LOG.debug('Reconfiguring    VM    instance    to    attach    cdrom    %s', file_path, instance=instance)
    vm_util.reconfigure_vm(self._session, vm_ref, cdrom_attach_config_spec)
    LOG.debug('Reconfigured    VM    instance    to    attach    cdrom    %s', file_path, instance=instance)
