'Driver entry point to setup a connection for a volume.'

@utils.trace
def initialize_connection(self, volume, connector):

    lcfg = self.configuration
    init_groups = self.zfssa.get_initiator_initiatorgroup(connector['initiator'])
    if (not init_groups):
        if (lcfg.zfssa_initiator_group == 'default'):
            init_groups.append('default')
        else:
            exception_msg = (_('Failed    to    find    iSCSI    initiator    group    containing    %(initiator)s.') % {'initiator': connector['initiator']})
            LOG.error(exception_msg)
            raise exception.VolumeBackendAPIException(data=exception_msg)
    if ((lcfg.zfssa_enable_local_cache is True) and volume['name'].startswith('os-cache-vol-')):
        project = lcfg.zfssa_cache_project
    else:
        project = lcfg.zfssa_project
    lun = self.zfssa.get_lun(lcfg.zfssa_pool, project, volume['name'])
    new_init_groups = set((lun['initiatorgroup'] + init_groups))
    self.zfssa.set_lun_initiatorgroup(lcfg.zfssa_pool, project, volume['name'], sorted(list(new_init_groups)))
    iscsi_properties = {}
    provider = self._get_provider_info()
    (target_portal, target_iqn) = provider['provider_location'].split()
    iscsi_properties['target_discovered'] = False
    iscsi_properties['target_portal'] = target_portal
    iscsi_properties['target_iqn'] = target_iqn
    lun = self.zfssa.get_lun(lcfg.zfssa_pool, project, volume['name'])
    lu_map = dict(zip(lun['initiatorgroup'], lun['number']))
    iscsi_properties['target_lun'] = int(lu_map[init_groups[0]])
    iscsi_properties['volume_id'] = volume['id']
    if ('provider_auth' in provider):
        (auth_method, auth_username, auth_password) = provider['provider_auth'].split()
        iscsi_properties['auth_method'] = auth_method
        iscsi_properties['auth_username'] = auth_username
        iscsi_properties['auth_password'] = auth_password
    return {'driver_volume_type': 'iscsi', 'data': iscsi_properties}
