'Find mapped ports, memorize them and return unmapped port count.'

def find_targets_from_storage(self, targets, connector, target_ports):

    nr_not_found = 0
    old_target_name = None
    if ('ip' in connector):
        old_target_name = (utils.TARGET_PREFIX + connector['ip'])
    success_code = horcm.HORCM_EXIT_CODE.union([horcm.EX_ENOOBJ])
    wwpns = self.get_hba_ids_from_connector(connector)
    wwpns_pattern = re.compile(('^CL\\w-\\w+    +\\d+    +\\S+    +(%s)    ' % '|'.join(wwpns)), (re.M | re.I))
    target_name = (utils.TARGET_PREFIX + min(wwpns))
    for port in target_ports:
        targets['info'][port] = False
        result = self.run_raidcom('get', 'hba_wwn', '-port', port, target_name, success_code=success_code)
        wwpns = wwpns_pattern.findall(result[1])
        if ((not wwpns) and old_target_name):
            result = self.run_raidcom('get', 'hba_wwn', '-port', port, old_target_name, success_code=success_code)
            wwpns = wwpns_pattern.findall(result[1])
        if wwpns:
            gid = result[1].splitlines()[1].split()[1]
            targets['info'][port] = True
            targets['list'].append((port, gid))
            LOG.debug('Found    wwpns    in    host    group    immediately.    (port:    %(port)s,    gid:    %(gid)s,    wwpns:    %(wwpns)s)', {'port': port, 'gid': gid, 'wwpns': wwpns})
            continue
        result = self.run_raidcom('get', 'host_grp', '-port', port)
        for gid in _HOST_GROUPS_PATTERN.findall(result[1]):
            result = self.run_raidcom('get', 'hba_wwn', '-port', '-'.join([port, gid]))
            wwpns = wwpns_pattern.findall(result[1])
            if wwpns:
                targets['info'][port] = True
                targets['list'].append((port, gid))
                LOG.debug('Found    wwpns    in    host    group.    (port:    %(port)s,    gid:    %(gid)s,    wwpns:    %(wwpns)s)', {'port': port, 'gid': gid, 'wwpns': wwpns})
                break
        else:
            nr_not_found += 1
    return nr_not_found
