'Initialize connection to instance.
Maps the created volume to the nova volume node,
and returns the iSCSI target to be used in the instance'

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

    connection_type = self._get_connection_type()
    LOG.debug('initialize_connection:    %(volume)s    %(connector)s    connection_type:    %(connection_type)s', {'volume': volume['name'], 'connector': connector, 'connection_type': connection_type})
    (fc_targets, host) = self._get_host_and_fc_targets(volume, connector)
    lun_id = self._vol_map_and_get_lun_id(volume, connector, host)
    meta = {'driver_volume_type': connection_type, 'data': {'target_discovered': True, 'target_lun': lun_id, 'volume_id': volume['id']}}
    if (connection_type == storage.XIV_CONNECTION_TYPE_ISCSI):
        meta['data']['target_portal'] = self.meta['ibm_storage_portal']
        meta['data']['target_iqn'] = self.meta['ibm_storage_iqn']
        meta['data']['provider_location'] = ('%s,1    %s    %s' % (self.meta['ibm_storage_portal'], self.meta['ibm_storage_iqn'], lun_id))
        chap_type = self._get_chap_type()
        LOG.debug('initialize_connection:    %(volume)s.    chap_type:%(chap_type)s', {'volume': volume['name'], 'chap_type': chap_type})
        if (chap_type == storage.CHAP_ENABLED):
            chap = self._create_chap(host)
            meta['data']['auth_method'] = 'CHAP'
            meta['data']['auth_username'] = chap[0]
            meta['data']['auth_password'] = chap[1]
    else:
        all_storage_wwpns = self._get_fc_targets(None)
        meta['data']['all_storage_wwpns'] = all_storage_wwpns
        modules = set()
        for wwpn in fc_targets:
            modules.add(wwpn[(-2)])
        meta['data']['recommended_connections'] = (len(modules) * CONNECTIONS_PER_MODULE)
        meta['data']['target_wwn'] = fc_targets
        if (fc_targets == []):
            fc_targets = all_storage_wwpns
        meta['data']['initiator_target_map'] = self._build_initiator_target_map(fc_targets, connector)
    LOG.debug(six.text_type(meta))
    return meta
