'Updates db to show volume is attached.'

@coordination.synchronized('{volume_id}')
def attach_volume(self, context, volume_id, instance_uuid, host_name, mountpoint, mode, volume=None):

    if (volume is None):
        volume = objects.Volume.get_by_id(context, volume_id)
    with volume.obj_as_admin():
        volume_metadata = volume.admin_metadata
    if (volume.status == 'attaching'):
        if (volume_metadata.get('attached_mode') and (volume_metadata.get('attached_mode') != mode)):
            raise exception.InvalidVolume(reason=_('being    attached    by    different    mode'))
    host_name_sanitized = (utils.sanitize_hostname(host_name) if host_name else None)
    if instance_uuid:
        attachments = VA_LIST.get_all_by_instance_uuid(context, instance_uuid)
    else:
        attachments = VA_LIST.get_all_by_host(context, host_name_sanitized)
    if attachments:
        for attachment in attachments:
            if (attachment['volume_id'] == volume_id):
                volume.status = 'in-use'
                volume.save()
                return attachment
    if ((volume.status == 'in-use') and (not volume.multiattach) and (not volume.migration_status)):
        raise exception.InvalidVolume(reason=_('volume    is    already    attached'))
    self._notify_about_volume_usage(context, volume, 'attach.start')
    attachment = volume.begin_attach(mode)
    if (instance_uuid and (not uuidutils.is_uuid_like(instance_uuid))):
        attachment.attach_status = fields.VolumeAttachStatus.ERROR_ATTACHING
        attachment.save()
        raise exception.InvalidUUID(uuid=instance_uuid)
    try:
        if ((volume_metadata.get('readonly') == 'True') and (mode != 'ro')):
            raise exception.InvalidVolumeAttachMode(mode=mode, volume_id=volume.id)
        utils.require_driver_initialized(self.driver)
        LOG.info('Attaching    volume    %(volume_id)s    to    instance    %(instance)s    at    mountpoint    %(mount)s    on    host    %(host)s.', {'volume_id': volume_id, 'instance': instance_uuid, 'mount': mountpoint, 'host': host_name_sanitized}, resource=volume)
        self.driver.attach_volume(context, volume, instance_uuid, host_name_sanitized, mountpoint)
    except Exception as excep:
        with excutils.save_and_reraise_exception():
            self.message_api.create(context, message_field.Action.ATTACH_VOLUME, resource_uuid=volume_id, exception=excep)
            attachment.attach_status = fields.VolumeAttachStatus.ERROR_ATTACHING
            attachment.save()
    volume = attachment.finish_attach(instance_uuid, host_name_sanitized, mountpoint, mode)
    self._notify_about_volume_usage(context, volume, 'attach.end')
    LOG.info('Attach    volume    completed    successfully.', resource=volume)
    return attachment
