'unmap volume from host.'

@lockutils.synchronized('ETERNUS-connect', 'cinder-', True)
def _unmap_lun(self, volume, connector, force=False):

    LOG.debug('_map_lun,    volume    id:    %(vid)s,    connector:    %(connector)s,    force:    %(frc)s.', {'vid': volume['id'], 'connector': connector, 'frc': force})
    volumename = self._create_volume_name(volume['id'])
    vol_instance = self._find_lun(volume)
    if (vol_instance is None):
        LOG.info('_unmap_lun,    volumename:%(volumename)s,    volume    not    found.', {'volumename': volumename})
        return False
    volume_uid = vol_instance['Name']
    if (not force):
        aglist = self._find_affinity_group(connector, vol_instance)
        if (not aglist):
            LOG.info('_unmap_lun,    volumename:    %(volumename)s,    volume    is    not    mapped.', {'volumename': volumename})
            return False
    else:
        try:
            aglist = self._assoc_eternus_names(vol_instance.path, AssocClass='CIM_ProtocolControllerForUnit', ResultClass='FUJITSU_AffinityGroupController')
        except Exception:
            msg = (_('_unmap_lun,vol_instance.path:    %(volume)s,    AssociatorNames:    CIM_ProtocolControllerForUnit,    cannot    connect    to    ETERNUS.') % {'volume': vol_instance.path})
            LOG.error(msg)
            raise exception.VolumeBackendAPIException(data=msg)
        LOG.debug('_unmap_lun,    vol_instance.path:    %(volume)s,    affinity_groups:    %(aglist)s.', {'volume': vol_instance.path, 'aglist': aglist})
    configservice = self._find_eternus_service(CTRL_CONF)
    if (configservice is None):
        msg = (_('_unmap_lun,    vol_instance.path:    %(volume)s,    volumename:    %(volumename)s,    volume_uid:    %(uid)s,    aglist:    %(aglist)s,    Controller    Configuration    Service    not    found.') % {'vol': vol_instance.path, 'volumename': [volumename], 'uid': [volume_uid], 'aglist': aglist})
        LOG.error(msg)
        raise exception.VolumeBackendAPIException(data=msg)
    for ag in aglist:
        LOG.debug('_unmap_lun,    volumename:    %(volumename)s,    volume_uid:    %(volume_uid)s,    AffinityGroup:    %(ag)s.', {'volumename': volumename, 'volume_uid': volume_uid, 'ag': ag})
        (rc, errordesc, job) = self._exec_eternus_service('HidePaths', configservice, LUNames=[volume_uid], ProtocolControllers=[ag])
        LOG.debug('_unmap_lun,    Error:    %(errordesc)s,    Return    code:    %(rc)lu.', {'errordesc': errordesc, 'rc': rc})
        if (rc == LUNAME_NOT_EXIST):
            LOG.debug('_unmap_lun,    volumename:    %(volumename)s,    Invalid    LUNames.', {'volumename': volumename})
        elif (rc != 0):
            msg = (_('_unmap_lun,    volumename:    %(volumename)s,    volume_uid:    %(volume_uid)s,    AffinityGroup:    %(ag)s,    Return    code:    %(rc)lu,    Error:    %(errordesc)s.') % {'volumename': volumename, 'volume_uid': volume_uid, 'ag': ag, 'rc': rc, 'errordesc': errordesc})
            LOG.error(msg)
            raise exception.VolumeBackendAPIException(data=msg)
    LOG.debug('_unmap_lun,    volumename:    %(volumename)s.', {'volumename': volumename})
    return True
