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)
|
||||
except Exception as e:
|
||||
if (not isinstance(e, AttributeError) and
|
||||
not util.is_error_nosupport(e)):
|
||||
not self.support.is_error_nosupport(e)):
|
||||
raise
|
||||
logging.debug("Connection doesn't support KeepAlive, "
|
||||
"skipping")
|
||||
|
|
|
@ -9,8 +9,6 @@ import time
|
|||
|
||||
import libvirt
|
||||
|
||||
from virtinst import util
|
||||
|
||||
from .baseclass import vmmGObject
|
||||
|
||||
|
||||
|
@ -204,7 +202,7 @@ class vmmStatsManager(vmmGObject):
|
|||
tx = io[4]
|
||||
return rx, tx
|
||||
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")
|
||||
self._net_stats_supported = False
|
||||
return 0, 0
|
||||
|
@ -264,7 +262,7 @@ class vmmStatsManager(vmmGObject):
|
|||
wr = io[3]
|
||||
return rd, wr
|
||||
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")
|
||||
self._disk_stats_supported = False
|
||||
return 0, 0
|
||||
|
@ -353,7 +351,7 @@ class vmmStatsManager(vmmGObject):
|
|||
totalmem = stats.get("actual", 1)
|
||||
curmem = max(0, totalmem - stats.get("unused", totalmem))
|
||||
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")
|
||||
self._mem_stats_supported = False
|
||||
else:
|
||||
|
@ -418,7 +416,7 @@ class vmmStatsManager(vmmGObject):
|
|||
domallstats["virt-manager.timestamp"] = timestamp
|
||||
ret[dom.UUIDString()] = domallstats
|
||||
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()")
|
||||
self._all_stats_supported = False
|
||||
else:
|
||||
|
|
|
@ -9,8 +9,6 @@
|
|||
import os
|
||||
import logging
|
||||
|
||||
import libvirt
|
||||
|
||||
from .devices import DeviceDisk
|
||||
from .domain import DomainOs
|
||||
from .osdict import OSDB, OsMedia
|
||||
|
@ -464,12 +462,11 @@ class Installer(object):
|
|||
"""
|
||||
try:
|
||||
domain.setAutostart(True)
|
||||
except libvirt.libvirtError as e:
|
||||
if util.is_error_nosupport(e):
|
||||
logging.warning("Could not set autostart flag: libvirt "
|
||||
"connection does not support autostart.")
|
||||
else:
|
||||
raise e
|
||||
except Exception as e:
|
||||
if not self.conn.support.is_error_nosupport(e):
|
||||
raise
|
||||
logging.warning("Could not set autostart flag: libvirt "
|
||||
"connection does not support autostart.")
|
||||
|
||||
|
||||
######################
|
||||
|
|
|
@ -136,8 +136,8 @@ class StoragePool(_StorageObject):
|
|||
|
||||
try:
|
||||
xml = conn.findStoragePoolSources(pool_type, source_xml, 0)
|
||||
except libvirt.libvirtError as e:
|
||||
if util.is_error_nosupport(e):
|
||||
except Exception as e:
|
||||
if conn.support.is_error_nosupport(e):
|
||||
return []
|
||||
raise
|
||||
|
||||
|
|
|
@ -8,8 +8,6 @@
|
|||
|
||||
import libvirt
|
||||
|
||||
from . import util
|
||||
|
||||
|
||||
# Check that command is present in the python bindings, and return the
|
||||
# the requested function
|
||||
|
@ -44,7 +42,7 @@ def _try_command(func, run_args, check_all_error=False):
|
|||
try:
|
||||
func(*run_args)
|
||||
except libvirt.libvirtError as e:
|
||||
if util.is_error_nosupport(e):
|
||||
if SupportCache.is_error_nosupport(e):
|
||||
return False
|
||||
|
||||
if check_all_error:
|
||||
|
@ -246,6 +244,24 @@ class SupportCache:
|
|||
return False
|
||||
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):
|
||||
self._cache = {}
|
||||
|
|
|
@ -119,24 +119,6 @@ def xml_escape(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():
|
||||
"""
|
||||
Lookup the local libvirt library version, but cache the value since
|
||||
|
|
Loading…
Reference in New Issue