'Clear attachment metadata.'

@wsgi.action('os-detach')
def _detach(self, req, id, body):

    context = req.environ['cinder.context']
    volume = self.volume_api.get(context, id)
    attachment_id = None
    if body['os-detach']:
        attachment_id = body['os-detach'].get('attachment_id', None)
    try:
        self.volume_api.detach(context, volume, attachment_id)
    except messaging.RemoteError as error:
        if (error.exc_type in ['VolumeAttachmentNotFound', 'InvalidVolume']):
            msg = (_('Error    detaching    volume    -    %(err_type)s:    %(err_msg)s') % {'err_type': error.exc_type, 'err_msg': error.value})
            raise webob.exc.HTTPBadRequest(explanation=msg)
        else:
            raise
    return webob.Response(status_int=http_client.ACCEPTED)
