3
3
4
4
import click
5
5
6
+ import utilities_common .cli as clicommon
7
+
6
8
from natsort import natsorted
7
9
from sonic_py_common .multi_asic import get_external_ports
8
10
from tabulate import tabulate
@@ -98,10 +100,14 @@ def get_server_facing_ports(db):
98
100
99
101
100
102
class 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
+ ):
102
106
self .db = None
103
107
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
+ )
105
111
self .table = []
106
112
self .all_ports = []
107
113
@@ -397,6 +403,7 @@ def big_red_switch(self, big_red_switch):
397
403
pfcwd_info
398
404
)
399
405
406
+
400
407
# Show stats
401
408
class Show (object ):
402
409
# Show commands
@@ -408,19 +415,21 @@ def show():
408
415
@multi_asic_util .multi_asic_click_options
409
416
@click .option ('-e' , '--empty' , is_flag = True )
410
417
@click .argument ('queues' , nargs = - 1 )
411
- def stats (namespace , display , empty , queues ):
418
+ @clicommon .pass_db
419
+ def stats (db , namespace , display , empty , queues ):
412
420
""" Show PFC Watchdog stats per queue """
413
421
if (len (queues )):
414
422
display = constants .DISPLAY_ALL
415
- PfcwdCli (namespace , display ).show_stats (empty , queues )
423
+ PfcwdCli (db , namespace , display ).show_stats (empty , queues )
416
424
417
425
# Show config
418
426
@show .command ()
419
427
@multi_asic_util .multi_asic_click_options
420
428
@click .argument ('ports' , nargs = - 1 )
421
- def config (namespace , display , ports ):
429
+ @clicommon .pass_db
430
+ def config (db , namespace , display , ports ):
422
431
""" Show PFC Watchdog configuration """
423
- PfcwdCli (namespace , display ).config (ports )
432
+ PfcwdCli (db , namespace , display ).config (ports )
424
433
425
434
426
435
# Start WD
@@ -432,7 +441,8 @@ class Start(object):
432
441
@click .option ('--restoration-time' , '-r' , type = click .IntRange (100 , 60000 ))
433
442
@click .argument ('ports' , nargs = - 1 )
434
443
@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 ):
436
446
"""
437
447
Start PFC watchdog on port(s). To config all ports, use all as input.
438
448
@@ -441,51 +451,58 @@ def start(action, restoration_time, ports, detection_time):
441
451
sudo pfcwd start --action drop ports all detection-time 400 --restoration-time 400
442
452
443
453
"""
444
- PfcwdCli ().start (action , restoration_time , ports , detection_time )
454
+ PfcwdCli (db ).start (
455
+ action , restoration_time , ports , detection_time
456
+ )
445
457
446
458
447
459
# Set WD poll interval
448
460
class Interval (object ):
449
461
@cli .command ()
450
462
@click .argument ('poll_interval' , type = click .IntRange (100 , 3000 ))
451
- def interval (poll_interval ):
463
+ @clicommon .pass_db
464
+ def interval (db , poll_interval ):
452
465
""" Set PFC watchdog counter polling interval """
453
- PfcwdCli ().interval (poll_interval )
466
+ PfcwdCli (db ).interval (poll_interval )
454
467
455
468
456
469
# Stop WD
457
470
class Stop (object ):
458
471
@cli .command ()
459
472
@click .argument ('ports' , nargs = - 1 )
460
- def stop (ports ):
473
+ @clicommon .pass_db
474
+ def stop (db , ports ):
461
475
""" Stop PFC watchdog on port(s) """
462
- PfcwdCli ().stop (ports )
476
+ PfcwdCli (db ).stop (ports )
463
477
464
478
465
479
# Set WD default configuration on server facing ports when enable flag is on
466
480
class StartDefault (object ):
467
481
@cli .command ("start_default" )
468
- def start_default ():
482
+ @clicommon .pass_db
483
+ def start_default (db ):
469
484
""" Start PFC WD by default configurations """
470
- PfcwdCli ().start_default ()
485
+ PfcwdCli (db ).start_default ()
471
486
472
487
473
488
# Enable/disable PFC WD counter polling
474
489
class CounterPoll (object ):
475
490
@cli .command ('counter_poll' )
476
491
@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 ):
478
494
""" Enable/disable counter polling """
479
- PfcwdCli ().counter_poll (counter_poll )
495
+ PfcwdCli (db ).counter_poll (counter_poll )
480
496
481
497
482
498
# Enable/disable PFC WD BIG_RED_SWITCH mode
483
499
class BigRedSwitch (object ):
484
500
@cli .command ('big_red_switch' )
485
501
@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 ):
487
504
""" Enable/disable BIG_RED_SWITCH mode """
488
- PfcwdCli ().big_red_switch (big_red_switch )
505
+ PfcwdCli (db ).big_red_switch (big_red_switch )
489
506
490
507
491
508
def get_pfcwd_clis ():
0 commit comments