'Terminate connection.
Unmaps volume. If this is the last connection from the host, undefines
the host from the storage.'

@proxy._trace_time
def terminate_connection(self, volume, connector):

    LOG.debug('terminate_connection:    %(volume)s    %(connector)s', {'volume': volume['name'], 'connector': connector})
    host = self._get_host(connector)
    if (host is None):
        LOG.error(TERMINATE_CONNECTION_BASE_ERROR, {'volume': volume['name'], 'error': 'Host    not    found.'})
        return
    fc_targets = {}
    if (self._get_connection_type() == storage.XIV_CONNECTION_TYPE_FC):
        fc_targets = self._get_fc_targets(host)
    try:
        self._call_xiv_xcli('unmap_vol', vol=volume['name'], host=host.get('name'))
    except errors.VolumeBadNameError:
        LOG.error(TERMINATE_CONNECTION_BASE_ERROR, {'volume': volume['name'], 'error': 'Volume    not    found.'})
    except errors.XCLIError as err:
        details = self._get_code_and_status_or_message(err)
        LOG.error(TERMINATE_CONNECTION_BASE_ERROR, {'volume': volume['name'], 'error': details})
    host_mappings = []
    try:
        host_mappings = self._call_xiv_xcli('mapping_list', host=host.get('name')).as_list
        if (len(host_mappings) == 0):
            LOG.info("Terminate    connection    for    volume    '%(volume)s':    %(host)s    %(info)s.", {'volume': volume['name'], 'host': host.get('name'), 'info': 'will    be    deleted'})
            if (not self._is_iscsi()):
                meta = {'driver_volume_type': self._get_connection_type(), 'data': {'volume_id': volume['id']}}
                meta['data']['target_wwn'] = fc_targets
                meta['data']['initiator_target_map'] = self._build_initiator_target_map(fc_targets, connector)
            self._call_xiv_xcli('host_delete', host=host.get('name'))
            if (not self._is_iscsi()):
                return meta
            return None
        else:
            LOG.debug("Host    '%(host)s'    has    additional    mapped    volumes    %(mappings)s", {'host': host.get('name'), 'mappings': host_mappings})
    except errors.HostBadNameError:
        LOG.error(TERMINATE_CONNECTION_HOST_ERROR, {'volume': volume['name'], 'host': host.get('name'), 'error': 'Host    not    found.'})
    except errors.XCLIError as err:
        details = self._get_code_and_status_or_message(err)
        LOG.error(TERMINATE_CONNECTION_HOST_ERROR, {'volume': volume['name'], 'host': host.get('name'), 'error': details})
