@@ -215,6 +215,8 @@ def __init__(self, uri):
215
215
self ._network_cb_ids = []
216
216
self .using_storage_pool_events = False
217
217
self ._storage_pool_cb_ids = []
218
+ self .using_node_device_events = False
219
+ self ._node_device_cb_ids = []
218
220
219
221
self ._xml_flags = {}
220
222
@@ -796,6 +798,17 @@ def _storage_pool_lifecycle_event(self, conn, pool,
796
798
else :
797
799
self .schedule_priority_tick (pollpool = True , force = True )
798
800
801
+ def _node_device_lifecycle_event (self , conn , dev ,
802
+ event , reason , userdata ):
803
+ ignore = conn
804
+ ignore = userdata
805
+
806
+ name = dev .name ()
807
+ logging .debug ("node device lifecycle event: device=%s event=%s "
808
+ "reason=%s" , name , event , reason )
809
+
810
+ self .schedule_priority_tick (pollnodedev = True , force = True )
811
+
799
812
def _add_conn_events (self ):
800
813
if not self .check_support (support .SUPPORT_CONN_WORKING_XEN_EVENTS ):
801
814
return
@@ -866,6 +879,20 @@ def _add_domain_xml_event(eventid, typestr):
866
879
self .using_storage_pool_events = False
867
880
logging .debug ("Error registering storage pool events: %s" , e )
868
881
882
+ try :
883
+ if FORCE_DISABLE_EVENTS :
884
+ raise RuntimeError ("FORCE_DISABLE_EVENTS = True" )
885
+
886
+ eventid = getattr (libvirt , "VIR_NODE_DEVICE_EVENT_ID_LIFECYCLE" , 0 )
887
+ self ._node_device_cb_ids .append (
888
+ self .get_backend ().nodeDeviceEventRegisterAny (
889
+ None , eventid , self ._node_device_lifecycle_event , None ))
890
+ self .using_node_device_events = True
891
+ logging .debug ("Using node device events" )
892
+ except Exception , e :
893
+ self .using_network_events = False
894
+ logging .debug ("Error registering node device events: %s" , e )
895
+
869
896
870
897
######################################
871
898
# Connection closing/opening methods #
@@ -888,13 +915,16 @@ def close(self):
888
915
self ._backend .networkEventDeregisterAny (eid )
889
916
for eid in self ._storage_pool_cb_ids :
890
917
self ._backend .storagePoolEventDeregisterAny (eid )
918
+ for eid in self ._node_device_cb_ids :
919
+ self ._backend .nodeDeviceEventDeregisterAny (eid )
891
920
except :
892
921
logging .debug ("Failed to deregister events in conn cleanup" ,
893
922
exc_info = True )
894
923
finally :
895
924
self ._domain_cb_ids = []
896
925
self ._network_cb_ids = []
897
926
self ._storage_pool_cb_ids = []
927
+ self ._node_device_cb_ids = []
898
928
899
929
self ._backend .close ()
900
930
self ._stats = []
@@ -1227,6 +1257,8 @@ def _tick(self, stats_update=False,
1227
1257
pollnet = False
1228
1258
if self .using_storage_pool_events and not force :
1229
1259
pollpool = False
1260
+ if self .using_node_device_events and not force :
1261
+ pollnodedev = False
1230
1262
1231
1263
self ._hostinfo = self ._backend .getInfo ()
1232
1264
0 commit comments