mirror of
https://github.com/retspen/webvirtcloud
synced 2024-12-25 23:55: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
|
# 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
|
||||||
|
@ -368,7 +360,7 @@ class wvmConnect(object):
|
||||||
minor = ver / 1000
|
minor = ver / 1000
|
||||||
ver = ver % 1000
|
ver = ver % 1000
|
||||||
release = ver
|
release = ver
|
||||||
return "%s.%s.%s" % (major,minor,release)
|
return "%s.%s.%s" % (major, minor, release)
|
||||||
|
|
||||||
def get_lib_version(self):
|
def get_lib_version(self):
|
||||||
ver = self.wvm.getLibVersion()
|
ver = self.wvm.getLibVersion()
|
||||||
|
@ -432,7 +424,7 @@ class wvmConnect(object):
|
||||||
for arch in ctx.xpath('/capabilities/guest/arch'):
|
for arch in ctx.xpath('/capabilities/guest/arch'):
|
||||||
domain_types = arch.xpath('domain/@type')
|
domain_types = arch.xpath('domain/@type')
|
||||||
arch_name = arch.xpath('@name')[0]
|
arch_name = arch.xpath('@name')[0]
|
||||||
result[arch_name]= domain_types
|
result[arch_name] = domain_types
|
||||||
return result
|
return result
|
||||||
return util.get_xml_path(self.get_cap_xml(), func=hypervisors)
|
return util.get_xml_path(self.get_cap_xml(), func=hypervisors)
|
||||||
|
|
||||||
|
@ -446,7 +438,7 @@ class wvmConnect(object):
|
||||||
for arch in ctx.xpath('/capabilities/guest/arch'):
|
for arch in ctx.xpath('/capabilities/guest/arch'):
|
||||||
emulator = arch.xpath('emulator')
|
emulator = arch.xpath('emulator')
|
||||||
arch_name = arch.xpath('@name')[0]
|
arch_name = arch.xpath('@name')[0]
|
||||||
result[arch_name]= emulator
|
result[arch_name] = emulator
|
||||||
return result
|
return result
|
||||||
return util.get_xml_path(self.get_cap_xml(), func=emulators)
|
return util.get_xml_path(self.get_cap_xml(), func=emulators)
|
||||||
|
|
||||||
|
@ -482,11 +474,11 @@ class wvmConnect(object):
|
||||||
|
|
||||||
def get_image_formats(self):
|
def get_image_formats(self):
|
||||||
"""Get available image formats"""
|
"""Get available image formats"""
|
||||||
return [ 'raw', 'qcow', 'qcow2' ]
|
return ['raw', 'qcow', 'qcow2']
|
||||||
|
|
||||||
def get_file_extensions(self):
|
def get_file_extensions(self):
|
||||||
"""Get available image filename extensions"""
|
"""Get available image filename extensions"""
|
||||||
return [ 'img', 'qcow', 'qcow2' ]
|
return ['img', 'qcow', 'qcow2']
|
||||||
|
|
||||||
def get_video(self):
|
def get_video(self):
|
||||||
""" Get available graphics video types """
|
""" Get available graphics video types """
|
||||||
|
@ -496,7 +488,7 @@ class wvmConnect(object):
|
||||||
if video_enum.xpath("@name")[0] == "modelType":
|
if video_enum.xpath("@name")[0] == "modelType":
|
||||||
for values in video_enum: result.append(values.text)
|
for values in video_enum: result.append(values.text)
|
||||||
return result
|
return result
|
||||||
return util.get_xml_path(self.get_dom_cap_xml(),func=get_video_list)
|
return util.get_xml_path(self.get_dom_cap_xml(), func=get_video_list)
|
||||||
|
|
||||||
def get_iface(self, name):
|
def get_iface(self, name):
|
||||||
return self.wvm.interfaceLookupByName(name)
|
return self.wvm.interfaceLookupByName(name)
|
||||||
|
@ -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