mirror of
https://github.com/retspen/webvirtcloud
synced 2025-01-12 16:35:17 +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
|
# on server shutdown libvirt module gets freed before the close callbacks are called
|
||||||
# so we just check here if it is still present
|
# so we just check here if it is still present
|
||||||
if libvirt is not None:
|
if libvirt is not None:
|
||||||
if (reason == libvirt.VIR_CONNECT_CLOSE_REASON_ERROR):
|
self.last_error = reason
|
||||||
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'
|
|
||||||
|
|
||||||
# prevent other threads from using the connection (in the future)
|
# prevent other threads from using the connection (in the future)
|
||||||
self.connection = None
|
self.connection = None
|
||||||
|
@ -255,11 +246,11 @@ class wvmConnectionManager(object):
|
||||||
"""
|
"""
|
||||||
self._connections_lock.acquireRead()
|
self._connections_lock.acquireRead()
|
||||||
try:
|
try:
|
||||||
if (host in self._connections):
|
if host in self._connections:
|
||||||
connections = self._connections[host]
|
connections = self._connections[host]
|
||||||
|
|
||||||
for connection in connections:
|
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
|
return connection
|
||||||
finally:
|
finally:
|
||||||
self._connections_lock.release()
|
self._connections_lock.release()
|
||||||
|
@ -278,13 +269,13 @@ class wvmConnectionManager(object):
|
||||||
|
|
||||||
connection = self._search_connection(host, login, passwd, conn)
|
connection = self._search_connection(host, login, passwd, conn)
|
||||||
|
|
||||||
if (connection is None):
|
if connection is None:
|
||||||
self._connections_lock.acquireWrite()
|
self._connections_lock.acquireWrite()
|
||||||
try:
|
try:
|
||||||
# we have to search for the connection again after aquireing the write lock
|
# 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
|
# as the thread previously holding the write lock may have already added our connection
|
||||||
connection = self._search_connection(host, login, passwd, conn)
|
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
|
# create a new connection if a matching connection does not already exist
|
||||||
connection = wvmConnection(host, login, passwd, conn)
|
connection = wvmConnection(host, login, passwd, conn)
|
||||||
|
|
||||||
|
@ -317,7 +308,7 @@ class wvmConnectionManager(object):
|
||||||
socket_host.settimeout(1)
|
socket_host.settimeout(1)
|
||||||
if conn_type == CONN_SSH:
|
if conn_type == CONN_SSH:
|
||||||
if ':' in hostname:
|
if ':' in hostname:
|
||||||
LIBVIRT_HOST, PORT = (hostname).split(":")
|
LIBVIRT_HOST, PORT = hostname.split(":")
|
||||||
PORT = int(PORT)
|
PORT = int(PORT)
|
||||||
else:
|
else:
|
||||||
PORT = SSH_PORT
|
PORT = SSH_PORT
|
||||||
|
@ -332,6 +323,7 @@ class wvmConnectionManager(object):
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
return err
|
return err
|
||||||
|
|
||||||
|
|
||||||
connection_manager = wvmConnectionManager(
|
connection_manager = wvmConnectionManager(
|
||||||
settings.LIBVIRT_KEEPALIVE_INTERVAL if hasattr(settings, 'LIBVIRT_KEEPALIVE_INTERVAL') else 5,
|
settings.LIBVIRT_KEEPALIVE_INTERVAL if hasattr(settings, 'LIBVIRT_KEEPALIVE_INTERVAL') else 5,
|
||||||
settings.LIBVIRT_KEEPALIVE_COUNT if hasattr(settings, 'LIBVIRT_KEEPALIVE_COUNT') 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):
|
def get_host_instances(self, raw_mem_size=False):
|
||||||
vname = {}
|
vname = {}
|
||||||
|
|
||||||
def get_info(doc):
|
def get_info(doc):
|
||||||
mem = util.get_xpath(doc, "/domain/currentMemory")
|
mem = util.get_xpath(doc, "/domain/currentMemory")
|
||||||
mem = int(mem) / 1024
|
mem = int(mem) / 1024
|
||||||
|
@ -574,7 +567,7 @@ class wvmConnect(object):
|
||||||
title = title if title else ''
|
title = title if title else ''
|
||||||
description = util.get_xpath(doc, "/domain/description")
|
description = util.get_xpath(doc, "/domain/description")
|
||||||
description = description if description else ''
|
description = description if description else ''
|
||||||
return (mem, vcpu, title, description)
|
return mem, vcpu, title, description
|
||||||
for name in self.get_instances():
|
for name in self.get_instances():
|
||||||
dom = self.get_instance(name)
|
dom = self.get_instance(name)
|
||||||
xml = dom.XMLDesc(0)
|
xml = dom.XMLDesc(0)
|
||||||
|
@ -592,6 +585,7 @@ class wvmConnect(object):
|
||||||
def get_user_instances(self, name):
|
def get_user_instances(self, name):
|
||||||
dom = self.get_instance(name)
|
dom = self.get_instance(name)
|
||||||
xml = dom.XMLDesc(0)
|
xml = dom.XMLDesc(0)
|
||||||
|
|
||||||
def get_info(ctx):
|
def get_info(ctx):
|
||||||
mem = util.get_xpath(ctx, "/domain/currentMemory")
|
mem = util.get_xpath(ctx, "/domain/currentMemory")
|
||||||
mem = int(mem) / 1024
|
mem = int(mem) / 1024
|
||||||
|
@ -604,7 +598,7 @@ class wvmConnect(object):
|
||||||
title = title if title else ''
|
title = title if title else ''
|
||||||
description = util.get_xpath(ctx, "/domain/description")
|
description = util.get_xpath(ctx, "/domain/description")
|
||||||
description = description if description else ''
|
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)
|
(mem, vcpu, title, description) = util.get_xml_path(xml, func=get_info)
|
||||||
return {
|
return {
|
||||||
'name': dom.name(),
|
'name': dom.name(),
|
||||||
|
|
Loading…
Reference in a new issue