mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-02-25 18:55:27 -06:00
util: move is_error_nosupport to SupportCache
This commit is contained in:
parent
ecc3e3d34e
commit
ca10e4094b
@ -1002,7 +1002,7 @@ class vmmConnection(vmmGObject):
|
|||||||
self._backend.setKeepAlive(20, 1)
|
self._backend.setKeepAlive(20, 1)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if (not isinstance(e, AttributeError) and
|
if (not isinstance(e, AttributeError) and
|
||||||
not util.is_error_nosupport(e)):
|
not self.support.is_error_nosupport(e)):
|
||||||
raise
|
raise
|
||||||
logging.debug("Connection doesn't support KeepAlive, "
|
logging.debug("Connection doesn't support KeepAlive, "
|
||||||
"skipping")
|
"skipping")
|
||||||
|
@ -9,8 +9,6 @@ import time
|
|||||||
|
|
||||||
import libvirt
|
import libvirt
|
||||||
|
|
||||||
from virtinst import util
|
|
||||||
|
|
||||||
from .baseclass import vmmGObject
|
from .baseclass import vmmGObject
|
||||||
|
|
||||||
|
|
||||||
@ -204,7 +202,7 @@ class vmmStatsManager(vmmGObject):
|
|||||||
tx = io[4]
|
tx = io[4]
|
||||||
return rx, tx
|
return rx, tx
|
||||||
except libvirt.libvirtError as err:
|
except libvirt.libvirtError as err:
|
||||||
if util.is_error_nosupport(err):
|
if vm.conn.support.is_error_nosupport(err):
|
||||||
logging.debug("conn does not support interfaceStats")
|
logging.debug("conn does not support interfaceStats")
|
||||||
self._net_stats_supported = False
|
self._net_stats_supported = False
|
||||||
return 0, 0
|
return 0, 0
|
||||||
@ -264,7 +262,7 @@ class vmmStatsManager(vmmGObject):
|
|||||||
wr = io[3]
|
wr = io[3]
|
||||||
return rd, wr
|
return rd, wr
|
||||||
except libvirt.libvirtError as err:
|
except libvirt.libvirtError as err:
|
||||||
if util.is_error_nosupport(err):
|
if vm.conn.support.is_error_nosupport(err):
|
||||||
logging.debug("conn does not support blockStats")
|
logging.debug("conn does not support blockStats")
|
||||||
self._disk_stats_supported = False
|
self._disk_stats_supported = False
|
||||||
return 0, 0
|
return 0, 0
|
||||||
@ -353,7 +351,7 @@ class vmmStatsManager(vmmGObject):
|
|||||||
totalmem = stats.get("actual", 1)
|
totalmem = stats.get("actual", 1)
|
||||||
curmem = max(0, totalmem - stats.get("unused", totalmem))
|
curmem = max(0, totalmem - stats.get("unused", totalmem))
|
||||||
except libvirt.libvirtError as err:
|
except libvirt.libvirtError as err:
|
||||||
if util.is_error_nosupport(err):
|
if vm.conn.support.is_error_nosupport(err):
|
||||||
logging.debug("conn does not support memoryStats")
|
logging.debug("conn does not support memoryStats")
|
||||||
self._mem_stats_supported = False
|
self._mem_stats_supported = False
|
||||||
else:
|
else:
|
||||||
@ -418,7 +416,7 @@ class vmmStatsManager(vmmGObject):
|
|||||||
domallstats["virt-manager.timestamp"] = timestamp
|
domallstats["virt-manager.timestamp"] = timestamp
|
||||||
ret[dom.UUIDString()] = domallstats
|
ret[dom.UUIDString()] = domallstats
|
||||||
except libvirt.libvirtError as err:
|
except libvirt.libvirtError as err:
|
||||||
if util.is_error_nosupport(err):
|
if conn.support.is_error_nosupport(err):
|
||||||
logging.debug("conn does not support getAllDomainStats()")
|
logging.debug("conn does not support getAllDomainStats()")
|
||||||
self._all_stats_supported = False
|
self._all_stats_supported = False
|
||||||
else:
|
else:
|
||||||
|
@ -9,8 +9,6 @@
|
|||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import libvirt
|
|
||||||
|
|
||||||
from .devices import DeviceDisk
|
from .devices import DeviceDisk
|
||||||
from .domain import DomainOs
|
from .domain import DomainOs
|
||||||
from .osdict import OSDB, OsMedia
|
from .osdict import OSDB, OsMedia
|
||||||
@ -464,12 +462,11 @@ class Installer(object):
|
|||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
domain.setAutostart(True)
|
domain.setAutostart(True)
|
||||||
except libvirt.libvirtError as e:
|
except Exception as e:
|
||||||
if util.is_error_nosupport(e):
|
if not self.conn.support.is_error_nosupport(e):
|
||||||
logging.warning("Could not set autostart flag: libvirt "
|
raise
|
||||||
"connection does not support autostart.")
|
logging.warning("Could not set autostart flag: libvirt "
|
||||||
else:
|
"connection does not support autostart.")
|
||||||
raise e
|
|
||||||
|
|
||||||
|
|
||||||
######################
|
######################
|
||||||
|
@ -136,8 +136,8 @@ class StoragePool(_StorageObject):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
xml = conn.findStoragePoolSources(pool_type, source_xml, 0)
|
xml = conn.findStoragePoolSources(pool_type, source_xml, 0)
|
||||||
except libvirt.libvirtError as e:
|
except Exception as e:
|
||||||
if util.is_error_nosupport(e):
|
if conn.support.is_error_nosupport(e):
|
||||||
return []
|
return []
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
@ -8,8 +8,6 @@
|
|||||||
|
|
||||||
import libvirt
|
import libvirt
|
||||||
|
|
||||||
from . import util
|
|
||||||
|
|
||||||
|
|
||||||
# Check that command is present in the python bindings, and return the
|
# Check that command is present in the python bindings, and return the
|
||||||
# the requested function
|
# the requested function
|
||||||
@ -44,7 +42,7 @@ def _try_command(func, run_args, check_all_error=False):
|
|||||||
try:
|
try:
|
||||||
func(*run_args)
|
func(*run_args)
|
||||||
except libvirt.libvirtError as e:
|
except libvirt.libvirtError as e:
|
||||||
if util.is_error_nosupport(e):
|
if SupportCache.is_error_nosupport(e):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if check_all_error:
|
if check_all_error:
|
||||||
@ -246,6 +244,24 @@ class SupportCache:
|
|||||||
return False
|
return False
|
||||||
return err.get_error_code() == libvirt.VIR_ERR_NO_DOMAIN
|
return err.get_error_code() == libvirt.VIR_ERR_NO_DOMAIN
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def is_error_nosupport(err):
|
||||||
|
"""
|
||||||
|
Check if passed exception indicates that the called libvirt command isn't
|
||||||
|
supported
|
||||||
|
|
||||||
|
:param err: Exception raised from command call
|
||||||
|
:returns: True if command isn't supported, False if we can't determine
|
||||||
|
"""
|
||||||
|
if not isinstance(err, libvirt.libvirtError):
|
||||||
|
return False
|
||||||
|
|
||||||
|
if (err.get_error_code() == libvirt.VIR_ERR_RPC or
|
||||||
|
err.get_error_code() == libvirt.VIR_ERR_NO_SUPPORT):
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, virtconn):
|
def __init__(self, virtconn):
|
||||||
self._cache = {}
|
self._cache = {}
|
||||||
|
@ -119,24 +119,6 @@ def xml_escape(xml):
|
|||||||
return xml
|
return xml
|
||||||
|
|
||||||
|
|
||||||
def is_error_nosupport(err):
|
|
||||||
"""
|
|
||||||
Check if passed exception indicates that the called libvirt command isn't
|
|
||||||
supported
|
|
||||||
|
|
||||||
:param err: Exception raised from command call
|
|
||||||
:returns: True if command isn't supported, False if we can't determine
|
|
||||||
"""
|
|
||||||
if not isinstance(err, libvirt.libvirtError):
|
|
||||||
return False
|
|
||||||
|
|
||||||
if (err.get_error_code() == libvirt.VIR_ERR_RPC or
|
|
||||||
err.get_error_code() == libvirt.VIR_ERR_NO_SUPPORT):
|
|
||||||
return True
|
|
||||||
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def local_libvirt_version():
|
def local_libvirt_version():
|
||||||
"""
|
"""
|
||||||
Lookup the local libvirt library version, but cache the value since
|
Lookup the local libvirt library version, but cache the value since
|
||||||
|
Loading…
Reference in New Issue
Block a user