'Detach EBS volume identified by blockdevice_id.
:param unicode blockdevice_id: EBS UUID for volume to be detached.
:raises UnknownVolume: If there does not exist a BlockDeviceVolume
corresponding to the input blockdevice_id.
:raises UnattachedVolume: If the BlockDeviceVolume for the
blockdevice_id is not currently \'in-use\'.
:raises VolumeBusy: If the volume\'s attachment state is busy.'

def detach_volume(self, blockdevice_id):

    ebs_volume = self._get_ebs_volume(blockdevice_id)
    if (ebs_volume.state != VolumeStates.IN_USE.value):
        raise UnattachedVolume(blockdevice_id)
    if ebs_volume.attachments:
        attachment_state = ebs_volume.attachments[0]['State']
        if (attachment_state == VOLUME_ATTACHMENT_BUSY):
            logged_attachments = []
            for attachment in ebs_volume.attachments:
                logged_attachments.append(dict(instance_id=attachment['InstanceId'], volume_id=attachment['VolumeId'], device=attachment['Device'], state=attachment['State']))
            VOLUME_BUSY_MESSAGE(volume_id=ebs_volume.id, attachments=logged_attachments).write()
            raise VolumeBusy(ebs_volume)
    self._detach_ebs_volume(blockdevice_id)
    _wait_for_volume_state_change(VolumeOperations.DETACH, ebs_volume)
