MCPcopy Create free account
hub / github.com/apache/cassandra-python-driver / register_connection

Function register_connection

cassandra/cqlengine/connection.py:153–209  ·  view source on GitHub ↗

Add a connection to the connection registry. ``hosts`` and ``session`` are mutually exclusive, and ``consistency``, ``lazy_connect``, ``retry_connect``, and ``cluster_options`` only work with ``hosts``. Using ``hosts`` will create a new :class:`cassandra.cluster.Cluster` and :cl

(name, hosts=None, consistency=None, lazy_connect=False,
                        retry_connect=False, cluster_options=None, default=False,
                        session=None)

Source from the content-addressed store, hash-verified

151
152
153def register_connection(name, hosts=None, consistency=None, lazy_connect=False,
154 retry_connect=False, cluster_options=None, default=False,
155 session=None):
156 """
157 Add a connection to the connection registry. ``hosts`` and ``session`` are
158 mutually exclusive, and ``consistency``, ``lazy_connect``,
159 ``retry_connect``, and ``cluster_options`` only work with ``hosts``. Using
160 ``hosts`` will create a new :class:`cassandra.cluster.Cluster` and
161 :class:`cassandra.cluster.Session`.
162
163 :param list hosts: list of hosts, (``contact_points`` for :class:`cassandra.cluster.Cluster`).
164 :param int consistency: The default :class:`~.ConsistencyLevel` for the
165 registered connection's new session. Default is the same as
166 :attr:`.Session.default_consistency_level`. For use with ``hosts`` only;
167 will fail when used with ``session``.
168 :param bool lazy_connect: True if should not connect until first use. For
169 use with ``hosts`` only; will fail when used with ``session``.
170 :param bool retry_connect: True if we should retry to connect even if there
171 was a connection failure initially. For use with ``hosts`` only; will
172 fail when used with ``session``.
173 :param dict cluster_options: A dict of options to be used as keyword
174 arguments to :class:`cassandra.cluster.Cluster`. For use with ``hosts``
175 only; will fail when used with ``session``.
176 :param bool default: If True, set the new connection as the cqlengine
177 default
178 :param Session session: A :class:`cassandra.cluster.Session` to be used in
179 the created connection.
180 """
181
182 if name in _connections:
183 log.warning("Registering connection '{0}' when it already exists.".format(name))
184
185 if session is not None:
186 invalid_config_args = (hosts is not None or
187 consistency is not None or
188 lazy_connect is not False or
189 retry_connect is not False or
190 cluster_options is not None)
191 if invalid_config_args:
192 raise CQLEngineException(
193 "Session configuration arguments and 'session' argument are mutually exclusive"
194 )
195 conn = Connection.from_session(name, session=session)
196 else: # use hosts argument
197 conn = Connection(
198 name, hosts=hosts,
199 consistency=consistency, lazy_connect=lazy_connect,
200 retry_connect=retry_connect, cluster_options=cluster_options
201 )
202 conn.setup()
203
204 _connections[name] = conn
205
206 if default:
207 set_default_connection(name)
208
209 return conn
210

Callers 3

defaultFunction · 0.85
set_sessionFunction · 0.85
setupFunction · 0.85

Calls 5

setupMethod · 0.95
CQLEngineExceptionClass · 0.90
set_default_connectionFunction · 0.85
from_sessionMethod · 0.80
ConnectionClass · 0.70

Tested by

no test coverage detected