'Allow connection to connector and return connection info.'

@fczm_utils.add_fc_zone
def initialize_connection(self, volume, connector):

    "\n                                                connector    =    {'ip':    CONF.my_ip,\n                                                                                                    'host':    CONF.host,\n                                                                                                    'initiator':    self._initiator,\n                                                                                                    'wwnns':    self._fc_wwnns,\n                                                                                                    'wwpns':    self._fc_wwpns}\n\n                                "
    dc_fc = {}
    dc_target = {}
    lsTargetWwpn = []
    output = None
    properties = {}
    preferTargets = {}
    ret = 0
    targetIdentifier = []
    szwwpns = []
    LOG.info('initialize_connection    volume:    %(volume)s,    connector:    %(connector)s', {'volume': volume, 'connector': connector})
    dc_fc = self._get_fc_channel()
    dc_target = self._get_targets()
    if (len(dc_target) == 0):
        msg = _('Backend    storage    did    not    configure    fiber    channel    target.')
        raise exception.VolumeBackendAPIException(data=msg)
    for keyFc in dc_fc.keys():
        for targetuuid in dc_target.keys():
            if (dc_fc[keyFc]['hardware_address'] == dc_target[targetuuid]['targetAddr']):
                preferTargets[targetuuid] = dc_target[targetuuid]
                break
    for dwwpn in connector['wwpns']:
        szwwpn = self._convertHex2String(dwwpn)
        if (len(szwwpn) == 0):
            msg = (_('Invalid    wwpns    format    %(wwpns)s') % {'wwpns': connector['wwpns']})
            raise exception.VolumeBackendAPIException(data=msg)
        szwwpns.append(szwwpn)
    if len(szwwpns):
        for targetUuid in preferTargets.keys():
            targetWwpn = ''
            targetWwpn = preferTargets.get(targetUuid, {}).get('targetAddr', '')
            lsTargetWwpn.append(targetWwpn)
    LOG.info('Prefer    use    target    wwpn    %(wwpn)s', {'wwpn': lsTargetWwpn})
    assignedTarget = []
    for pTarget in lsTargetWwpn:
        try:
            ret = self._export_fc(volume['id'], str(pTarget), szwwpns, volume['name'])
            if ret:
                break
            else:
                assignedTarget.append(pTarget)
        except Exception as e:
            LOG.error('Failed    to    export    fiber    channel    target    due    to    %s', e)
            ret = errno.EFAULT
            break
    if (ret == 0):
        (ret, output) = self.dpl.get_vdev(self._conver_uuid2hex(volume['id']))
    nLun = (-1)
    if (ret == 0):
        try:
            for p in output['exports']['Network/FC']:
                for initI in p.get('permissions', []):
                    for szwpn in szwwpns:
                        if initI.get(szwpn, None):
                            nLun = initI[szwpn]
                            break
                    if (nLun != (-1)):
                        break
                if (nLun != (-1)):
                    targetIdentifier.append(str(p['target_identifier']).replace(':', ''))
        except Exception:
            msg = (_('Invalid    connection    initialization    response    of    volume    %(name)s:    %(output)s') % {'name': volume['name'], 'output': output})
            raise exception.VolumeBackendAPIException(data=msg)
    if (nLun != (-1)):
        init_targ_map = self._build_initiator_target_map(connector, targetIdentifier)
        properties['target_discovered'] = True
        properties['target_wwn'] = targetIdentifier
        properties['target_lun'] = int(nLun)
        properties['volume_id'] = volume['id']
        properties['initiator_target_map'] = init_targ_map
        LOG.info('%(volume)s    assign    type    fibre_channel,    properties    %(properties)s', {'volume': volume['id'], 'properties': properties})
    else:
        msg = (_('Invalid    connection    initialization    response    of    volume    %(name)s') % {'name': volume['name']})
        raise exception.VolumeBackendAPIException(data=msg)
    LOG.info('Connect    initialization    info:    {driver_volume_type:    fibre_channel,    data:    %(properties)s', {'properties': properties})
    return {'driver_volume_type': 'fibre_channel', 'data': properties}
