diff --git a/pfcwd/main.py b/pfcwd/main.py index 93508c3529cd..d6569a2686af 100644 --- a/pfcwd/main.py +++ b/pfcwd/main.py @@ -2,6 +2,7 @@ import click import swsssdk +import os from tabulate import tabulate from natsort import natsorted @@ -124,18 +125,30 @@ def config(ports): @cli.command() @click.option('--action', '-a', type=click.Choice(['drop', 'forward', 'alert'])) @click.option('--restoration-time', '-r', type=click.IntRange(100, 60000)) -@click.argument('ports', nargs = -1) +@click.argument('ports', nargs=-1) @click.argument('detection-time', type=click.IntRange(100, 5000)) def start(action, restoration_time, ports, detection_time): - """ Start PFC watchdog on port(s). To config all ports, use all as input. """ + """ + Start PFC watchdog on port(s). To config all ports, use all as input. + + Example: + + sudo pfcwd start --action drop ports all detection-time 400 --restoration-time 400 + + """ if os.geteuid() != 0: exit("Root privileges are required for this operation") + allowed_strs = ['ports', 'all', 'detection-time'] configdb = swsssdk.ConfigDBConnector() configdb.connect() countersdb = swsssdk.SonicV2Connector(host='127.0.0.1') countersdb.connect(countersdb.COUNTERS_DB) all_ports = get_all_ports(countersdb) + allowed_strs = allowed_strs + all_ports + for p in ports: + if p not in allowed_strs: + raise click.BadOptionUsage("Bad command line format. Try 'pfcwd start --help' for usage") if len(ports) == 0: ports = all_ports @@ -147,6 +160,9 @@ def start(action, restoration_time, ports, detection_time): pfcwd_info['action'] = action if restoration_time is not None: pfcwd_info['restoration_time'] = restoration_time + else: + pfcwd_info['restoration_time'] = 2 * detection_time + print "restoration time not defined; default to 2 times detection time: %d ms" % (2 * detection_time) for port in ports: if port == "all":