33
44import click
55
6+ import utilities_common .cli as clicommon
7+
68from natsort import natsorted
79from sonic_py_common .multi_asic import get_external_ports
810from tabulate import tabulate
@@ -98,10 +100,14 @@ def get_server_facing_ports(db):
98100
99101
100102class PfcwdCli (object ):
101- def __init__ (self , namespace = None , display = constants .DISPLAY_ALL ):
103+ def __init__ (
104+ self , db = None , namespace = None , display = constants .DISPLAY_ALL
105+ ):
102106 self .db = None
103107 self .config_db = None
104- self .multi_asic = multi_asic_util .MultiAsic (display , namespace )
108+ self .multi_asic = multi_asic_util .MultiAsic (
109+ display , namespace , db
110+ )
105111 self .table = []
106112 self .all_ports = []
107113
@@ -397,6 +403,7 @@ def big_red_switch(self, big_red_switch):
397403 pfcwd_info
398404 )
399405
406+
400407# Show stats
401408class Show (object ):
402409 # Show commands
@@ -408,19 +415,21 @@ def show():
408415 @multi_asic_util .multi_asic_click_options
409416 @click .option ('-e' , '--empty' , is_flag = True )
410417 @click .argument ('queues' , nargs = - 1 )
411- def stats (namespace , display , empty , queues ):
418+ @clicommon .pass_db
419+ def stats (db , namespace , display , empty , queues ):
412420 """ Show PFC Watchdog stats per queue """
413421 if (len (queues )):
414422 display = constants .DISPLAY_ALL
415- PfcwdCli (namespace , display ).show_stats (empty , queues )
423+ PfcwdCli (db , namespace , display ).show_stats (empty , queues )
416424
417425 # Show config
418426 @show .command ()
419427 @multi_asic_util .multi_asic_click_options
420428 @click .argument ('ports' , nargs = - 1 )
421- def config (namespace , display , ports ):
429+ @clicommon .pass_db
430+ def config (db , namespace , display , ports ):
422431 """ Show PFC Watchdog configuration """
423- PfcwdCli (namespace , display ).config (ports )
432+ PfcwdCli (db , namespace , display ).config (ports )
424433
425434
426435# Start WD
@@ -432,7 +441,8 @@ class Start(object):
432441 @click .option ('--restoration-time' , '-r' , type = click .IntRange (100 , 60000 ))
433442 @click .argument ('ports' , nargs = - 1 )
434443 @click .argument ('detection-time' , type = click .IntRange (100 , 5000 ))
435- def start (action , restoration_time , ports , detection_time ):
444+ @clicommon .pass_db
445+ def start (db , action , restoration_time , ports , detection_time ):
436446 """
437447 Start PFC watchdog on port(s). To config all ports, use all as input.
438448
@@ -441,51 +451,58 @@ def start(action, restoration_time, ports, detection_time):
441451 sudo pfcwd start --action drop ports all detection-time 400 --restoration-time 400
442452
443453 """
444- PfcwdCli ().start (action , restoration_time , ports , detection_time )
454+ PfcwdCli (db ).start (
455+ action , restoration_time , ports , detection_time
456+ )
445457
446458
447459# Set WD poll interval
448460class Interval (object ):
449461 @cli .command ()
450462 @click .argument ('poll_interval' , type = click .IntRange (100 , 3000 ))
451- def interval (poll_interval ):
463+ @clicommon .pass_db
464+ def interval (db , poll_interval ):
452465 """ Set PFC watchdog counter polling interval """
453- PfcwdCli ().interval (poll_interval )
466+ PfcwdCli (db ).interval (poll_interval )
454467
455468
456469# Stop WD
457470class Stop (object ):
458471 @cli .command ()
459472 @click .argument ('ports' , nargs = - 1 )
460- def stop (ports ):
473+ @clicommon .pass_db
474+ def stop (db , ports ):
461475 """ Stop PFC watchdog on port(s) """
462- PfcwdCli ().stop (ports )
476+ PfcwdCli (db ).stop (ports )
463477
464478
465479# Set WD default configuration on server facing ports when enable flag is on
466480class StartDefault (object ):
467481 @cli .command ("start_default" )
468- def start_default ():
482+ @clicommon .pass_db
483+ def start_default (db ):
469484 """ Start PFC WD by default configurations """
470- PfcwdCli ().start_default ()
485+ PfcwdCli (db ).start_default ()
471486
472487
473488# Enable/disable PFC WD counter polling
474489class CounterPoll (object ):
475490 @cli .command ('counter_poll' )
476491 @click .argument ('counter_poll' , type = click .Choice (['enable' , 'disable' ]))
477- def counter_poll (counter_poll ):
492+ @clicommon .pass_db
493+ def counter_poll (db , counter_poll ):
478494 """ Enable/disable counter polling """
479- PfcwdCli ().counter_poll (counter_poll )
495+ PfcwdCli (db ).counter_poll (counter_poll )
480496
481497
482498# Enable/disable PFC WD BIG_RED_SWITCH mode
483499class BigRedSwitch (object ):
484500 @cli .command ('big_red_switch' )
485501 @click .argument ('big_red_switch' , type = click .Choice (['enable' , 'disable' ]))
486- def big_red_switch (big_red_switch ):
502+ @clicommon .pass_db
503+ def big_red_switch (db , big_red_switch ):
487504 """ Enable/disable BIG_RED_SWITCH mode """
488- PfcwdCli ().big_red_switch (big_red_switch )
505+ PfcwdCli (db ).big_red_switch (big_red_switch )
489506
490507
491508def get_pfcwd_clis ():
0 commit comments