Skip to content

Commit

Permalink
Added code comments and updated docker files
Browse files Browse the repository at this point in the history
  • Loading branch information
kellyyeh committed Aug 27, 2021
1 parent 4308fda commit 3d257b8
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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()
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:
Expand All @@ -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')

Expand Down Expand Up @@ -75,5 +76,7 @@ def counts(interface, verbose):


def register(cli):
cli.commands['dhcp6realy_counters'].add_command(dhcp6relay_counters)

cli.add_command(dhcp6relay_counters)

if __name__ == '__main__':
dhcp6relay_counters()
Original file line number Diff line number Diff line change
Expand Up @@ -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()

3 changes: 2 additions & 1 deletion files/build_templates/manifest.json.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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('') }}"
}
}
4 changes: 4 additions & 0 deletions rules/docker-dhcp-relay.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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)
1 change: 1 addition & 0 deletions rules/functions
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3d257b8

Please sign in to comment.