Detach an EBS volume from an EC2 instance.

    .. versionadded:: 2016.11.0

    volume_id
        (string) – The ID of the EBS volume to be detached.
    instance_id
        (string) – The ID of the EC2 instance from which it will be detached.
    device
        (string) – The device on the instance through which the volume is exposted (e.g. /dev/sdh)
    force
        (bool) – Forces detachment if the previous detachment attempt did not occur cleanly.
                 This option can lead to data loss or a corrupted file system. Use this option
                 only as a last resort to detach a volume from a failed instance. The instance
                 will not have an opportunity to flush file system caches nor file system meta data.
                 If you use this option, you must perform file system check and repair procedures.
    wait_for_detachement
       (bool) - Whether or not to wait for volume detachement to complete.

    returns
        (bool) - True on success, False on failure.

    CLI Example:

    .. code-block:: bash

        salt-call boto_ec2.detach_volume vol-12345678 i-87654321

def detach_volume(volume_id, instance_id=None, device=None, force=False,
                  wait_for_detachement=False, region=None, key=None, keyid=None, profile=None):
    '''
    Detach an EBS volume from an EC2 instance.

    .. versionadded:: 2016.11.0

    volume_id
        (string) – The ID of the EBS volume to be detached.
    instance_id
        (string) – The ID of the EC2 instance from which it will be detached.
    device
        (string) – The device on the instance through which the volume is exposted (e.g. /dev/sdh)
    force
        (bool) – Forces detachment if the previous detachment attempt did not occur cleanly.
                 This option can lead to data loss or a corrupted file system. Use this option
                 only as a last resort to detach a volume from a failed instance. The instance
                 will not have an opportunity to flush file system caches nor file system meta data.
                 If you use this option, you must perform file system check and repair procedures.
    wait_for_detachement
       (bool) - Whether or not to wait for volume detachement to complete.

    returns
        (bool) - True on success, False on failure.

    CLI Example:

    .. code-block:: bash

        salt-call boto_ec2.detach_volume vol-12345678 i-87654321

    '''
    conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
    try:
        ret = conn.detach_volume(volume_id, instance_id, device, force)
        if ret and wait_for_detachement and not _wait_for_volume_available(conn, volume_id):
            timeout_msg = 'Timed out waiting for the volume status "available".'
            log.error(timeout_msg)
            return False
        return ret
    except boto.exception.BotoServerError as e:
        log.error(e)
        return False