mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-01-08 21:18:04 +03:00
pollhelpers: Streamline usage a bit
* Explicitly define the build 'cb', don't use lambda * Rename pollhelpers arguments, clarifying use of cb * Check support status in pollhelpers * Move 'dopoll' checking up a level in vmmConnection Signed-off-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
parent
3ad646fef1
commit
419f8cd31b
@ -1100,40 +1100,35 @@ class vmmConnection(vmmGObject):
|
||||
if self._init_object_count <= 0:
|
||||
self._init_object_event.set()
|
||||
|
||||
def _update_nets(self, dopoll):
|
||||
def _update_nets(self,):
|
||||
keymap = dict((o.get_connkey(), o) for o in self.list_nets())
|
||||
if not dopoll or not self.support.conn_network():
|
||||
return [], [], list(keymap.values())
|
||||
return pollhelpers.fetch_nets(self._backend, keymap,
|
||||
(lambda obj, key: vmmNetwork(self, obj, key)))
|
||||
def cb(obj, key):
|
||||
return vmmNetwork(self, obj, key)
|
||||
return pollhelpers.fetch_nets(self._backend, keymap, cb)
|
||||
|
||||
def _update_pools(self, dopoll):
|
||||
def _update_pools(self):
|
||||
keymap = dict((o.get_connkey(), o) for o in self.list_pools())
|
||||
if not dopoll or not self.support.conn_storage():
|
||||
return [], [], list(keymap.values())
|
||||
return pollhelpers.fetch_pools(self._backend, keymap,
|
||||
(lambda obj, key: vmmStoragePool(self, obj, key)))
|
||||
def cb(obj, key):
|
||||
return vmmStoragePool(self, obj, key)
|
||||
return pollhelpers.fetch_pools(self._backend, keymap, cb)
|
||||
|
||||
def _update_interfaces(self, dopoll):
|
||||
def _update_interfaces(self):
|
||||
keymap = dict((o.get_connkey(), o) for o in self.list_interfaces())
|
||||
if not dopoll or not self.support.conn_interface():
|
||||
return [], [], list(keymap.values())
|
||||
return pollhelpers.fetch_interfaces(self._backend, keymap,
|
||||
(lambda obj, key: vmmInterface(self, obj, key)))
|
||||
def cb(obj, key):
|
||||
return vmmInterface(self, obj, key)
|
||||
return pollhelpers.fetch_interfaces(self._backend, keymap, cb)
|
||||
|
||||
def _update_nodedevs(self, dopoll):
|
||||
def _update_nodedevs(self):
|
||||
keymap = dict((o.get_connkey(), o) for o in self.list_nodedevs())
|
||||
if not dopoll or not self.support.conn_nodedev():
|
||||
return [], [], list(keymap.values())
|
||||
return pollhelpers.fetch_nodedevs(self._backend, keymap,
|
||||
(lambda obj, key: vmmNodeDevice(self, obj, key)))
|
||||
def cb(obj, key):
|
||||
return vmmNodeDevice(self, obj, key)
|
||||
return pollhelpers.fetch_nodedevs(self._backend, keymap, cb)
|
||||
|
||||
def _update_vms(self, dopoll):
|
||||
def _update_vms(self):
|
||||
keymap = dict((o.get_connkey(), o) for o in self.list_vms())
|
||||
if not dopoll:
|
||||
return [], [], list(keymap.values())
|
||||
return pollhelpers.fetch_vms(self._backend, keymap,
|
||||
(lambda obj, key: vmmDomain(self, obj, key)))
|
||||
def cb(obj, key):
|
||||
return vmmDomain(self, obj, key)
|
||||
return pollhelpers.fetch_vms(self._backend, keymap, cb)
|
||||
|
||||
def _poll(self, initial_poll,
|
||||
pollvm, pollnet, pollpool, polliface, pollnodedev):
|
||||
@ -1144,8 +1139,11 @@ class vmmConnection(vmmGObject):
|
||||
gone_objects = []
|
||||
preexisting_objects = []
|
||||
|
||||
def _process_objects(polloutput):
|
||||
gone, new, master = polloutput
|
||||
def _process_objects(pollcb, dopoll):
|
||||
if not dopoll:
|
||||
return []
|
||||
|
||||
gone, new, master = pollcb()
|
||||
|
||||
if initial_poll:
|
||||
self._init_object_count += len(new)
|
||||
@ -1155,11 +1153,11 @@ class vmmConnection(vmmGObject):
|
||||
new = [n for n in new if not self._objects.in_blacklist(n)]
|
||||
return new
|
||||
|
||||
new_vms = _process_objects(self._update_vms(pollvm))
|
||||
new_nets = _process_objects(self._update_nets(pollnet))
|
||||
new_pools = _process_objects(self._update_pools(pollpool))
|
||||
new_ifaces = _process_objects(self._update_interfaces(polliface))
|
||||
new_nodedevs = _process_objects(self._update_nodedevs(pollnodedev))
|
||||
new_vms = _process_objects(self._update_vms, pollvm)
|
||||
new_nets = _process_objects(self._update_nets, pollnet)
|
||||
new_pools = _process_objects(self._update_pools, pollpool)
|
||||
new_ifaces = _process_objects(self._update_interfaces, polliface)
|
||||
new_nodedevs = _process_objects(self._update_nodedevs, pollnodedev)
|
||||
|
||||
# Kick off one thread per object type to handle the initial
|
||||
# XML fetching. Going any more fine grained then this probably
|
||||
|
@ -271,9 +271,10 @@ class vmmStoragePool(vmmLibvirtObject):
|
||||
return
|
||||
|
||||
keymap = dict((o.get_connkey(), o) for o in self._volumes or [])
|
||||
def cb(obj, key):
|
||||
return vmmStorageVolume(self.conn, obj, key)
|
||||
(ignore, ignore, allvols) = pollhelpers.fetch_volumes(
|
||||
self.conn.get_backend(), self.get_backend(), keymap,
|
||||
lambda obj, key: vmmStorageVolume(self.conn, obj, key))
|
||||
self.conn.get_backend(), self.get_backend(), keymap, cb)
|
||||
self._volumes = allvols
|
||||
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
from .logger import log
|
||||
|
||||
|
||||
def _new_poll_helper(origmap, typename, listfunc, buildfunc):
|
||||
def _new_poll_helper(origmap, typename, list_cb, build_cb, support_cb):
|
||||
"""
|
||||
Helper for new style listAll* APIs
|
||||
"""
|
||||
@ -17,7 +17,8 @@ def _new_poll_helper(origmap, typename, listfunc, buildfunc):
|
||||
objs = []
|
||||
|
||||
try:
|
||||
objs = listfunc()
|
||||
if support_cb():
|
||||
objs = list_cb()
|
||||
except Exception as e:
|
||||
log.debug("Unable to list all %ss: %s", typename, e)
|
||||
|
||||
@ -26,7 +27,7 @@ def _new_poll_helper(origmap, typename, listfunc, buildfunc):
|
||||
|
||||
if connkey not in origmap:
|
||||
# Object is brand new this period
|
||||
current[connkey] = buildfunc(obj, connkey)
|
||||
current[connkey] = build_cb(obj, connkey)
|
||||
new[connkey] = current[connkey]
|
||||
else:
|
||||
# Previously known object
|
||||
@ -36,37 +37,43 @@ def _new_poll_helper(origmap, typename, listfunc, buildfunc):
|
||||
return (list(origmap.values()), list(new.values()), list(current.values()))
|
||||
|
||||
|
||||
def fetch_nets(backend, origmap, build_func):
|
||||
def fetch_nets(backend, origmap, build_cb):
|
||||
name = "network"
|
||||
return _new_poll_helper(origmap, name,
|
||||
backend.listAllNetworks, build_func)
|
||||
list_cb = backend.listAllNetworks
|
||||
support_cb = backend.support.conn_network
|
||||
return _new_poll_helper(origmap, name, list_cb, build_cb, support_cb)
|
||||
|
||||
|
||||
def fetch_pools(backend, origmap, build_func):
|
||||
def fetch_pools(backend, origmap, build_cb):
|
||||
name = "pool"
|
||||
return _new_poll_helper(origmap, name,
|
||||
backend.listAllStoragePools, build_func)
|
||||
list_cb = backend.listAllStoragePools
|
||||
support_cb = backend.support.conn_storage
|
||||
return _new_poll_helper(origmap, name, list_cb, build_cb, support_cb)
|
||||
|
||||
|
||||
def fetch_volumes(backend, pool, origmap, build_func):
|
||||
def fetch_volumes(backend, pool, origmap, build_cb):
|
||||
name = "volume"
|
||||
return _new_poll_helper(origmap, name,
|
||||
pool.listAllVolumes, build_func)
|
||||
list_cb = pool.listAllVolumes
|
||||
support_cb = backend.support.conn_storage
|
||||
return _new_poll_helper(origmap, name, list_cb, build_cb, support_cb)
|
||||
|
||||
|
||||
def fetch_interfaces(backend, origmap, build_func):
|
||||
def fetch_interfaces(backend, origmap, build_cb):
|
||||
name = "interface"
|
||||
return _new_poll_helper(origmap, name,
|
||||
backend.listAllInterfaces, build_func)
|
||||
list_cb = backend.listAllInterfaces
|
||||
support_cb = backend.support.conn_interface
|
||||
return _new_poll_helper(origmap, name, list_cb, build_cb, support_cb)
|
||||
|
||||
|
||||
def fetch_nodedevs(backend, origmap, build_func):
|
||||
def fetch_nodedevs(backend, origmap, build_cb):
|
||||
name = "nodedev"
|
||||
return _new_poll_helper(origmap, name,
|
||||
backend.listAllDevices, build_func)
|
||||
list_cb = backend.listAllDevices
|
||||
support_cb = backend.support.conn_nodedev
|
||||
return _new_poll_helper(origmap, name, list_cb, build_cb, support_cb)
|
||||
|
||||
|
||||
def fetch_vms(backend, origmap, build_func):
|
||||
def fetch_vms(backend, origmap, build_cb):
|
||||
name = "domain"
|
||||
return _new_poll_helper(origmap, name,
|
||||
backend.listAllDomains, build_func)
|
||||
list_cb = backend.listAllDomains
|
||||
support_cb = backend.support.conn_domain
|
||||
return _new_poll_helper(origmap, name, list_cb, build_cb, support_cb)
|
||||
|
Loading…
Reference in New Issue
Block a user