def _create_session(self, node, keyspace, user, password, compression, protocol_version, port=None, ssl_opts=None, execution_profiles=None, **kwargs): node_ip = get_ip_from_node(node) if not port: port = get_port_from_node(node) if protocol_version is None: protocol_version = get_eager_protocol_version(node.cluster.version()) if user is not None: auth_provider = get_auth_provider(user=user, password=password) else: auth_provider = None profiles = {EXEC_PROFILE_DEFAULT: make_execution_profile(**kwargs) } if not execution_profiles else execution_profiles cluster = PyCluster([node_ip], auth_provider=auth_provider, compression=compression, protocol_version=protocol_version, port=port, ssl_options=ssl_opts, connect_timeout=15, allow_beta_protocol_version=True, execution_profiles=profiles) session = cluster.connect(wait_for_all_pools=True) if keyspace is not None: session.set_keyspace(keyspace) self.connections.append(session) return session
def exclusive_cql_connection(self, node, keyspace=None, version=None, user=None, password=None, compression=True, protocol_version=None): node_ip = self.get_ip_from_node(node) if protocol_version is None: if self.cluster.version() >= '2.1': protocol_version = 3 elif self.cluster.version() >= '2.0': protocol_version = 2 else: protocol_version = 1 wlrr = WhiteListRoundRobinPolicy([node_ip]) if user is None: cluster = PyCluster([node_ip], compression=compression, protocol_version=protocol_version, load_balancing_policy=wlrr) else: auth_provider = self.get_auth_provider(user=user, password=password) cluster = PyCluster([node_ip], auth_provider=auth_provider, compression=compression, protocol_version=protocol_version, load_balancing_policy=wlrr) session = cluster.connect() if keyspace is not None: session.execute('USE %s' % keyspace) self.connections.append(session) return session
def cql_connection(self, node, keyspace=None, version=None, user=None, password=None, compression=True, protocol_version=None): node_ip = self.get_ip_from_node(node) if protocol_version is None: if self.cluster.version() >= '2.1': protocol_version = 3 elif self.cluster.version() >= '2.0': protocol_version = 2 else: protocol_version = 1 if user is None: cluster = PyCluster([node_ip], compression=compression, protocol_version=protocol_version) else: auth_provider = self.get_auth_provider(user=user, password=password) cluster = PyCluster([node_ip], auth_provider=auth_provider, compression=compression, protocol_version=protocol_version) session = cluster.connect() if keyspace is not None: session.execute('USE %s' % keyspace) self.connections.append(session) return session
def _create_session(self, node, keyspace, user, password, compression, protocol_version, load_balancing_policy=None, port=None, ssl_opts=None): node_ip = self.get_ip_from_node(node) if not port: port = self.get_port_from_node(node) if protocol_version is None: protocol_version = self.get_eager_protocol_version( self.cluster.version()) if user is not None: auth_provider = self.get_auth_provider(user=user, password=password) else: auth_provider = None cluster = PyCluster([node_ip], auth_provider=auth_provider, compression=compression, protocol_version=protocol_version, load_balancing_policy=load_balancing_policy, default_retry_policy=FlakyRetryPolicy(), port=port, ssl_options=ssl_opts, connect_timeout=10, allow_beta_protocol_version=True) session = cluster.connect(wait_for_all_pools=True) # temporarily increase client-side timeout to 1m to determine # if the cluster is simply responding slowly to requests session.default_timeout = 60.0 if keyspace is not None: session.set_keyspace(keyspace) # override driver default consistency level of LOCAL_QUORUM session.default_consistency_level = ConsistencyLevel.ONE self.connections.append(session) return session