'Delete map between a volume and a host.'

@fczm_utils.remove_fc_zone
@coordination.synchronized('huawei-mapping-{connector[host]}')
def terminate_connection(self, volume, connector, **kwargs):

    (lun_id, lun_type) = self.get_lun_id_and_type(volume)
    wwns = connector['wwpns']
    host_name = connector['host']
    left_lunnum = (-1)
    lungroup_id = None
    view_id = None
    LOG.info('terminate_connection:    wwpns:    %(wwns)s,    LUN    ID:    %(lun_id)s.', {'wwns': wwns, 'lun_id': lun_id})
    host_id = huawei_utils.get_host_id(self.client, host_name)
    if host_id:
        mapping_view_name = (constants.MAPPING_VIEW_PREFIX + host_id)
        view_id = self.client.find_mapping_view(mapping_view_name)
        if view_id:
            lungroup_id = self.client.find_lungroup_from_map(view_id)
    if (lun_id and lungroup_id):
        lungroup_ids = self.client.get_lungroupids_by_lunid(lun_id, lun_type)
        if (lungroup_id in lungroup_ids):
            self.client.remove_lun_from_lungroup(lungroup_id, lun_id, lun_type)
        else:
            LOG.warning('LUN    is    not    in    lungroup.    LUN    ID:    %(lun_id)s.    Lungroup    id:    %(lungroup_id)s.', {'lun_id': lun_id, 'lungroup_id': lungroup_id})
    else:
        LOG.warning("Can't    find    lun    on    the    array.")
    if lungroup_id:
        left_lunnum = self.client.get_obj_count_from_lungroup(lungroup_id)
    if (int(left_lunnum) > 0):
        fc_info = {'driver_volume_type': 'fibre_channel', 'data': {}}
    else:
        (fc_info, portg_id) = self._delete_zone_and_remove_fc_initiators(wwns, host_id)
        if lungroup_id:
            if (view_id and self.client.lungroup_associated(view_id, lungroup_id)):
                self.client.delete_lungroup_mapping_view(view_id, lungroup_id)
            self.client.delete_lungroup(lungroup_id)
        if portg_id:
            if (view_id and self.client.is_portgroup_associated_to_view(view_id, portg_id)):
                self.client.delete_portgroup_mapping_view(view_id, portg_id)
                self.client.delete_portgroup(portg_id)
        if host_id:
            hostgroup_name = (constants.HOSTGROUP_PREFIX + host_id)
            hostgroup_id = self.client.find_hostgroup(hostgroup_name)
            if hostgroup_id:
                if (view_id and self.client.hostgroup_associated(view_id, hostgroup_id)):
                    self.client.delete_hostgoup_mapping_view(view_id, hostgroup_id)
                self.client.remove_host_from_hostgroup(hostgroup_id, host_id)
                self.client.delete_hostgroup(hostgroup_id)
            if (not self.client.check_fc_initiators_exist_in_host(host_id)):
                self.client.remove_host(host_id)
        if view_id:
            self.client.delete_mapping_view(view_id)
    metadata = huawei_utils.get_lun_metadata(volume)
    LOG.info('Detach    Volume,    metadata    is:    %s.', metadata)
    if ('hypermetro_id' in metadata):
        hyperm = hypermetro.HuaweiHyperMetro(self.client, self.rmt_client, self.configuration)
        hyperm.disconnect_volume_fc(volume, connector)
    LOG.info('terminate_connection,    return    data    is:    %s.', fc_info)
    return fc_info
