code: def connect(self, keyspace=None, wait_for_all_pools=False):
          
          with self._lock:
              if self.is_shutdown:
                  raise DriverException("Cluster is already shut down")
  
              if not self._is_setup:
                  log.debug("Connecting to cluster, contact points: %s; protocol version: %s",
                            self.contact_points, self.protocol_version)
                  self.connection_class.initialize_reactor()
                  _register_cluster_shutdown(self)
                  for endpoint in self.endpoints_resolved:
                      host, new = self.add_host(endpoint, signal=False)
                      if new:
                          host.set_up()
                          for listener in self.listeners:
                              listener.on_add(host)
  
                  self.profile_manager.populate(
                      weakref.proxy(self), self.metadata.all_hosts())
                  self.load_balancing_policy.populate(
                      weakref.proxy(self), self.metadata.all_hosts()
                  )
  
                  try:
                      self.control_connection.connect()
  
                      # we set all contact points up for connecting, but we won't infer state after this
                      for endpoint in self.endpoints_resolved:
                          h = self.metadata.get_host(endpoint)
                          if h and self.profile_manager.distance(h) == HostDistance.IGNORED:
                              h.is_up = None
  
                      log.debug("Control connection created")
                  except Exception:
                      log.exception("Control connection failed to connect, "
                                    "shutting down Cluster:")
                      self.shutdown()
                      raise
  
                  self.profile_manager.check_supported()  # todo: rename this method
  
                  if self.idle_heartbeat_interval:
                      self._idle_heartbeat = ConnectionHeartbeat(
                          self.idle_heartbeat_interval,
                          self.get_connection_holders,
                          timeout=self.idle_heartbeat_timeout
                      )
                  self._is_setup = True
  
          session = self._new_session(keyspace)
          if wait_for_all_pools:
              wait_futures(session._initial_connect_futures)
          return session
docs: Creates and returns a new :class:`~.Session` object.  If `keyspace`
          is specified, that keyspace will be the default keyspace for
          operations on the ``Session``.