@@ -71,7 +71,6 @@ class ManAddrConst:
71
71
"""
72
72
man_addr_oid = (1 , 3 , 6 , 1 , 2 , 1 , 2 , 2 , 1 , 1 )
73
73
74
-
75
74
def poll_lldp_entry_updates (pubsub ):
76
75
ret = None , None , None
77
76
msg = pubsub .get_message ()
@@ -157,7 +156,7 @@ def __init__(self):
157
156
# cache of port data
158
157
# { if_name -> { 'key': 'value' } }
159
158
self .loc_port_data = {}
160
- self .pubsub = [None ] * len (self .db_conn )
159
+ self .pubsub = [None ] * len (self .db_conn )
161
160
162
161
def reinit_data (self ):
163
162
"""
@@ -222,16 +221,10 @@ def get_next(self, sub_id):
222
221
return None
223
222
return self .if_range [right ]
224
223
225
- def _update_per_namespace_data (self , db_conn , pubsub ):
224
+ def _update_per_namespace_data (self , pubsub ):
226
225
"""
227
226
Listen to updates in APP DB, update local cache
228
227
"""
229
- if not pubsub :
230
- redis_client = db_conn .get_redis_client (db_conn .APPL_DB )
231
- db = db_conn .get_dbid (db_conn .APPL_DB )
232
- pubsub = redis_client .pubsub ()
233
- pubsub .psubscribe ("__keyspace@{}__:{}" .format (db , mibs .lldp_entry_table (b'*' )))
234
-
235
228
while True :
236
229
data , interface , if_id = poll_lldp_entry_updates (pubsub )
237
230
@@ -243,7 +236,10 @@ def _update_per_namespace_data(self, db_conn, pubsub):
243
236
244
237
def update_data (self ):
245
238
for i in range (len (self .db_conn )):
246
- self ._update_per_namespace_data (self .db_conn [i ], self .pubsub [i ])
239
+ if not self .pubsub [i ]:
240
+ pattern = mibs .lldp_entry_table (b'*' )
241
+ self .pubsub [i ] = mibs .get_redis_pubsub (self .db_conn [i ], self .db_conn [i ].APPL_DB , pattern )
242
+ self ._update_per_namespace_data (self .pubsub [i ])
247
243
248
244
def local_port_num (self , sub_id ):
249
245
if len (sub_id ) == 0 :
@@ -307,7 +303,7 @@ def reinit_data(self):
307
303
self .mgmt_ip_str = None
308
304
309
305
# establish connection to application database.
310
- self .db_conn .connect (mibs .APPL_DB )
306
+ self .db_conn .connect (mibs .APPL_DB )
311
307
mgmt_ip_bytes = self .db_conn .get (mibs .APPL_DB , mibs .LOC_CHASSIS_TABLE , b'lldp_loc_man_addr' )
312
308
313
309
if not mgmt_ip_bytes :
@@ -488,7 +484,7 @@ class LLDPRemManAddrUpdater(MIBUpdater):
488
484
def __init__ (self ):
489
485
super ().__init__ ()
490
486
491
- self .db_conn = Namespace .init_namespace_dbs ()
487
+ self .db_conn = Namespace .init_namespace_dbs ()
492
488
# establish connection to application database.
493
489
Namespace .connect_all_dbs (self .db_conn , mibs .APPL_DB )
494
490
self .if_range = []
@@ -536,16 +532,10 @@ def update_rem_if_mgmt(self, if_oid, if_name):
536
532
return
537
533
self .if_range .sort ()
538
534
539
- def _update_per_namespace_data (self , db_conn , pubsub ):
535
+ def _update_per_namespace_data (self , pubsub ):
540
536
"""
541
537
Listen to updates in APP DB, update local cache
542
538
"""
543
- if not pubsub :
544
- redis_client = db_conn .get_redis_client (db_conn .APPL_DB )
545
- db = db_conn .get_dbid (db_conn .APPL_DB )
546
- pubsub = redis_client .pubsub ()
547
- pubsub .psubscribe ("__keyspace@{}__:{}" .format (db , mibs .lldp_entry_table (b'*' )))
548
-
549
539
while True :
550
540
data , interface , if_index = poll_lldp_entry_updates (pubsub )
551
541
@@ -561,7 +551,10 @@ def _update_per_namespace_data(self, db_conn, pubsub):
561
551
562
552
def update_data (self ):
563
553
for i in range (len (self .db_conn )):
564
- self ._update_per_namespace_data (self .db_conn [i ], self .pubsub [i ])
554
+ if not self .pubsub [i ]:
555
+ pattern = mibs .lldp_entry_table (b'*' )
556
+ self .pubsub [i ] = mibs .get_redis_pubsub (self .db_conn [i ], self .db_conn [i ].APPL_DB , pattern )
557
+ self ._update_per_namespace_data (self .pubsub [i ])
565
558
566
559
567
560
def reinit_data (self ):
0 commit comments