'Initialize volume attachment.'

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

    context = req.environ['cinder.context']
    volume = self.volume_api.get(context, id)
    try:
        connector = body['os-initialize_connection']['connector']
    except KeyError:
        raise webob.exc.HTTPBadRequest(explanation=_("Must    specify    'connector'"))
    try:
        info = self.volume_api.initialize_connection(context, volume, connector)
    except exception.InvalidInput as err:
        raise webob.exc.HTTPBadRequest(explanation=err.msg)
    except exception.VolumeBackendAPIException:
        msg = _('Unable    to    fetch    connection    information    from    backend.')
        raise webob.exc.HTTPInternalServerError(explanation=msg)
    except messaging.RemoteError as error:
        if (error.exc_type == 'InvalidInput'):
            raise exception.InvalidInput(reason=error.value)
        raise
    return {'connection_info': info}
