Skip to content

Commit 6fd0675

Browse files
[PBH] CLI for Policy Based Hashing (sonic-net#1701)
- What I did Created click CLI plugins for PBH feature - How I did it The CLI plugins were auto-generated (by using the sonic-cli-gen) for show and config CLI groups, then manually those were manually edited to meet PBH the CLI requirements according to the PBH HLD - How to verify it Added the UT
1 parent 7ebb2f7 commit 6fd0675

13 files changed

+2921
-2
lines changed

clear/main.py

+28-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
import os
33
import subprocess
44
import sys
5-
65
import click
6+
import utilities_common.cli as clicommon
7+
import json
78

89
from utilities_common import util_base
9-
10+
from show.plugins.pbh import read_pbh_counters
1011
from . import plugins
1112

1213

@@ -449,6 +450,31 @@ def translations():
449450
cmd = "natclear -t"
450451
run_command(cmd)
451452

453+
# 'pbh' group ("clear pbh ...")
454+
@cli.group(cls=AliasedGroup)
455+
def pbh():
456+
""" Clear the PBH info """
457+
pass
458+
459+
# 'statistics' subcommand ("clear pbh statistics")
460+
@pbh.command()
461+
@clicommon.pass_db
462+
def statistics(db):
463+
""" Clear PBH counters
464+
clear counters -- write current counters to file in /tmp
465+
"""
466+
467+
pbh_rules = db.cfgdb.get_table("PBH_RULE")
468+
pbh_counters = read_pbh_counters(pbh_rules)
469+
470+
try:
471+
with open('/tmp/.pbh_counters.txt', 'w') as fp:
472+
json.dump(remap_keys(pbh_counters), fp)
473+
except IOError as err:
474+
pass
475+
476+
def remap_keys(dict):
477+
return [{'key': k, 'value': v} for k, v in dict.items()]
452478

453479
# Load plugins and register them
454480
helper = util_base.UtilHelper()

0 commit comments

Comments
 (0)