Set up the connection
(self)
| 90 | return instance |
| 91 | |
| 92 | def setup(self): |
| 93 | """Set up the connection""" |
| 94 | global cluster, session |
| 95 | |
| 96 | if 'username' in self.cluster_options or 'password' in self.cluster_options: |
| 97 | raise CQLEngineException("Username & Password are now handled by using the native driver's auth_provider") |
| 98 | |
| 99 | if self.lazy_connect: |
| 100 | return |
| 101 | |
| 102 | if 'cloud' in self.cluster_options: |
| 103 | if self.hosts: |
| 104 | log.warning("Ignoring hosts %s because a cloud config was provided.", self.hosts) |
| 105 | self.cluster = Cluster(**self.cluster_options) |
| 106 | else: |
| 107 | self.cluster = Cluster(self.hosts, **self.cluster_options) |
| 108 | |
| 109 | try: |
| 110 | self.session = self.cluster.connect() |
| 111 | log.debug(format_log_context("connection initialized with internally created session", connection=self.name)) |
| 112 | except NoHostAvailable: |
| 113 | if self.retry_connect: |
| 114 | log.warning(format_log_context("connect failed, setting up for re-attempt on first use", connection=self.name)) |
| 115 | self.lazy_connect = True |
| 116 | raise |
| 117 | |
| 118 | if DEFAULT_CONNECTION in _connections and _connections[DEFAULT_CONNECTION] == self: |
| 119 | cluster = _connections[DEFAULT_CONNECTION].cluster |
| 120 | session = _connections[DEFAULT_CONNECTION].session |
| 121 | |
| 122 | self.setup_session() |
| 123 | |
| 124 | def setup_session(self): |
| 125 | if self.cluster._config_mode == _ConfigMode.PROFILES: |