@@ -192,11 +192,14 @@ def fetch_all_guests(self):
192
192
self ._fetch_cache [key ] = self ._fetch_all_guests_raw ()
193
193
return self ._fetch_cache [key ][:]
194
194
195
+ def _build_pool_raw (self , poolobj ):
196
+ return StoragePool (weakref .ref (self ),
197
+ parsexml = poolobj .XMLDesc (0 ))
198
+
195
199
def _fetch_all_pools_raw (self ):
196
200
ignore , ignore , ret = pollhelpers .fetch_pools (
197
201
self , {}, lambda obj , ignore : obj )
198
- return [StoragePool (weakref .ref (self ), parsexml = obj .XMLDesc (0 ))
199
- for obj in ret ]
202
+ return [self ._build_pool_raw (poolobj ) for poolobj in ret ]
200
203
201
204
def fetch_all_pools (self ):
202
205
"""
@@ -210,23 +213,27 @@ def fetch_all_pools(self):
210
213
self ._fetch_cache [key ] = self ._fetch_all_pools_raw ()
211
214
return self ._fetch_cache [key ][:]
212
215
213
- def _fetch_all_vols_raw (self ):
216
+ def _fetch_vols_raw (self , poolxmlobj ):
214
217
ret = []
215
- for xmlobj in self .fetch_all_pools ():
216
- pool = self . _libvirtconn . storagePoolLookupByName ( xmlobj . name )
217
- if pool . info ()[ 0 ] != libvirt . VIR_STORAGE_POOL_RUNNING :
218
- continue
219
-
220
- ignore , ignore , vols = pollhelpers . fetch_volumes (
221
- self , pool , {}, lambda obj , ignore : obj )
222
-
223
- for vol in vols :
224
- try :
225
- xml = vol . XMLDesc ( 0 )
226
- ret . append ( StorageVolume ( weakref . ref ( self ), parsexml = xml ))
227
- except Exception as e :
228
- logging . debug ( "Fetching volume XML failed: %s" , e )
218
+ pool = self ._libvirtconn . storagePoolLookupByName ( poolxmlobj . name )
219
+ if pool . info ()[ 0 ] != libvirt . VIR_STORAGE_POOL_RUNNING :
220
+ return ret
221
+
222
+ ignore , ignore , vols = pollhelpers . fetch_volumes (
223
+ self , pool , {}, lambda obj , ignore : obj )
224
+
225
+ for vol in vols :
226
+ try :
227
+ xml = vol . XMLDesc ( 0 )
228
+ ret . append ( StorageVolume ( weakref . ref ( self ), parsexml = xml ) )
229
+ except Exception as e :
230
+ logging . debug ( "Fetching volume XML failed: %s" , e )
231
+ return ret
229
232
233
+ def _fetch_all_vols_raw (self ):
234
+ ret = []
235
+ for poolxmlobj in self .fetch_all_pools ():
236
+ ret .extend (self ._fetch_vols_raw (poolxmlobj ))
230
237
return ret
231
238
232
239
def fetch_all_vols (self ):
@@ -241,6 +248,26 @@ def fetch_all_vols(self):
241
248
self ._fetch_cache [key ] = self ._fetch_all_vols_raw ()
242
249
return self ._fetch_cache [key ][:]
243
250
251
+ def cache_new_pool (self , poolobj ):
252
+ """
253
+ Insert the passed poolobj into our cache
254
+ """
255
+ if self .cb_cache_new_pool :
256
+ # pylint: disable=not-callable
257
+ return self .cb_cache_new_pool (poolobj )
258
+
259
+ # Make sure cache is primed
260
+ if self ._FETCH_KEY_POOLS not in self ._fetch_cache :
261
+ # Nothing cached yet, so next poll will pull in latest bits,
262
+ # so there's nothing to do
263
+ return
264
+
265
+ poollist = self ._fetch_cache [self ._FETCH_KEY_POOLS ]
266
+ poolxmlobj = self ._build_pool_raw (poolobj )
267
+ poollist .append (poolxmlobj )
268
+ vollist = self ._fetch_cache [self ._FETCH_KEY_VOLS ]
269
+ vollist .extend (self ._fetch_vols_raw (poolxmlobj ))
270
+
244
271
def _fetch_all_nodedevs_raw (self ):
245
272
ignore , ignore , ret = pollhelpers .fetch_nodedevs (
246
273
self , {}, lambda obj , ignore : obj )
0 commit comments