2013-07-08 01:53:37 +08:00
|
|
|
#
|
|
|
|
# Copyright (C) 2013 Red Hat, Inc.
|
|
|
|
#
|
2018-04-04 21:35:41 +08:00
|
|
|
# This work is licensed under the GNU GPLv2 or later.
|
2018-03-21 03:00:02 +08:00
|
|
|
# See the COPYING file in the top-level directory.
|
2013-07-08 01:53:37 +08:00
|
|
|
#
|
|
|
|
|
2019-06-17 09:12:39 +08:00
|
|
|
from .logger import log
|
2013-07-08 01:53:37 +08:00
|
|
|
|
|
|
|
|
2020-01-25 04:46:02 +08:00
|
|
|
def _new_poll_helper(origmap, typename, list_cb, build_cb, support_cb):
|
2013-07-08 01:53:37 +08:00
|
|
|
"""
|
|
|
|
Helper for new style listAll* APIs
|
|
|
|
"""
|
|
|
|
current = {}
|
|
|
|
new = {}
|
|
|
|
objs = []
|
|
|
|
|
|
|
|
try:
|
2020-01-25 04:46:02 +08:00
|
|
|
if support_cb():
|
|
|
|
objs = list_cb()
|
2020-01-27 17:49:46 +08:00
|
|
|
except Exception as e: # pragma: no cover
|
2019-06-17 09:12:39 +08:00
|
|
|
log.debug("Unable to list all %ss: %s", typename, e)
|
2013-07-08 01:53:37 +08:00
|
|
|
|
|
|
|
for obj in objs:
|
2020-09-02 00:35:26 +08:00
|
|
|
name = obj.name()
|
2013-07-08 01:53:37 +08:00
|
|
|
|
2020-09-02 00:35:26 +08:00
|
|
|
if name not in origmap:
|
2013-07-08 01:53:37 +08:00
|
|
|
# Object is brand new this period
|
2020-09-02 00:35:26 +08:00
|
|
|
current[name] = build_cb(obj, name)
|
|
|
|
new[name] = current[name]
|
2013-07-08 01:53:37 +08:00
|
|
|
else:
|
|
|
|
# Previously known object
|
2020-09-02 00:35:26 +08:00
|
|
|
current[name] = origmap[name]
|
|
|
|
del(origmap[name])
|
2013-07-08 01:53:37 +08:00
|
|
|
|
2017-10-11 19:35:46 +08:00
|
|
|
return (list(origmap.values()), list(new.values()), list(current.values()))
|
2013-07-08 01:53:37 +08:00
|
|
|
|
|
|
|
|
2020-01-25 04:46:02 +08:00
|
|
|
def fetch_nets(backend, origmap, build_cb):
|
2020-09-02 00:35:26 +08:00
|
|
|
typename = "network"
|
2020-01-25 04:46:02 +08:00
|
|
|
list_cb = backend.listAllNetworks
|
|
|
|
support_cb = backend.support.conn_network
|
2020-09-02 00:35:26 +08:00
|
|
|
return _new_poll_helper(origmap, typename, list_cb, build_cb, support_cb)
|
2013-07-08 01:53:37 +08:00
|
|
|
|
|
|
|
|
2020-01-25 04:46:02 +08:00
|
|
|
def fetch_pools(backend, origmap, build_cb):
|
2020-09-02 00:35:26 +08:00
|
|
|
typename = "pool"
|
2020-01-25 04:46:02 +08:00
|
|
|
list_cb = backend.listAllStoragePools
|
|
|
|
support_cb = backend.support.conn_storage
|
2020-09-02 00:35:26 +08:00
|
|
|
return _new_poll_helper(origmap, typename, list_cb, build_cb, support_cb)
|
2013-07-08 01:53:37 +08:00
|
|
|
|
|
|
|
|
2020-01-25 04:46:02 +08:00
|
|
|
def fetch_volumes(backend, pool, origmap, build_cb):
|
2020-09-02 00:35:26 +08:00
|
|
|
typename = "volume"
|
2020-01-25 04:46:02 +08:00
|
|
|
list_cb = pool.listAllVolumes
|
|
|
|
support_cb = backend.support.conn_storage
|
2020-09-02 00:35:26 +08:00
|
|
|
return _new_poll_helper(origmap, typename, list_cb, build_cb, support_cb)
|
2013-09-29 21:31:39 +08:00
|
|
|
|
|
|
|
|
2020-01-25 04:46:02 +08:00
|
|
|
def fetch_nodedevs(backend, origmap, build_cb):
|
2020-09-02 00:35:26 +08:00
|
|
|
typename = "nodedev"
|
2020-01-25 04:46:02 +08:00
|
|
|
list_cb = backend.listAllDevices
|
|
|
|
support_cb = backend.support.conn_nodedev
|
2020-09-02 00:35:26 +08:00
|
|
|
return _new_poll_helper(origmap, typename, list_cb, build_cb, support_cb)
|
2013-07-08 01:53:37 +08:00
|
|
|
|
|
|
|
|
2020-01-25 04:46:02 +08:00
|
|
|
def fetch_vms(backend, origmap, build_cb):
|
2020-09-02 00:35:26 +08:00
|
|
|
typename = "domain"
|
2020-01-25 04:46:02 +08:00
|
|
|
list_cb = backend.listAllDomains
|
|
|
|
support_cb = backend.support.conn_domain
|
2020-09-02 00:35:26 +08:00
|
|
|
return _new_poll_helper(origmap, typename, list_cb, build_cb, support_cb)
|