mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-02-09 23:15:46 -06:00
pollhelpers: Add fetch_volumes helper
That does the listAllVolumes support check to speed us up a bit.
This commit is contained in:
parent
ce9f8ee24e
commit
52e4976462
@ -22,6 +22,7 @@
|
||||
from gi.repository import GObject
|
||||
# pylint: enable=E0611
|
||||
|
||||
from virtinst import pollhelpers
|
||||
from virtinst import StoragePool, StorageVolume
|
||||
from virtinst import util
|
||||
|
||||
@ -191,19 +192,14 @@ class vmmStoragePool(vmmLibvirtObject):
|
||||
self._volumes = {}
|
||||
return
|
||||
|
||||
vols = self._backend.listVolumes()
|
||||
new_vol_list = {}
|
||||
(ignore, new, allvols) = pollhelpers.fetch_volumes(
|
||||
self.conn.get_backend(), self.get_backend(), self._volumes.copy(),
|
||||
lambda obj, key: vmmStorageVolume(self.conn, obj, key))
|
||||
|
||||
for volname in vols:
|
||||
if volname in self._volumes:
|
||||
new_vol_list[volname] = self._volumes[volname]
|
||||
if refresh:
|
||||
new_vol_list[volname].refresh_xml()
|
||||
else:
|
||||
new_vol_list[volname] = vmmStorageVolume(self.conn,
|
||||
self._backend.storageVolLookupByName(volname),
|
||||
volname)
|
||||
self._volumes = new_vol_list
|
||||
for volname in allvols:
|
||||
if volname not in new and refresh:
|
||||
allvols[volname].refresh_xml()
|
||||
self._volumes = allvols
|
||||
|
||||
|
||||
#################
|
||||
|
@ -216,11 +216,10 @@ class VirtualConnection(object):
|
||||
ret = []
|
||||
for xmlobj in self.fetch_all_pools():
|
||||
pool = self._libvirtconn.storagePoolLookupByName(xmlobj.name)
|
||||
# XXX: Should implement pollhelpers support for listAllVolumes
|
||||
for volname in pool.listVolumes():
|
||||
vol = pool.storageVolLookupByName(volname)
|
||||
ret.append(StorageVolume(weakref.ref(self),
|
||||
parsexml=vol.XMLDesc(0)))
|
||||
ignore, ignore, vols = pollhelpers.fetch_volumes(
|
||||
self, pool, {}, lambda obj, ignore: obj)
|
||||
ret += [StorageVolume(weakref.ref(self), parsexml=obj.XMLDesc(0))
|
||||
for obj in vols.values()]
|
||||
|
||||
if self.cache_object_fetch:
|
||||
self._fetch_cache[key] = ret
|
||||
|
@ -141,6 +141,23 @@ def fetch_pools(backend, origmap, build_func):
|
||||
lookup_func, build_func)
|
||||
|
||||
|
||||
def fetch_volumes(backend, pool, origmap, build_func):
|
||||
name = "volume"
|
||||
|
||||
if backend.check_pool_support(pool,
|
||||
backend.SUPPORT_POOL_LISTALLVOLUMES):
|
||||
return _new_poll_helper(origmap, name,
|
||||
pool.listAllVolumes,
|
||||
"name", build_func)
|
||||
else:
|
||||
active_list = pool.listVolumes
|
||||
inactive_list = lambda: []
|
||||
lookup_func = pool.storageVolLookupByName
|
||||
return _old_poll_helper(origmap, name,
|
||||
active_list, inactive_list,
|
||||
lookup_func, build_func)
|
||||
|
||||
|
||||
def fetch_interfaces(backend, origmap, build_func):
|
||||
name = "interface"
|
||||
|
||||
|
@ -352,6 +352,8 @@ SUPPORT_DOMAIN_GET_METADATA = _make(function="virDomain.metadata",
|
||||
SUPPORT_POOL_CREATEVOLFROM = _make(function="virStoragePool.createXMLFrom",
|
||||
version=6004)
|
||||
SUPPORT_POOL_ISACTIVE = _make(function="virStoragePool.isActive", args=())
|
||||
SUPPORT_POOL_LISTALLVOLUMES = _make(function="virStoragePool.listAllVolumes",
|
||||
args=())
|
||||
|
||||
|
||||
# Interface checks
|
||||
|
Loading…
Reference in New Issue
Block a user