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