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 b555b5a58b..d429b75669 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} @@ -298,7 +298,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 @@ -365,8 +365,23 @@ limitations under the License. - - + + + + + + + + + + + + + + + + @@ -450,10 +465,10 @@ limitations under the License. name="no" help="Negate a command or set its defaults" /> - - @@ -467,8 +482,8 @@ limitations under the License. - python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface_config_mtu ${po_id} ${mtu} @@ -478,12 +493,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 %} +