Skip to content

Commit

Permalink
[PBH] CLI for Policy Based Hashing (#1701)
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
vadymhlushko-mlnx committed Aug 25, 2021
1 parent 7ebb2f7 commit 6fd0675
Show file tree
Hide file tree
Showing 13 changed files with 2,921 additions and 2 deletions.
30 changes: 28 additions & 2 deletions clear/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
import os
import subprocess
import sys

import click
import utilities_common.cli as clicommon
import json

from utilities_common import util_base

from show.plugins.pbh import read_pbh_counters
from . import plugins


Expand Down Expand Up @@ -449,6 +450,31 @@ def translations():
cmd = "natclear -t"
run_command(cmd)

# 'pbh' group ("clear pbh ...")
@cli.group(cls=AliasedGroup)
def pbh():
""" Clear the PBH info """
pass

# 'statistics' subcommand ("clear pbh statistics")
@pbh.command()
@clicommon.pass_db
def statistics(db):
""" Clear PBH counters
clear counters -- write current counters to file in /tmp
"""

pbh_rules = db.cfgdb.get_table("PBH_RULE")
pbh_counters = read_pbh_counters(pbh_rules)

try:
with open('/tmp/.pbh_counters.txt', 'w') as fp:
json.dump(remap_keys(pbh_counters), fp)
except IOError as err:
pass

def remap_keys(dict):
return [{'key': k, 'value': v} for k, v in dict.items()]

# Load plugins and register them
helper = util_base.UtilHelper()
Expand Down
Loading

0 comments on commit 6fd0675

Please sign in to comment.