MCPcopy
hub / github.com/retspen/webvirtcloud / get_connection

Method get_connection

vrtManager/connection.py:269–308  ·  view source on GitHub ↗

returns a connection object (as returned by the libvirt.open* methods) for the given host and credentials raises libvirtError if (re)connecting fails

(self, host, login, passwd, conn)

Source from the content-addressed store, hash-verified

267 return None
268
269 def get_connection(self, host, login, passwd, conn):
270 """
271 returns a connection object (as returned by the libvirt.open* methods) for the given host and credentials
272 raises libvirtError if (re)connecting fails
273 """
274 # force all string values to unicode
275 host = unicode(host)
276 login = unicode(login)
277 passwd = unicode(passwd) if passwd is not None else None
278
279 connection = self._search_connection(host, login, passwd, conn)
280
281 if (connection is None):
282 self._connections_lock.acquireWrite()
283 try:
284 # we have to search for the connection again after aquireing the write lock
285 # as the thread previously holding the write lock may have already added our connection
286 connection = self._search_connection(host, login, passwd, conn)
287 if (connection is None):
288 # create a new connection if a matching connection does not already exist
289 connection = wvmConnection(host, login, passwd, conn)
290
291 # add new connection to connection dict
292 if host in self._connections:
293 self._connections[host].append(connection)
294 else:
295 self._connections[host] = [connection]
296 finally:
297 self._connections_lock.release()
298
299 elif not connection.connected:
300 # try to (re-)connect if connection is closed
301 connection.connect()
302
303 if connection.connected:
304 # return libvirt connection object
305 return connection.connection
306 else:
307 # raise libvirt error
308 raise libvirtError(connection.last_error)
309
310 def host_is_up(self, conn_type, hostname):
311 """

Callers 1

__init__Method · 0.80

Calls 5

_search_connectionMethod · 0.95
wvmConnectionClass · 0.85
acquireWriteMethod · 0.80
releaseMethod · 0.80
connectMethod · 0.80

Tested by

no test coverage detected