mirror of
https://github.com/retspen/webvirtcloud
synced 2025-07-31 12:41:08 +00:00
fix code conventions for pylint
This commit is contained in:
parent
d283e0e1b3
commit
22cb8f702a
16 changed files with 245 additions and 110 deletions
|
@ -18,6 +18,8 @@ TCP_PORT = 16509
|
|||
|
||||
|
||||
class wvmEventLoop(threading.Thread):
|
||||
""" Event Loop Class"""
|
||||
|
||||
def __init__(self, group=None, target=None, name=None, args=(), kwargs={}):
|
||||
# register the default event implementation
|
||||
# of libvirt, as we do not have an existing
|
||||
|
@ -309,12 +311,12 @@ 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
|
||||
LIBVIRT_HOST = hostname
|
||||
socket_host.connect((LIBVIRT_HOST, PORT))
|
||||
libvirt_host = hostname
|
||||
socket_host.connect((libvirt_host, PORT))
|
||||
if conn_type == CONN_TCP:
|
||||
socket_host.connect((hostname, TCP_PORT))
|
||||
if conn_type == CONN_TLS:
|
||||
|
@ -387,7 +389,7 @@ class wvmConnect(object):
|
|||
result = dict()
|
||||
|
||||
xml = self.get_dom_cap_xml(arch, machine)
|
||||
result["path"] = util.get_xml_path(xml,"/domainCapabilities/path")
|
||||
result["path"] = util.get_xml_path(xml, "/domainCapabilities/path")
|
||||
result["domain"] = util.get_xml_path(xml, "/domainCapabilities/domain")
|
||||
result["machine"] = util.get_xml_path(xml, "/domainCapabilities/machine")
|
||||
result["vcpu_max"] = util.get_xml_path(xml, "/domainCapabilities/vcpu/@max")
|
||||
|
@ -431,6 +433,9 @@ class wvmConnect(object):
|
|||
return result
|
||||
|
||||
def get_version(self):
|
||||
"""
|
||||
:return: libvirt version
|
||||
"""
|
||||
ver = self.wvm.getVersion()
|
||||
major = ver // 1000000
|
||||
ver = ver % 1000000
|
||||
|
@ -449,10 +454,15 @@ class wvmConnect(object):
|
|||
return f"{major}.{minor}.{release}"
|
||||
|
||||
def is_kvm_supported(self):
|
||||
"""Return KVM capabilities."""
|
||||
"""
|
||||
:return: kvm support or not
|
||||
"""
|
||||
return util.is_kvm_available(self.get_cap_xml())
|
||||
|
||||
def get_storages(self, only_actives=False):
|
||||
"""
|
||||
:return: list of active or all storages
|
||||
"""
|
||||
storages = []
|
||||
for pool in self.wvm.listStoragePools():
|
||||
storages.append(pool)
|
||||
|
@ -462,6 +472,9 @@ class wvmConnect(object):
|
|||
return storages
|
||||
|
||||
def get_networks(self):
|
||||
"""
|
||||
:return: list of networks
|
||||
"""
|
||||
virtnet = []
|
||||
for net in self.wvm.listNetworks():
|
||||
virtnet.append(net)
|
||||
|
@ -470,6 +483,9 @@ class wvmConnect(object):
|
|||
return virtnet
|
||||
|
||||
def get_ifaces(self):
|
||||
"""
|
||||
:return: list of network interfaces
|
||||
"""
|
||||
interface = []
|
||||
for inface in self.wvm.listInterfaces():
|
||||
interface.append(inface)
|
||||
|
@ -478,13 +494,18 @@ class wvmConnect(object):
|
|||
return interface
|
||||
|
||||
def get_nwfilters(self):
|
||||
"""
|
||||
:return: list of network filters
|
||||
"""
|
||||
nwfilters = []
|
||||
for nwfilter in self.wvm.listNWFilters():
|
||||
nwfilters.append(nwfilter)
|
||||
return nwfilters
|
||||
|
||||
def get_cache_modes(self):
|
||||
"""Get cache available modes"""
|
||||
"""
|
||||
:return: Get cache available modes
|
||||
"""
|
||||
return {
|
||||
'default': 'Default',
|
||||
'none': 'Disabled',
|
||||
|
@ -495,7 +516,9 @@ class wvmConnect(object):
|
|||
}
|
||||
|
||||
def get_io_modes(self):
|
||||
"""Get io threads available modes"""
|
||||
"""
|
||||
:return: available io modes
|
||||
"""
|
||||
return {
|
||||
'default': 'Default',
|
||||
'native': 'Native',
|
||||
|
@ -503,7 +526,9 @@ class wvmConnect(object):
|
|||
}
|
||||
|
||||
def get_discard_modes(self):
|
||||
"""Get discard available modes"""
|
||||
"""
|
||||
:return: available discard modes
|
||||
"""
|
||||
return {
|
||||
'default': 'Default',
|
||||
'ignore': 'Ignore',
|
||||
|
@ -511,7 +536,9 @@ class wvmConnect(object):
|
|||
}
|
||||
|
||||
def get_detect_zeroes_modes(self):
|
||||
"""Get detect zeroes available modes"""
|
||||
"""
|
||||
:return: available detect zeroes modes
|
||||
"""
|
||||
return {
|
||||
'default': 'Default',
|
||||
'on': 'On',
|
||||
|
@ -520,7 +547,9 @@ class wvmConnect(object):
|
|||
}
|
||||
|
||||
def get_hypervisors_domain_types(self):
|
||||
"""Return hypervisor type"""
|
||||
"""
|
||||
:return: hypervisor domain types
|
||||
"""
|
||||
def hypervisors(ctx):
|
||||
result = {}
|
||||
for arch in ctx.xpath('/capabilities/guest/arch'):
|
||||
|
@ -531,7 +560,9 @@ class wvmConnect(object):
|
|||
return util.get_xml_path(self.get_cap_xml(), func=hypervisors)
|
||||
|
||||
def get_hypervisors_machines(self):
|
||||
"""Return hypervisor and its machine types"""
|
||||
"""
|
||||
:return: hypervisor and its machine types
|
||||
"""
|
||||
def machines(ctx):
|
||||
result = dict()
|
||||
for arche in ctx.xpath('/capabilities/guest/arch'):
|
||||
|
@ -542,11 +573,15 @@ class wvmConnect(object):
|
|||
return util.get_xml_path(self.get_cap_xml(), func=machines)
|
||||
|
||||
def get_emulator(self, arch):
|
||||
"""Return emulator """
|
||||
"""
|
||||
:return: emulator list
|
||||
"""
|
||||
return util.get_xml_path(self.get_cap_xml(), "/capabilities/guest/arch[@name='{}']/emulator".format(arch))
|
||||
|
||||
def get_machine_types(self, arch):
|
||||
"""Return canonical(if exist) name of machine types """
|
||||
"""
|
||||
:return: canonical(if exist) name of machine types
|
||||
"""
|
||||
def machines(ctx):
|
||||
result = list()
|
||||
canonical_name = ctx.xpath("/capabilities/guest/arch[@name='{}']/machine[@canonical]".format(arch))
|
||||
|
@ -559,6 +594,9 @@ class wvmConnect(object):
|
|||
return util.get_xml_path(self.get_cap_xml(), func=machines)
|
||||
|
||||
def get_emulators(self):
|
||||
"""
|
||||
:return: host emulators list
|
||||
"""
|
||||
def emulators(ctx):
|
||||
result = {}
|
||||
for arch in ctx.xpath('/capabilities/guest/arch'):
|
||||
|
@ -569,13 +607,21 @@ class wvmConnect(object):
|
|||
return util.get_xml_path(self.get_cap_xml(), func=emulators)
|
||||
|
||||
def get_os_loaders(self, arch='x86_64', machine='pc'):
|
||||
"""Get available os loaders list"""
|
||||
"""
|
||||
:param arch: architecture
|
||||
:param machine:
|
||||
:return: available os loaders list
|
||||
"""
|
||||
def get_os_loaders(ctx):
|
||||
return [v.text for v in ctx.xpath("/domainCapabilities/os/loader[@supported='yes']/value")]
|
||||
return util.get_xml_path(self.get_dom_cap_xml(arch, machine), func=get_os_loaders)
|
||||
|
||||
def get_os_loader_enums(self, arch, machine):
|
||||
"""Get available os loaders list"""
|
||||
"""
|
||||
:param arch: architecture
|
||||
:param machine:
|
||||
:return: available os loaders list
|
||||
"""
|
||||
def get_os_loader_enums(ctx):
|
||||
result = dict()
|
||||
enums = [v for v in ctx.xpath("/domainCapabilities/os/loader[@supported='yes']/enum/@name")]
|
||||
|
@ -586,33 +632,53 @@ class wvmConnect(object):
|
|||
return util.get_xml_path(self.get_dom_cap_xml(arch, machine), func=get_os_loader_enums)
|
||||
|
||||
def get_disk_bus_types(self, arch, machine):
|
||||
"""Get available disk bus types list"""
|
||||
"""
|
||||
:param machine:
|
||||
:param arch:
|
||||
:return: available disk bus types list
|
||||
"""
|
||||
def get_bus_list(ctx):
|
||||
return [v.text for v in ctx.xpath("/domainCapabilities/devices/disk/enum[@name='bus']/value")]
|
||||
# return [ 'ide', 'scsi', 'usb', 'virtio' ]
|
||||
return util.get_xml_path(self.get_dom_cap_xml(arch, machine), func=get_bus_list)
|
||||
|
||||
def get_disk_device_types(self, arch, machine):
|
||||
"""Get available disk device type list"""
|
||||
"""
|
||||
:param arch: architecture
|
||||
:param machine:
|
||||
:return: available disk device type list
|
||||
"""
|
||||
def get_device_list(ctx):
|
||||
return [v.text for v in ctx.xpath("/domainCapabilities/devices/disk/enum[@name='diskDevice']/value")]
|
||||
# return [ 'disk', 'cdrom', 'floppy', 'lun' ]
|
||||
return util.get_xml_path(self.get_dom_cap_xml(arch, machine), func=get_device_list)
|
||||
|
||||
def get_graphics_types(self, arch, machine):
|
||||
"""Get available graphics types """
|
||||
"""
|
||||
:param arch: architecture
|
||||
:param machine:
|
||||
:return: available graphics types
|
||||
"""
|
||||
def get_graphics_list(ctx):
|
||||
return [ v.text for v in ctx.xpath("/domainCapabilities/devices/graphics/enum[@name='type']/value")]
|
||||
return [v.text for v in ctx.xpath("/domainCapabilities/devices/graphics/enum[@name='type']/value")]
|
||||
return util.get_xml_path(self.get_dom_cap_xml(arch, machine), func=get_graphics_list)
|
||||
|
||||
def get_cpu_modes(self, arch, machine):
|
||||
"""Get available cpu modes """
|
||||
"""
|
||||
:param arch: architecture
|
||||
:param machine:
|
||||
:return: available cpu modes
|
||||
"""
|
||||
def get_cpu_modes(ctx):
|
||||
return [v for v in ctx.xpath("/domainCapabilities/cpu/mode[@supported='yes']/@name")]
|
||||
return util.get_xml_path(self.get_dom_cap_xml(arch, machine), func=get_cpu_modes)
|
||||
|
||||
def get_cpu_custom_types(self, arch, machine):
|
||||
"""Get available graphics types """
|
||||
"""
|
||||
:param arch: architecture
|
||||
:param machine:
|
||||
:return: available graphics types
|
||||
"""
|
||||
def get_custom_list(ctx):
|
||||
usable_yes = "/domainCapabilities/cpu/mode[@name='custom'][@supported='yes']/model[@usable='yes']"
|
||||
usable_unknown = "/domainCapabilities/cpu/mode[@name='custom'][@supported='yes']/model[@usable='unknown']"
|
||||
|
@ -622,42 +688,65 @@ class wvmConnect(object):
|
|||
return util.get_xml_path(self.get_dom_cap_xml(arch, machine), func=get_custom_list)
|
||||
|
||||
def get_hostdev_modes(self, arch, machine):
|
||||
"""Get available nodedev modes """
|
||||
"""
|
||||
:param arch: architecture
|
||||
:param machine:
|
||||
:return. available nodedev modes
|
||||
"""
|
||||
def get_hostdev_list(ctx):
|
||||
return [v.text for v in ctx.xpath("/domainCapabilities/devices/hostdev/enum[@name='mode']/value")]
|
||||
return util.get_xml_path(self.get_dom_cap_xml(arch, machine), func=get_hostdev_list)
|
||||
|
||||
def get_hostdev_startup_policies(self, arch, machine):
|
||||
"""Get available hostdev modes """
|
||||
"""
|
||||
:param arch: architecture
|
||||
:param machine:
|
||||
:return: available hostdev modes
|
||||
"""
|
||||
def get_hostdev_list(ctx):
|
||||
return [v.text for v in ctx.xpath("/domainCapabilities/devices/hostdev/enum[@name='startupPolicy']/value")]
|
||||
return util.get_xml_path(self.get_dom_cap_xml(arch, machine), func=get_hostdev_list)
|
||||
|
||||
def get_hostdev_subsys_types(self, arch, machine):
|
||||
"""Get available nodedev sub system types """
|
||||
"""
|
||||
:param arch: architecture
|
||||
:param machine:
|
||||
:return: available nodedev sub system types
|
||||
"""
|
||||
def get_hostdev_list(ctx):
|
||||
return [v.text for v in ctx.xpath("/domainCapabilities/devices/hostdev/enum[@name='subsysType']/value")]
|
||||
return util.get_xml_path(self.get_dom_cap_xml(arch, machine), func=get_hostdev_list)
|
||||
|
||||
def get_network_models(self):
|
||||
"""Get available image filename extensions"""
|
||||
"""
|
||||
:return: network card models
|
||||
"""
|
||||
return ['default', 'e1000', 'virtio']
|
||||
|
||||
def get_image_formats(self):
|
||||
"""Get available image formats"""
|
||||
"""
|
||||
:return: available image formats
|
||||
"""
|
||||
return ['raw', 'qcow', 'qcow2']
|
||||
|
||||
def get_file_extensions(self):
|
||||
"""Get available image filename extensions"""
|
||||
"""
|
||||
:return: available image filename extensions
|
||||
"""
|
||||
return ['img', 'qcow', 'qcow2']
|
||||
|
||||
def get_video_models(self, arch, machine):
|
||||
""" Get available graphics video types """
|
||||
"""
|
||||
:param arch: architecture
|
||||
:param machine:
|
||||
:return: available graphics video types
|
||||
"""
|
||||
def get_video_list(ctx):
|
||||
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(arch, machine), func=get_video_list)
|
||||
|
||||
|
@ -804,7 +893,7 @@ class wvmConnect(object):
|
|||
return
|
||||
|
||||
loaders = self.get_os_loaders(arch, machine)
|
||||
patterns = util.uefi_arch_patterns.get(arch)
|
||||
patterns = util.UEFI_ARCH_PATTERNS.get(arch)
|
||||
for pattern in patterns:
|
||||
for path in loaders:
|
||||
if re.match(pattern, path):
|
||||
|
@ -820,11 +909,10 @@ class wvmConnect(object):
|
|||
return "BIOS"
|
||||
return
|
||||
|
||||
for arch, patterns in util.uefi_arch_patterns.items():
|
||||
for arch, patterns in util.UEFI_ARCH_PATTERNS.items():
|
||||
for pattern in patterns:
|
||||
if re.match(pattern, path):
|
||||
return ("UEFI %(arch)s: %(path)s" %
|
||||
{"arch": arch, "path": path})
|
||||
return ("UEFI %(arch)s: %(path)s" % {"arch": arch, "path": path})
|
||||
|
||||
return "Custom: %(path)s" % {"path": path}
|
||||
|
||||
|
@ -832,7 +920,7 @@ class wvmConnect(object):
|
|||
"""
|
||||
Return True if we know how to setup UEFI for the passed arch
|
||||
"""
|
||||
return arch in list(util.uefi_arch_patterns.keys())
|
||||
return arch in list(util.UEFI_ARCH_PATTERNS.keys())
|
||||
|
||||
def supports_uefi_xml(self, loader_enums):
|
||||
"""
|
||||
|
@ -854,4 +942,3 @@ class wvmConnect(object):
|
|||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue