def connect(self, raise_on_any_error=False):
        """
        Connect to hosts in hosts list. Returns status of connect as a dict.

        :param raise_on_any_error: Optional Raise an exception even if connecting to one
                                   of the hosts fails.
        :type raise_on_any_error: ``boolean``

        :rtype: ``dict`` of ``str`` to ``dict``
        """
        results = {}

        for host in self._hosts:
            while not concurrency_lib.is_green_pool_free(self._pool):
                concurrency_lib.sleep(self._scan_interval)
            self._pool.spawn(
                self._connect,
                host=host,
                results=results,
                raise_on_any_error=raise_on_any_error,
            )

        concurrency_lib.green_pool_wait_all(self._pool)

        if self._successful_connects < 1:
            # We definitely have to raise an exception in this case.
            LOG.error(
                "Unable to connect to any of the hosts.",
                extra={"connect_results": results},
            )
            msg = (
                "Unable to connect to any one of the hosts: %s.\n\n connect_errors=%s"
                % (
                    self._hosts,
                    json_encode(results, indent=2),
                )
            )
            raise NoHostsConnectedToException(msg)

        return results

        Connect to hosts in hosts list. Returns status of connect as a dict.

        :param raise_on_any_error: Optional Raise an exception even if connecting to one
                                   of the hosts fails.
        :type raise_on_any_error: ``boolean``

        :rtype: ``dict`` of ``str`` to ``dict``
        
st2common/st2common/runners/parallel_ssh.py