virt-manager/virtinst/pollhelpers.py
Cole Robinson e45a2228dc objects: Erase the notion of connkey
Make it explicit that all uses of this is actually the object
name. We already leaked this abstraction in several places so better
to make it explicit. This also communicates to users that this is a
field that is not immutable so it shouldn't be used as a unique key

Signed-off-by: Cole Robinson <crobinso@redhat.com>
2020-09-01 14:27:11 -04:00

73 lines
2.1 KiB
Python

#
# Copyright (C) 2013 Red Hat, Inc.
#
# This work is licensed under the GNU GPLv2 or later.
# See the COPYING file in the top-level directory.
#
from .logger import log
def _new_poll_helper(origmap, typename, list_cb, build_cb, support_cb):
"""
Helper for new style listAll* APIs
"""
current = {}
new = {}
objs = []
try:
if support_cb():
objs = list_cb()
except Exception as e: # pragma: no cover
log.debug("Unable to list all %ss: %s", typename, e)
for obj in objs:
name = obj.name()
if name not in origmap:
# Object is brand new this period
current[name] = build_cb(obj, name)
new[name] = current[name]
else:
# Previously known object
current[name] = origmap[name]
del(origmap[name])
return (list(origmap.values()), list(new.values()), list(current.values()))
def fetch_nets(backend, origmap, build_cb):
typename = "network"
list_cb = backend.listAllNetworks
support_cb = backend.support.conn_network
return _new_poll_helper(origmap, typename, list_cb, build_cb, support_cb)
def fetch_pools(backend, origmap, build_cb):
typename = "pool"
list_cb = backend.listAllStoragePools
support_cb = backend.support.conn_storage
return _new_poll_helper(origmap, typename, list_cb, build_cb, support_cb)
def fetch_volumes(backend, pool, origmap, build_cb):
typename = "volume"
list_cb = pool.listAllVolumes
support_cb = backend.support.conn_storage
return _new_poll_helper(origmap, typename, list_cb, build_cb, support_cb)
def fetch_nodedevs(backend, origmap, build_cb):
typename = "nodedev"
list_cb = backend.listAllDevices
support_cb = backend.support.conn_nodedev
return _new_poll_helper(origmap, typename, list_cb, build_cb, support_cb)
def fetch_vms(backend, origmap, build_cb):
typename = "domain"
list_cb = backend.listAllDomains
support_cb = backend.support.conn_domain
return _new_poll_helper(origmap, typename, list_cb, build_cb, support_cb)