@@ -471,3 +471,86 @@ def rate_limit_container(db, service_name, interval, burst):
471
471
feature_data = db .cfgdb .get_table (syslog_common .FEATURE_TABLE )
472
472
syslog_common .service_validator (feature_data , service_name )
473
473
syslog_common .save_rate_limit_to_db (db , service_name , interval , burst , log )
474
+
475
+
476
+ @syslog .group (
477
+ name = "rate-limit-feature" ,
478
+ cls = clicommon .AliasedGroup
479
+ )
480
+ def rate_limit_feature ():
481
+ """ Configure syslog rate limit feature """
482
+ pass
483
+
484
+
485
+ @rate_limit_feature .command ("enable" )
486
+ @clicommon .pass_db
487
+ def enable_rate_limit_feature (db ):
488
+ """ Enable syslog rate limit feature """
489
+ feature_data = db .cfgdb .get_table (syslog_common .FEATURE_TABLE )
490
+ for feature_name in feature_data .keys ():
491
+ click .echo (f'Enabling syslog rate limit feature for { feature_name } ' )
492
+ output , _ = clicommon .run_command (['docker' , 'ps' , '-q' , '-f' , 'status=running' , '-f' , f'name={ feature_name } ' ], return_cmd = True )
493
+ if not output :
494
+ click .echo (f'{ feature_name } is not running, ignoring...' )
495
+ continue
496
+
497
+ output , _ = clicommon .run_command (['docker' , 'exec' , '-i' , feature_name , 'supervisorctl' , 'status' , 'containercfgd' ],
498
+ ignore_error = True , return_cmd = True )
499
+ if 'no such process' not in output :
500
+ click .echo (f'Syslog rate limit feature is already enabled in { feature_name } , ignoring...' )
501
+ continue
502
+
503
+ commands = [
504
+ ['docker' , 'cp' , '/usr/share/sonic/templates/containercfgd.conf' , f'{ feature_name } :/etc/supervisor/conf.d/' ],
505
+ ['docker' , 'exec' , '-i' , feature_name , 'supervisorctl' , 'reread' ],
506
+ ['docker' , 'exec' , '-i' , feature_name , 'supervisorctl' , 'update' ],
507
+ ['docker' , 'exec' , '-i' , feature_name , 'supervisorctl' , 'start' , 'containercfgd' ]
508
+ ]
509
+
510
+ failed = False
511
+ for command in commands :
512
+ output , ret = clicommon .run_command (command , return_cmd = True )
513
+ if ret != 0 :
514
+ failed = True
515
+ click .echo (f'Enable syslog rate limit feature for { feature_name } failed - { output } ' )
516
+ break
517
+
518
+ if not failed :
519
+ click .echo (f'Enabled syslog rate limit feature for { feature_name } ' )
520
+
521
+
522
+ @rate_limit_feature .command ("disable" )
523
+ @clicommon .pass_db
524
+ def disable_rate_limit_feature (db ):
525
+ """ Disable syslog rate limit feature """
526
+ feature_data = db .cfgdb .get_table (syslog_common .FEATURE_TABLE )
527
+ for feature_name in feature_data .keys ():
528
+ click .echo (f'Disabling syslog rate limit feature for { feature_name } ' )
529
+ output , _ = clicommon .run_command (['docker' , 'ps' , '-q' , '-f' , 'status=running' , '-f' , f'name={ feature_name } ' ], return_cmd = True )
530
+ if not output :
531
+ click .echo (f'{ feature_name } is not running, ignoring...' )
532
+ continue
533
+
534
+ output , _ = clicommon .run_command (['docker' , 'exec' , '-i' , feature_name , 'supervisorctl' , 'status' , 'containercfgd' ],
535
+ ignore_error = True , return_cmd = True )
536
+ if 'no such process' in output :
537
+ click .echo (f'Syslog rate limit feature is already disabled in { feature_name } , ignoring...' )
538
+ continue
539
+
540
+ commands = [
541
+ ['docker' , 'exec' , '-i' , feature_name , 'supervisorctl' , 'stop' , 'containercfgd' ],
542
+ ['docker' , 'exec' , '-i' , feature_name , 'rm' , '-f' , '/etc/supervisor/conf.d/containercfgd.conf' ],
543
+ ['docker' , 'exec' , '-i' , feature_name , 'supervisorctl' , 'reread' ],
544
+ ['docker' , 'exec' , '-i' , feature_name , 'supervisorctl' , 'update' ]
545
+ ]
546
+ failed = False
547
+ for command in commands :
548
+ output , ret = clicommon .run_command (command , return_cmd = True )
549
+ if ret != 0 :
550
+ failed = True
551
+ click .echo (f'Disable syslog rate limit feature for { feature_name } failed - { output } ' )
552
+ break
553
+
554
+ if not failed :
555
+ click .echo (f'Disabled syslog rate limit feature for { feature_name } ' )
556
+
0 commit comments