'Driver entry point to attach a volume to an instance.'

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

    LOG.info('Assigning    volume(%(vol)s)    with    initiator(%(initiator)s)', {'vol': volume['name'], 'initiator': connector['initiator']})
    initiator_iqn = connector['initiator']
    vol_rdx_name = self._cinder_id_to_rdx(volume['id'])
    initiator_name = None
    found = False
    for host in self.rdxApi.list_hosts():
        if (host['iscsi_name'] == initiator_iqn):
            LOG.info('initiator    exists    in    Reduxio')
            found = True
            initiator_name = host['name']
            break
    if (not found):
        LOG.info("Initiator    doesn't    exist    in    Reduxio,    Creating    it")
        initiator_name = self._generate_initiator_name()
        self.rdxApi.create_host(name=initiator_name, iscsi_name=initiator_iqn)
    existing_assignment = self.rdxApi.get_single_assignment(vol=vol_rdx_name, host=initiator_name, raise_on_non_exists=False)
    if (existing_assignment is None):
        LOG.info('Creating    assignment')
        self.rdxApi.assign(vol_rdx_name, host_name=initiator_name)
    else:
        LOG.debug('Assignment    already    exists')
    settings = self.rdxApi.get_settings()
    target_iqn = settings['network_configuration']['iscsi_target_iqn']
    target_portal = self._get_target_portal(settings, 1, 1)
    if (existing_assignment is None):
        target_lun = self.rdxApi.get_single_assignment(vol=vol_rdx_name, host=initiator_name)['lun']
    else:
        target_lun = existing_assignment['lun']
    properties = {'driver_volume_type': 'iscsi', 'data': {'target_discovered': False, 'discard': False, 'volume_id': volume['id'], 'target_iqn': target_iqn, 'target_portal': target_portal, 'target_lun': target_lun}}
    connector_multipath = connector.get('multipath', False)
    rdx_multipath = ('iscsi_network2' in settings)
    if (rdx_multipath and connector_multipath):
        target_portal2 = self._get_target_portal(settings, 2, 1)
        target_portal3 = self._get_target_portal(settings, 1, 2)
        target_portal4 = self._get_target_portal(settings, 2, 2)
        properties['data']['target_portals'] = [target_portal, target_portal2, target_portal3, target_portal4]
        properties['data']['target_iqns'] = ([target_iqn] * 4)
        properties['data']['target_luns'] = ([target_lun] * 4)
    LOG.info('Assignment    complete.    Assignment    details:    %s', properties)
    return properties
