mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-02-25 18:55:27 -06:00
VirtualConnection: Add option to cache fetch_* results
We use this in the CLI tools since there's no point in repeatedly updating the VM list if the whole process only takes a few seconds.
This commit is contained in:
parent
9d560f7d9a
commit
d386ba5d62
@ -237,6 +237,7 @@ def getConnection(uri):
|
|||||||
logging.debug("Requesting libvirt URI %s", (uri or "default"))
|
logging.debug("Requesting libvirt URI %s", (uri or "default"))
|
||||||
conn = virtinst.VirtualConnection(uri)
|
conn = virtinst.VirtualConnection(uri)
|
||||||
conn.open(_do_creds_authname)
|
conn.open(_do_creds_authname)
|
||||||
|
conn.cache_object_fetch = True
|
||||||
logging.debug("Received libvirt URI %s", conn.uri)
|
logging.debug("Received libvirt URI %s", conn.uri)
|
||||||
|
|
||||||
return conn
|
return conn
|
||||||
|
@ -63,6 +63,12 @@ class VirtualConnection(object):
|
|||||||
self._conn_version = None
|
self._conn_version = None
|
||||||
|
|
||||||
self._support_cache = {}
|
self._support_cache = {}
|
||||||
|
self._fetch_cache = {}
|
||||||
|
|
||||||
|
# Setting this means we only do fetch_all* once and just carry
|
||||||
|
# the result. For the virt-* CLI tools this ensures any revalidation
|
||||||
|
# isn't hammering the connection over and over
|
||||||
|
self.cache_object_fetch = False
|
||||||
|
|
||||||
|
|
||||||
##############
|
##############
|
||||||
@ -97,6 +103,7 @@ class VirtualConnection(object):
|
|||||||
def close(self):
|
def close(self):
|
||||||
self._libvirtconn = None
|
self._libvirtconn = None
|
||||||
self._uri = None
|
self._uri = None
|
||||||
|
self._fetch_cache = {}
|
||||||
|
|
||||||
def invalidate_caps(self):
|
def invalidate_caps(self):
|
||||||
self._caps = None
|
self._caps = None
|
||||||
@ -120,14 +127,28 @@ class VirtualConnection(object):
|
|||||||
self._libvirtconn = conn
|
self._libvirtconn = conn
|
||||||
|
|
||||||
def fetch_all_guests(self):
|
def fetch_all_guests(self):
|
||||||
|
key = "vms"
|
||||||
|
if key in self._fetch_cache:
|
||||||
|
return self._fetch_cache[key]
|
||||||
|
|
||||||
ignore, ignore, ret = pollhelpers.fetch_vms(self, {},
|
ignore, ignore, ret = pollhelpers.fetch_vms(self, {},
|
||||||
lambda obj, ignore: obj)
|
lambda obj, ignore: obj)
|
||||||
return ret.values()
|
ret = ret.values()
|
||||||
|
if self.cache_object_fetch:
|
||||||
|
self._fetch_cache[key] = ret
|
||||||
|
return ret
|
||||||
|
|
||||||
def fetch_all_pools(self):
|
def fetch_all_pools(self):
|
||||||
|
key = "pools"
|
||||||
|
if key in self._fetch_cache:
|
||||||
|
return self._fetch_cache[key]
|
||||||
|
|
||||||
ignore, ignore, ret = pollhelpers.fetch_pools(self, {},
|
ignore, ignore, ret = pollhelpers.fetch_pools(self, {},
|
||||||
lambda obj, ignore: obj)
|
lambda obj, ignore: obj)
|
||||||
return ret.values()
|
ret = ret.values()
|
||||||
|
if self.cache_object_fetch:
|
||||||
|
self._fetch_cache[key] = ret
|
||||||
|
return ret
|
||||||
|
|
||||||
|
|
||||||
#########################
|
#########################
|
||||||
|
Loading…
Reference in New Issue
Block a user