Skip to content

Commit

Permalink
[counterpoll]: cli to change counter polling configuration (sonic-net…
Browse files Browse the repository at this point in the history
…#257)

Signed-off-by: Sihui Han <sihan@microsoft.com>
  • Loading branch information
sihuihan88 committed May 24, 2018
1 parent 9087d5f commit fffe98e
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
Empty file added counterpoll/__init__.py
Empty file.
59 changes: 59 additions & 0 deletions counterpoll/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#! /usr/bin/python -u

import click
import swsssdk
from tabulate import tabulate

@click.group()
def cli():
""" SONiC Static Counter Poll configurations """

# Queue counter commands
@cli.group()
def queue():
""" Queue counter commands """

@queue.command()
@click.argument('poll_interval', type=click.IntRange(100, 30000))
def interval(poll_interval):
""" Set queue counter query interval """
configdb = swsssdk.ConfigDBConnector()
configdb.connect()
queue_info = {}
if poll_interval is not None:
queue_info['POLL_INTERVAL'] = poll_interval
configdb.mod_entry("FLEX_COUNTER_TABLE", "QUEUE", queue_info)

# Port counter commands
@cli.group()
def port():
""" Queue counter commands """

@port.command()
@click.argument('poll_interval', type=click.IntRange(100, 30000))
def interval(poll_interval):
""" Set queue counter query interval """
configdb = swsssdk.ConfigDBConnector()
configdb.connect()
port_info = {}
if poll_interval is not None:
port_info['POLL_INTERVAL'] = poll_interval
configdb.mod_entry("FLEX_COUNTER_TABLE", "test", port_info)

@cli.command()
def show():
""" Show the counter configuration """
configdb = swsssdk.ConfigDBConnector()
configdb.connect()
queue_info = configdb.get_entry('FLEX_COUNTER_TABLE', 'QUEUE')
port_info = configdb.get_entry('FLEX_COUNTER_TABLE', 'PORT')

header = ("Type", "Interval")
data = []
if queue_info:
data.append(["QUEUE_STAT", queue_info["POLL_INTERVAL"]])
if port_info:
data.append(["PORT_STAT", port_info["POLL_INTERVAL"]])

print tabulate(data, headers=header, tablefmt="simple", missingval="")

8 changes: 8 additions & 0 deletions data/etc/bash_completion.d/counterpoll
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
_counterpoll_completion() {
COMPREPLY=( $( env COMP_WORDS="${COMP_WORDS[*]}" \
COMP_CWORD=$COMP_CWORD \
_COUNTERPOLL_COMPLETE=complete $1 ) )
return 0
}

complete -F _counterpoll_completion -o default counterpoll;
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def get_test_suite():
'acl_loader',
'clear',
'config',
'counterpoll',
'crm',
'debug',
'pfcwd',
Expand Down Expand Up @@ -63,6 +64,7 @@ def get_test_suite():
'console_scripts': [
'acl-loader = acl_loader.main:cli',
'config = config.main:cli',
'counterpoll = counterpoll.main:cli',
'crm = crm.main:cli',
'debug = debug.main:cli',
'pfcwd = pfcwd.main:cli',
Expand Down

0 comments on commit fffe98e

Please sign in to comment.