@@ -275,7 +275,7 @@ def get_switch_name(config_db):
275
275
sys .exit (STATUS_FAIL )
276
276
277
277
278
- def create_json_dump_per_port_status (db , port_status_dict , muxcable_info_dict , muxcable_health_dict , asic_index , port ):
278
+ def create_json_dump_per_port_status (db , port_status_dict , muxcable_info_dict , muxcable_health_dict , muxcable_metrics_dict , asic_index , port ):
279
279
280
280
status_value = get_value_for_key_in_dict (muxcable_info_dict [asic_index ], port , "state" , "MUX_CABLE_TABLE" )
281
281
port_name = platform_sfputil_helper .get_interface_alias (port , db )
@@ -284,18 +284,32 @@ def create_json_dump_per_port_status(db, port_status_dict, muxcable_info_dict, m
284
284
health_value = get_value_for_key_in_dict (muxcable_health_dict [asic_index ], port , "state" , "MUX_LINKMGR_TABLE" )
285
285
port_status_dict ["MUX_CABLE" ][port_name ]["HEALTH" ] = health_value
286
286
287
+ last_switch_end_time = ""
288
+ if "linkmgrd_switch_standby_end" in muxcable_metrics_dict [asic_index ]:
289
+ last_switch_end_time = muxcable_metrics_dict [asic_index ].get ("linkmgrd_switch_standby_end" )
290
+ elif "linkmgrd_switch_active_end" in muxcable_metrics_dict [asic_index ]:
291
+ last_switch_end_time = muxcable_metrics_dict [asic_index ].get ("linkmgrd_switch_active_end" )
292
+ port_status_dict ["MUX_CABLE" ][port_name ]["LAST_SWITCHOVER_TIME" ] = last_switch_end_time
287
293
288
- def create_table_dump_per_port_status (db , print_data , muxcable_info_dict , muxcable_health_dict , asic_index , port ):
294
+ def create_table_dump_per_port_status (db , print_data , muxcable_info_dict , muxcable_health_dict , muxcable_metrics_dict , asic_index , port ):
289
295
290
296
print_port_data = []
291
297
292
298
status_value = get_value_for_key_in_dict (muxcable_info_dict [asic_index ], port , "state" , "MUX_CABLE_TABLE" )
293
299
#status_value = get_value_for_key_in_tbl(y_cable_asic_table, port, "status")
294
300
health_value = get_value_for_key_in_dict (muxcable_health_dict [asic_index ], port , "state" , "MUX_LINKMGR_TABLE" )
301
+
302
+ last_switch_end_time = ""
303
+ if "linkmgrd_switch_standby_end" in muxcable_metrics_dict [asic_index ]:
304
+ last_switch_end_time = muxcable_metrics_dict [asic_index ].get ("linkmgrd_switch_standby_end" )
305
+ elif "linkmgrd_switch_active_end" in muxcable_metrics_dict [asic_index ]:
306
+ last_switch_end_time = muxcable_metrics_dict [asic_index ].get ("linkmgrd_switch_active_end" )
307
+
295
308
port_name = platform_sfputil_helper .get_interface_alias (port , db )
296
309
print_port_data .append (port_name )
297
310
print_port_data .append (status_value )
298
311
print_port_data .append (health_value )
312
+ print_port_data .append (last_switch_end_time )
299
313
print_data .append (print_port_data )
300
314
301
315
@@ -336,9 +350,11 @@ def status(db, port, json_output):
336
350
337
351
port_table_keys = {}
338
352
port_health_table_keys = {}
353
+ port_metrics_table_keys = {}
339
354
per_npu_statedb = {}
340
355
muxcable_info_dict = {}
341
356
muxcable_health_dict = {}
357
+ muxcable_metrics_dict = {}
342
358
343
359
# Getting all front asic namespace and correspding config and state DB connector
344
360
@@ -352,6 +368,8 @@ def status(db, port, json_output):
352
368
per_npu_statedb [asic_id ].STATE_DB , 'MUX_CABLE_TABLE|*' )
353
369
port_health_table_keys [asic_id ] = per_npu_statedb [asic_id ].keys (
354
370
per_npu_statedb [asic_id ].STATE_DB , 'MUX_LINKMGR_TABLE|*' )
371
+ port_metrics_table_keys [asic_id ] = per_npu_statedb [asic_id ].keys (
372
+ per_npu_statedb [asic_id ].STATE_DB , 'MUX_METRICS_TABLE|*' )
355
373
356
374
if port is not None :
357
375
asic_index = None
@@ -371,27 +389,33 @@ def status(db, port, json_output):
371
389
per_npu_statedb [asic_index ].STATE_DB , 'MUX_CABLE_TABLE|{}' .format (port ))
372
390
muxcable_health_dict [asic_index ] = per_npu_statedb [asic_index ].get_all (
373
391
per_npu_statedb [asic_index ].STATE_DB , 'MUX_LINKMGR_TABLE|{}' .format (port ))
392
+ muxcable_metrics_dict [asic_index ] = per_npu_statedb [asic_index ].get_all (
393
+ per_npu_statedb [asic_index ].STATE_DB , 'MUX_METRICS_TABLE|{}' .format (port ))
374
394
if muxcable_info_dict [asic_index ] is not None :
375
395
logical_key = "MUX_CABLE_TABLE|{}" .format (port )
376
396
logical_health_key = "MUX_LINKMGR_TABLE|{}" .format (port )
397
+ logical_metrics_key = "MUX_METRICS_TABLE|{}" .format (port )
377
398
if logical_key in port_table_keys [asic_index ] and logical_health_key in port_health_table_keys [asic_index ]:
399
+
400
+ if logical_metrics_key not in port_metrics_table_keys [asic_index ]:
401
+ muxcable_metrics_dict [asic_index ] = {}
378
402
379
403
if json_output :
380
404
port_status_dict = {}
381
405
port_status_dict ["MUX_CABLE" ] = {}
382
406
383
407
create_json_dump_per_port_status (db , port_status_dict , muxcable_info_dict ,
384
- muxcable_health_dict , asic_index , port )
408
+ muxcable_health_dict , muxcable_metrics_dict , asic_index , port )
385
409
386
410
click .echo ("{}" .format (json .dumps (port_status_dict , indent = 4 )))
387
411
sys .exit (STATUS_SUCCESSFUL )
388
412
else :
389
413
print_data = []
390
414
391
415
create_table_dump_per_port_status (db , print_data , muxcable_info_dict ,
392
- muxcable_health_dict , asic_index , port )
416
+ muxcable_health_dict , muxcable_metrics_dict , asic_index , port )
393
417
394
- headers = ['PORT' , 'STATUS' , 'HEALTH' ]
418
+ headers = ['PORT' , 'STATUS' , 'HEALTH' , 'LAST_SWITCHOVER_TIME' ]
395
419
396
420
click .echo (tabulate (print_data , headers = headers ))
397
421
sys .exit (STATUS_SUCCESSFUL )
@@ -416,8 +440,12 @@ def status(db, port, json_output):
416
440
per_npu_statedb [asic_id ].STATE_DB , 'MUX_CABLE_TABLE|{}' .format (port ))
417
441
muxcable_health_dict [asic_id ] = per_npu_statedb [asic_id ].get_all (
418
442
per_npu_statedb [asic_id ].STATE_DB , 'MUX_LINKMGR_TABLE|{}' .format (port ))
443
+ muxcable_metrics_dict [asic_id ] = per_npu_statedb [asic_id ].get_all (
444
+ per_npu_statedb [asic_id ].STATE_DB , 'MUX_METRICS_TABLE|{}' .format (port ))
445
+ if not muxcable_metrics_dict [asic_id ]:
446
+ muxcable_metrics_dict [asic_id ] = {}
419
447
create_json_dump_per_port_status (db , port_status_dict , muxcable_info_dict ,
420
- muxcable_health_dict , asic_id , port )
448
+ muxcable_health_dict , muxcable_metrics_dict , asic_id , port )
421
449
422
450
click .echo ("{}" .format (json .dumps (port_status_dict , indent = 4 )))
423
451
else :
@@ -430,11 +458,14 @@ def status(db, port, json_output):
430
458
per_npu_statedb [asic_id ].STATE_DB , 'MUX_LINKMGR_TABLE|{}' .format (port ))
431
459
muxcable_info_dict [asic_id ] = per_npu_statedb [asic_id ].get_all (
432
460
per_npu_statedb [asic_id ].STATE_DB , 'MUX_CABLE_TABLE|{}' .format (port ))
433
-
461
+ muxcable_metrics_dict [asic_id ] = per_npu_statedb [asic_id ].get_all (
462
+ per_npu_statedb [asic_id ].STATE_DB , 'MUX_METRICS_TABLE|{}' .format (port ))
463
+ if not muxcable_metrics_dict [asic_id ]:
464
+ muxcable_metrics_dict [asic_id ] = {}
434
465
create_table_dump_per_port_status (db , print_data , muxcable_info_dict ,
435
- muxcable_health_dict , asic_id , port )
466
+ muxcable_health_dict , muxcable_metrics_dict , asic_id , port )
436
467
437
- headers = ['PORT' , 'STATUS' , 'HEALTH' ]
468
+ headers = ['PORT' , 'STATUS' , 'HEALTH' , 'LAST_SWITCHOVER_TIME' ]
438
469
click .echo (tabulate (print_data , headers = headers ))
439
470
440
471
sys .exit (STATUS_SUCCESSFUL )
0 commit comments