'Add attachment metadata.'

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

    context = req.environ['cinder.context']
    volume = self.volume_api.get(context, id)
    instance_uuid = None
    if ('instance_uuid' in body['os-attach']):
        instance_uuid = body['os-attach']['instance_uuid']
    host_name = None
    if ('host_name' in body['os-attach']):
        host_name = body['os-attach']['host_name']
    if ('mountpoint' not in body['os-attach']):
        msg = _("Must    specify    'mountpoint'")
        raise webob.exc.HTTPBadRequest(explanation=msg)
    mountpoint = body['os-attach']['mountpoint']
    if ('mode' in body['os-attach']):
        mode = body['os-attach']['mode']
    else:
        mode = 'rw'
    if ((instance_uuid is None) and (host_name is None)):
        msg = _('Invalid    request    to    attach    volume    to    an    invalid    target')
        raise webob.exc.HTTPBadRequest(explanation=msg)
    if (mode not in ('rw', 'ro')):
        msg = _("Invalid    request    to    attach    volume    with    an    invalid    mode.    Attaching    mode    should    be    'rw'    or    'ro'")
        raise webob.exc.HTTPBadRequest(explanation=msg)
    try:
        self.volume_api.attach(context, volume, instance_uuid, host_name, mountpoint, mode)
    except messaging.RemoteError as error:
        if (error.exc_type in ['InvalidVolume', 'InvalidUUID', 'InvalidVolumeAttachMode']):
            msg = (_('Error    attaching    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)
