mirror of
https://github.com/retspen/webvirtcloud
synced 2024-12-24 23:25:24 +00:00
libvirt does not have the connection close reason contants anymore. pep8 conventions apply
This commit is contained in:
parent
38ae62d093
commit
568ff92449
1 changed files with 19 additions and 25 deletions
|
@ -124,16 +124,7 @@ class wvmConnection(object):
|
|||
# on server shutdown libvirt module gets freed before the close callbacks are called
|
||||
# so we just check here if it is still present
|
||||
if libvirt is not None:
|
||||
if (reason == libvirt.VIR_CONNECT_CLOSE_REASON_ERROR):
|
||||
self.last_error = 'connection closed: Misc I/O error'
|
||||
elif (reason == libvirt.VIR_CONNECT_CLOSE_REASON_EOF):
|
||||
self.last_error = 'connection closed: End-of-file from server'
|
||||
elif (reason == libvirt.VIR_CONNECT_CLOSE_REASON_KEEPALIVE):
|
||||
self.last_error = 'connection closed: Keepalive timer triggered'
|
||||
elif (reason == libvirt.VIR_CONNECT_CLOSE_REASON_CLIENT):
|
||||
self.last_error = 'connection closed: Client requested it'
|
||||
else:
|
||||
self.last_error = 'connection closed: Unknown error'
|
||||
self.last_error = reason
|
||||
|
||||
# prevent other threads from using the connection (in the future)
|
||||
self.connection = None
|
||||
|
@ -255,11 +246,11 @@ class wvmConnectionManager(object):
|
|||
"""
|
||||
self._connections_lock.acquireRead()
|
||||
try:
|
||||
if (host in self._connections):
|
||||
if host in self._connections:
|
||||
connections = self._connections[host]
|
||||
|
||||
for connection in connections:
|
||||
if (connection.login == login and connection.passwd == passwd and connection.type == conn):
|
||||
if connection.login == login and connection.passwd == passwd and connection.type == conn:
|
||||
return connection
|
||||
finally:
|
||||
self._connections_lock.release()
|
||||
|
@ -278,13 +269,13 @@ class wvmConnectionManager(object):
|
|||
|
||||
connection = self._search_connection(host, login, passwd, conn)
|
||||
|
||||
if (connection is None):
|
||||
if connection is None:
|
||||
self._connections_lock.acquireWrite()
|
||||
try:
|
||||
# we have to search for the connection again after aquireing the write lock
|
||||
# as the thread previously holding the write lock may have already added our connection
|
||||
connection = self._search_connection(host, login, passwd, conn)
|
||||
if (connection is None):
|
||||
if connection is None:
|
||||
# create a new connection if a matching connection does not already exist
|
||||
connection = wvmConnection(host, login, passwd, conn)
|
||||
|
||||
|
@ -317,7 +308,7 @@ class wvmConnectionManager(object):
|
|||
socket_host.settimeout(1)
|
||||
if conn_type == CONN_SSH:
|
||||
if ':' in hostname:
|
||||
LIBVIRT_HOST, PORT = (hostname).split(":")
|
||||
LIBVIRT_HOST, PORT = hostname.split(":")
|
||||
PORT = int(PORT)
|
||||
else:
|
||||
PORT = SSH_PORT
|
||||
|
@ -332,6 +323,7 @@ class wvmConnectionManager(object):
|
|||
except Exception as err:
|
||||
return err
|
||||
|
||||
|
||||
connection_manager = wvmConnectionManager(
|
||||
settings.LIBVIRT_KEEPALIVE_INTERVAL if hasattr(settings, 'LIBVIRT_KEEPALIVE_INTERVAL') else 5,
|
||||
settings.LIBVIRT_KEEPALIVE_COUNT if hasattr(settings, 'LIBVIRT_KEEPALIVE_COUNT') else 5
|
||||
|
@ -560,6 +552,7 @@ class wvmConnect(object):
|
|||
|
||||
def get_host_instances(self, raw_mem_size=False):
|
||||
vname = {}
|
||||
|
||||
def get_info(doc):
|
||||
mem = util.get_xpath(doc, "/domain/currentMemory")
|
||||
mem = int(mem) / 1024
|
||||
|
@ -574,7 +567,7 @@ class wvmConnect(object):
|
|||
title = title if title else ''
|
||||
description = util.get_xpath(doc, "/domain/description")
|
||||
description = description if description else ''
|
||||
return (mem, vcpu, title, description)
|
||||
return mem, vcpu, title, description
|
||||
for name in self.get_instances():
|
||||
dom = self.get_instance(name)
|
||||
xml = dom.XMLDesc(0)
|
||||
|
@ -592,6 +585,7 @@ class wvmConnect(object):
|
|||
def get_user_instances(self, name):
|
||||
dom = self.get_instance(name)
|
||||
xml = dom.XMLDesc(0)
|
||||
|
||||
def get_info(ctx):
|
||||
mem = util.get_xpath(ctx, "/domain/currentMemory")
|
||||
mem = int(mem) / 1024
|
||||
|
@ -604,7 +598,7 @@ class wvmConnect(object):
|
|||
title = title if title else ''
|
||||
description = util.get_xpath(ctx, "/domain/description")
|
||||
description = description if description else ''
|
||||
return (mem, vcpu, title, description)
|
||||
return mem, vcpu, title, description
|
||||
(mem, vcpu, title, description) = util.get_xml_path(xml, func=get_info)
|
||||
return {
|
||||
'name': dom.name(),
|
||||
|
|
Loading…
Reference in a new issue