From ecec01ec85e885f4192befc189a7440978165336 Mon Sep 17 00:00:00 2001 From: Garrick He <32883830+GarrickHe@users.noreply.github.com> Date: Thu, 3 Oct 2019 15:45:50 -0700 Subject: [PATCH] sFlow CLI Template (#147) * sFlow CLI template * Add XML skeleton for the sFlow CLI * Add actioner script * Add renderer template Signed-off-by: Garrick He --- src/CLI/actioner/sonic-cli-sflow.py | 45 +++++++++++ src/CLI/clitree/cli-xml/interface.xml | 41 ++++++---- src/CLI/clitree/cli-xml/sflow.xml | 75 +++++++++++++++++++ src/CLI/renderer/templates/show_sflow.j2 | 9 +++ src/CLI/renderer/templates/show_sflow_intf.j2 | 10 +++ 5 files changed, 167 insertions(+), 13 deletions(-) create mode 100755 src/CLI/actioner/sonic-cli-sflow.py create mode 100644 src/CLI/clitree/cli-xml/sflow.xml create mode 100755 src/CLI/renderer/templates/show_sflow.j2 create mode 100755 src/CLI/renderer/templates/show_sflow_intf.j2 diff --git a/src/CLI/actioner/sonic-cli-sflow.py b/src/CLI/actioner/sonic-cli-sflow.py new file mode 100755 index 0000000000..7ac8ac4d5d --- /dev/null +++ b/src/CLI/actioner/sonic-cli-sflow.py @@ -0,0 +1,45 @@ +#!/usr/bin/python +import sys +import time +import json +import ast +from collections import OrderedDict +from scripts.render_cli import show_cli_output + + +import urllib3 +urllib3.disable_warnings() +plugins = dict() + + +def register(func): + """Register sdk client method as a plug-in""" + plugins[func.__name__] = func + return func + +def call_method(name, args): + method = plugins[name] + return method(args) + +def get_sflow(): + pass + +def get_sflow_interface(): + pass + +def run(func, args): + + # create a body block + if (func.__name__ == 'get_sflow'): + sflow_info = {'sflow' : {'admin_state' : 'enabled', 'polling-interval' : 20, 'agent-id' : 'default'}} + else: + sflow_info = {} + sflow_info['sflow'] = OrderedDict() + for i in range(30): + sflow_info['sflow']['Ethernet'+str(i)] = {'admin_state' : 'enabled', 'sampling_rate' : 4000} + show_cli_output(sys.argv[2], sflow_info) + return + +if __name__ == '__main__': + func = eval(sys.argv[1], globals(), {}) + run(func, sys.argv[2:]) diff --git a/src/CLI/clitree/cli-xml/interface.xml b/src/CLI/clitree/cli-xml/interface.xml index cb13fab5ec..f913ac6808 100644 --- a/src/CLI/clitree/cli-xml/interface.xml +++ b/src/CLI/clitree/cli-xml/interface.xml @@ -1,6 +1,6 @@ +--> - - + python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_if_aggregate_interfaces_interface_ethernet_config_aggregate_id ${iface} ${lag-id} @@ -334,7 +334,7 @@ limitations under the License. help="Disable the interface"> python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface_config_enabled ${iface} False - python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface_config_enabled ${iface} True @@ -401,8 +401,23 @@ limitations under the License. - - + + + + + + + + + + + + + + + + @@ -486,10 +501,10 @@ limitations under the License. name="no" help="Negate a command or set its defaults" /> - - @@ -503,8 +518,8 @@ limitations under the License. - python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface_config_mtu ${po_id} ${mtu} @@ -514,12 +529,12 @@ limitations under the License. help="Remove MTU"> python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface_config_mtu ${po_id} 9100 - - diff --git a/src/CLI/clitree/cli-xml/sflow.xml b/src/CLI/clitree/cli-xml/sflow.xml new file mode 100644 index 0000000000..167badea2f --- /dev/null +++ b/src/CLI/clitree/cli-xml/sflow.xml @@ -0,0 +1,75 @@ + + + + + + + + python $SONIC_CLI_ROOT/sonic-cli-sflow.py get_sflow show_sflow.j2 + + + + python $SONIC_CLI_ROOT/sonic-cli-sflow.py get_sflow_interface show_sflow_intf.j2 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/CLI/renderer/templates/show_sflow.j2 b/src/CLI/renderer/templates/show_sflow.j2 new file mode 100755 index 0000000000..7bd2e9b378 --- /dev/null +++ b/src/CLI/renderer/templates/show_sflow.j2 @@ -0,0 +1,9 @@ +{{'---------------------------------------------------------'}} +{{'Global sFlow Information'.ljust(20)}} +{{'---------------------------------------------------------'}} +{% if json_output and 'sflow' in json_output -%} +{% set sflow_info = json_output['sflow'] %} +{{' admin state: '}}{{sflow_info['admin_state']}} +{{' polling-interval: '}}{{sflow_info['polling-interval']}} +{{' agent-id: '}} {{sflow_info['agent-id']}} +{% endif %} diff --git a/src/CLI/renderer/templates/show_sflow_intf.j2 b/src/CLI/renderer/templates/show_sflow_intf.j2 new file mode 100755 index 0000000000..1499d30e78 --- /dev/null +++ b/src/CLI/renderer/templates/show_sflow_intf.j2 @@ -0,0 +1,10 @@ +{{'-----------------------------------------------------------'}} +{{'sFlow interface configurations'.ljust(20)}} +{{'%40s'|format('Interface Admin State Sampling Rate')}} +{% if json_output and 'sflow' in json_output -%} +{% set sflow_info = json_output['sflow'] %} +{% for intf, values in sflow_info.items() %} +{{'%13s'|format(intf.ljust(10))}} {{sflow_info[intf]['admin_state']}} {{sflow_info[intf]['sampling_rate']}} +{% endfor %} +{% endif %} +