summaryrefslogtreecommitdiff
path: root/virtinst/connection.py
diff options
context:
space:
mode:
authorCole Robinson <crobinso@redhat.com>2019-06-07 14:48:59 -0400
committerCole Robinson <crobinso@redhat.com>2019-06-07 16:25:39 -0400
commit566a4681a81b5ddba275c0953b5edc08fe7f472b (patch)
tree3122927a346c67e30e1153d8716d5f2d2d4f5dc4 /virtinst/connection.py
parent3d2f678c0fd7fe0a14a07a6d231b1f94c6d6799d (diff)
downloadvirt-manager-566a4681a81b5ddba275c0953b5edc08fe7f472b.tar.gz
support: Rework support check invocations
SupportCache.check_support(SUPPORT_FOOBAR, args) becomes SupportCache.foobar(args) And SupportCache absorbs the caching infrastructure from VirtinstConnection. For now we add some hackery to hide the API change from callers, but this will be undone in the next patch
Diffstat (limited to 'virtinst/connection.py')
-rw-r--r--virtinst/connection.py25
1 files changed, 5 insertions, 20 deletions
diff --git a/virtinst/connection.py b/virtinst/connection.py
index 558b6142..57d74ffa 100644
--- a/virtinst/connection.py
+++ b/virtinst/connection.py
@@ -57,7 +57,6 @@ class VirtinstConnection(object):
self._uriobj = URI(self._uri)
self._caps = None
- self._support_cache = {}
self._fetch_cache = {}
# These let virt-manager register a callback which provides its
@@ -68,7 +67,7 @@ class VirtinstConnection(object):
self.cb_fetch_all_nodedevs = None
self.cb_cache_new_pool = None
- self.support = support.SupportCache()
+ self.support = support.SupportCache(weakref.proxy(self))
##############
@@ -79,6 +78,9 @@ class VirtinstConnection(object):
if attr in self.__dict__:
return self.__dict__[attr]
+ if attr.startswith("SUPPORT_"):
+ return getattr(self.support, attr.split("_", 1)[1].lower())
+
# Proxy virConnect API calls
libvirtconn = self.__dict__.get("_libvirtconn")
return getattr(libvirtconn, attr)
@@ -380,30 +382,13 @@ class VirtinstConnection(object):
# Support check helpers #
#########################
- for _supportname in [_supportname for _supportname in
- dir(support.SupportCache) if
- _supportname.startswith("SUPPORT_")]:
- locals()[_supportname] = getattr(support.SupportCache, _supportname)
-
-
def check_support(self, features, data=None):
- def _check_support(key):
- if key not in self._support_cache:
- self._support_cache[key] = self.support.check_support(
- self, key, data or self)
- return self._support_cache[key]
-
for f in util.listify(features):
# 'and' condition over the feature list
- if not _check_support(f):
+ if not f(data):
return False
return True
- def _check_version(self, version):
- # Entry point for the test suite to do simple version checks,
- # actual code should only use check_support
- return self.support.check_version(self, version)
-
def support_remote_url_install(self):
if self._magic_uri:
return False