From 3d257b8f3a81b686ac31905b3aa76b5d262497fa Mon Sep 17 00:00:00 2001 From: kellyyeh Date: Fri, 27 Aug 2021 20:27:49 +0000 Subject: [PATCH] Added code comments and updated docker files --- ...unter_clear.py => clear_dhcp6relay_counter.py} | 15 +++++++++------ .../cli/show/plugins/show_dhcp6relay_counters.py | 11 +++++++---- .../cli/show/plugins/show_dhcpv6_helper.py | 6 +++++- files/build_templates/manifest.json.j2 | 3 ++- rules/docker-dhcp-relay.mk | 4 ++++ rules/functions | 1 + 6 files changed, 28 insertions(+), 12 deletions(-) rename dockers/docker-dhcp-relay/cli/clear/plugins/{dhcp6relay_counter_clear.py => clear_dhcp6relay_counter.py} (56%) diff --git a/dockers/docker-dhcp-relay/cli/clear/plugins/dhcp6relay_counter_clear.py b/dockers/docker-dhcp-relay/cli/clear/plugins/clear_dhcp6relay_counter.py similarity index 56% rename from dockers/docker-dhcp-relay/cli/clear/plugins/dhcp6relay_counter_clear.py rename to dockers/docker-dhcp-relay/cli/clear/plugins/clear_dhcp6relay_counter.py index 76265c59fa60..0dd2dd242981 100644 --- a/dockers/docker-dhcp-relay/cli/clear/plugins/dhcp6relay_counter_clear.py +++ b/dockers/docker-dhcp-relay/cli/clear/plugins/clear_dhcp6relay_counter.py @@ -1,14 +1,14 @@ +import sys import click sys.path.insert(0, '../../show/plugins/') -import show_dhcp6relay_counters +from show_dhcp6relay_counters impot DHCPv6_Counter # sonic-clear dhcp6relay_counters -@click.command() +@click.command('dhcp6relay_counters') @click.option('-i', '--interface', required=False) -@click.option('--verbose', is_flag=True, help="Enable verbose output") -def dhcp6relay_counters(interface, verbose): - """Clear dhcp6relay message counts""" +def dhcp6relay_clear_counters(interface): + """ Clear dhcp6relay message counts """ counter = DHCPv6_Counter() counter_intf = counter.get_interface() @@ -20,4 +20,7 @@ def dhcp6relay_counters(interface, verbose): counter.clear_table(intf) def register(cli): - cli.add_command(dhcp6relay_counters) + cli.add_command(dhcp6relay_clear_counters) + +if __name__ == '__main__': + dhcp6relay_clear_counters() diff --git a/dockers/docker-dhcp-relay/cli/show/plugins/show_dhcp6relay_counters.py b/dockers/docker-dhcp-relay/cli/show/plugins/show_dhcp6relay_counters.py index bbaba69d7f83..676f2513fd22 100644 --- a/dockers/docker-dhcp-relay/cli/show/plugins/show_dhcp6relay_counters.py +++ b/dockers/docker-dhcp-relay/cli/show/plugins/show_dhcp6relay_counters.py @@ -1,8 +1,6 @@ import click import utilities_common.cli as clicommon -import argparse -import sys from tabulate import tabulate from swsscommon.swsscommon import SonicV2Connector @@ -22,6 +20,7 @@ def __init__(self): def get_interface(self): + """ Get all names of all interfaces in DHCPv6_COUNTER_TABLE """ vlans = [] for key in self.db.keys(self.db.STATE_DB): if DHCPv6_COUNTER_TABLE in key: @@ -30,12 +29,14 @@ def get_interface(self): def get_dhcp6relay_msg_count(self, interface, msg): + """ Get count of a dhcp6relay message """ count = self.db.get(self.db.STATE_DB, self.table_name + str(interface), str(msg)) data = [str(msg), count] return data def clear_table(self, interface): + """ Reset all message counts to 0 """ for msg in messages: self.db.set(self.db.STATE_DB, self.table_name + str(interface), str(msg), '0') @@ -75,5 +76,7 @@ def counts(interface, verbose): def register(cli): - cli.commands['dhcp6realy_counters'].add_command(dhcp6relay_counters) - \ No newline at end of file + cli.add_command(dhcp6relay_counters) + +if __name__ == '__main__': + dhcp6relay_counters() diff --git a/dockers/docker-dhcp-relay/cli/show/plugins/show_dhcpv6_helper.py b/dockers/docker-dhcp-relay/cli/show/plugins/show_dhcpv6_helper.py index 68220413cc63..0ae4e37b97e6 100644 --- a/dockers/docker-dhcp-relay/cli/show/plugins/show_dhcpv6_helper.py +++ b/dockers/docker-dhcp-relay/cli/show/plugins/show_dhcpv6_helper.py @@ -28,4 +28,8 @@ def get_dhcpv6_helper_address(): print(tabulate({'Interface':[vlan], vlan:addr.get(vlan)}, tablefmt='simple', stralign='right') + '\n') def register(cli): - cli.commands['dhcp_relay_helper'].add_command(dhcp_relay_helper) + cli.add_command(dhcp_relay_helper) + +if __name__ == '__main__': + dhcp_relay_helper() + \ No newline at end of file diff --git a/files/build_templates/manifest.json.j2 b/files/build_templates/manifest.json.j2 index 9f3e872d2e65..431b2dd22432 100644 --- a/files/build_templates/manifest.json.j2 +++ b/files/build_templates/manifest.json.j2 @@ -29,6 +29,7 @@ }, "cli": { "config": "{{ config_cli_plugin|default('') }}", - "show": "{{ show_cli_plugin|default('') }}" + "show": "{{ show_cli_plugin|default('') }}", + "clear": "{{ clear_cli_plugin|default('') }}" } } diff --git a/rules/docker-dhcp-relay.mk b/rules/docker-dhcp-relay.mk index a8b33c5bc74c..aeeb3c5ddf0a 100644 --- a/rules/docker-dhcp-relay.mk +++ b/rules/docker-dhcp-relay.mk @@ -53,5 +53,9 @@ $(DOCKER_DHCP_RELAY)_CONTAINER_TMPFS += /var/tmp/ $(DOCKER_DHCP_RELAY)_CLI_CONFIG_PLUGIN = /cli/config/plugins/dhcp_relay.py $(DOCKER_DHCP_RELAY)_CLI_SHOW_PLUGIN = /cli/show/plugins/show_dhcp_relay.py +$(DOCKER_DHCP_RELAY)_CLI_SHOW_PLUGIN = /cli/show/plugins/show_dhcp6relay_counters.py +$(DOCKER_DHCP_RELAY)_CLI_SHOW_PLUGIN = /cli/show/plugins/show_dhcp_helper.py +$(DOCKER_DHCP_RELAY)_CLI_CLEAR_PLUGIN = /cli/clear/plugins/clear_dhcp6relay_counter.py +$(DOCKER_DHCP_RELAY)_CLI_CLEAR_PLUGIN = /cli/clear/plugins/ipv7.py $(DOCKER_DHCP_RELAY)_FILES += $(SUPERVISOR_PROC_EXIT_LISTENER_SCRIPT) diff --git a/rules/functions b/rules/functions index 5873b2db1b87..6f62b87797c8 100644 --- a/rules/functions +++ b/rules/functions @@ -196,6 +196,7 @@ define generate_manifest $(eval export tmpfs=$($(1).gz_CONTAINER_TMPFS)) $(eval export config_cli_plugin=$($(1).gz_CLI_CONFIG_PLUGIN)) $(eval export show_cli_plugin=$($(1).gz_CLI_SHOW_PLUGIN)) + $(eval export clear_cli_plugin=$($(1).gz_CLI_CLEAR_PLUGIN)) j2 $($*.gz_PATH)/Dockerfile$(2).j2 > $($(1).gz_PATH)/Dockerfile$(2) j2 --customize scripts/j2cli/json_filter.py files/build_templates/manifest.json.j2 > $($(1).gz_PATH)/manifest.common.json if [ -f $($*.gz_PATH)/manifest.part.json.j2 ]; then