mirror of
https://github.com/retspen/webvirtcloud
synced 2025-07-31 12:41:08 +00:00
Migrate source code to python 3.7 and refine code style
This commit is contained in:
parent
0e231a930d
commit
a4d74a09a6
55 changed files with 192 additions and 306 deletions
|
|
@ -2,7 +2,7 @@ import libvirt
|
|||
import threading
|
||||
import socket
|
||||
from vrtManager import util
|
||||
from rwlock import ReadWriteLock
|
||||
from vrtManager.rwlock import ReadWriteLock
|
||||
from django.conf import settings
|
||||
from libvirt import libvirtError
|
||||
|
||||
|
|
@ -216,18 +216,18 @@ class wvmConnection(object):
|
|||
|
||||
def __unicode__(self):
|
||||
if self.type == CONN_TCP:
|
||||
type_str = u'tcp'
|
||||
type_str = 'tcp'
|
||||
elif self.type == CONN_SSH:
|
||||
type_str = u'ssh'
|
||||
type_str = 'ssh'
|
||||
elif self.type == CONN_TLS:
|
||||
type_str = u'tls'
|
||||
type_str = 'tls'
|
||||
else:
|
||||
type_str = u'invalid_type'
|
||||
type_str = 'invalid_type'
|
||||
|
||||
return u'qemu+{type}://{user}@{host}/system'.format(type=type_str, user=self.login, host=self.host)
|
||||
return f'qemu+{type_str}://{self.login}@{self.host}/system'
|
||||
|
||||
def __repr__(self):
|
||||
return '<wvmConnection {connection_str}>'.format(connection_str=unicode(self))
|
||||
return '<wvmConnection {connection_str}>'.format(connection_str=str(self))
|
||||
|
||||
|
||||
class wvmConnectionManager(object):
|
||||
|
|
@ -272,19 +272,19 @@ class wvmConnectionManager(object):
|
|||
raises libvirtError if (re)connecting fails
|
||||
"""
|
||||
# force all string values to unicode
|
||||
host = unicode(host)
|
||||
login = unicode(login)
|
||||
passwd = unicode(passwd) if passwd is not None else None
|
||||
host = str(host)
|
||||
login = str(login)
|
||||
passwd = str(passwd) if passwd is not None else None
|
||||
|
||||
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)
|
||||
|
||||
|
|
@ -332,6 +332,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
|
||||
|
|
@ -368,7 +369,7 @@ class wvmConnect(object):
|
|||
minor = ver / 1000
|
||||
ver = ver % 1000
|
||||
release = ver
|
||||
return "%s.%s.%s" % (major,minor,release)
|
||||
return f"{major}.{minor}.{release}"
|
||||
|
||||
def get_lib_version(self):
|
||||
ver = self.wvm.getLibVersion()
|
||||
|
|
@ -377,7 +378,7 @@ class wvmConnect(object):
|
|||
minor = ver / 1000
|
||||
ver %= 1000
|
||||
release = ver
|
||||
return "%s.%s.%s" % (major,minor,release)
|
||||
return f"{major}.{minor}.{release}"
|
||||
|
||||
def is_kvm_supported(self):
|
||||
"""Return KVM capabilities."""
|
||||
|
|
@ -432,7 +433,7 @@ class wvmConnect(object):
|
|||
for arch in ctx.xpath('/capabilities/guest/arch'):
|
||||
domain_types = arch.xpath('domain/@type')
|
||||
arch_name = arch.xpath('@name')[0]
|
||||
result[arch_name]= domain_types
|
||||
result[arch_name] = domain_types
|
||||
return result
|
||||
return util.get_xml_path(self.get_cap_xml(), func=hypervisors)
|
||||
|
||||
|
|
@ -446,7 +447,7 @@ class wvmConnect(object):
|
|||
for arch in ctx.xpath('/capabilities/guest/arch'):
|
||||
emulator = arch.xpath('emulator')
|
||||
arch_name = arch.xpath('@name')[0]
|
||||
result[arch_name]= emulator
|
||||
result[arch_name] = emulator
|
||||
return result
|
||||
return util.get_xml_path(self.get_cap_xml(), func=emulators)
|
||||
|
||||
|
|
@ -460,8 +461,9 @@ class wvmConnect(object):
|
|||
def get_bus_list(ctx):
|
||||
result = []
|
||||
for disk_enum in ctx.xpath('/domainCapabilities/devices/disk/enum'):
|
||||
if disk_enum.xpath("@name")[0] == "bus":
|
||||
for values in disk_enum: result.append(values.text)
|
||||
if disk_enum.xpath("@name")[0] == "bus":
|
||||
for values in disk_enum:
|
||||
result.append(values.text)
|
||||
return result
|
||||
|
||||
# return [ 'ide', 'scsi', 'usb', 'virtio' ]
|
||||
|
|
@ -474,7 +476,8 @@ class wvmConnect(object):
|
|||
result = []
|
||||
for disk_enum in ctx.xpath('/domainCapabilities/devices/disk/enum'):
|
||||
if disk_enum.xpath("@name")[0] == "diskDevice":
|
||||
for values in disk_enum: result.append(values.text)
|
||||
for values in disk_enum:
|
||||
result.append(values.text)
|
||||
return result
|
||||
|
||||
# return [ 'disk', 'cdrom', 'floppy', 'lun' ]
|
||||
|
|
@ -482,11 +485,11 @@ class wvmConnect(object):
|
|||
|
||||
def get_image_formats(self):
|
||||
"""Get available image formats"""
|
||||
return [ 'raw', 'qcow', 'qcow2' ]
|
||||
return ['raw', 'qcow', 'qcow2']
|
||||
|
||||
def get_file_extensions(self):
|
||||
"""Get available image filename extensions"""
|
||||
return [ 'img', 'qcow', 'qcow2' ]
|
||||
return ['img', 'qcow', 'qcow2']
|
||||
|
||||
def get_video(self):
|
||||
""" Get available graphics video types """
|
||||
|
|
@ -494,9 +497,10 @@ class wvmConnect(object):
|
|||
result = []
|
||||
for video_enum in ctx.xpath('/domainCapabilities/devices/video/enum'):
|
||||
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 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):
|
||||
return self.wvm.interfaceLookupByName(name)
|
||||
|
|
@ -560,6 +564,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
|
||||
|
|
@ -592,6 +597,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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue