From 31f1ffa2887262c5d8ecf3e4879884876091d10a Mon Sep 17 00:00:00 2001 From: Garrick He Date: Tue, 1 Oct 2019 13:31:25 -0700 Subject: [PATCH 1/4] 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 | 46 ++ src/CLI/clitree/cli-xml/interface.xml | 433 ++++-------------- src/CLI/clitree/cli-xml/sflow.xml | 42 ++ src/CLI/renderer/templates/show_sflow.j2 | 9 + src/CLI/renderer/templates/show_sflow_intf.j2 | 10 + 5 files changed, 189 insertions(+), 351 deletions(-) create mode 100755 src/CLI/actioner/sonic-cli-sflow.py create mode 100755 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..e49d9b7998 --- /dev/null +++ b/src/CLI/actioner/sonic-cli-sflow.py @@ -0,0 +1,46 @@ +#!/usr/bin/python +import sys +import time +import json +import ast +import sonic_sflow_client +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'] = {} + 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 0ded9aabfd..19e7cb7784 100644 --- a/src/CLI/clitree/cli-xml/interface.xml +++ b/src/CLI/clitree/cli-xml/interface.xml @@ -1,354 +1,85 @@ - - - - - + + + + + + +]> + + - - - - - - - - - - - - - if test "${if-subcommands}" = "status"; then - python $SONIC_CLI_ROOT/sonic-cli-if.py get_openconfig_interfaces_interfaces show_interface_status.j2 ${__full_line} - elif test "${if-subcommands}" = "counters"; then - python $SONIC_CLI_ROOT/sonic-cli-if.py get_openconfig_interfaces_interfaces show_interface_counters.j2 ${__full_line} - else - if test "${phy-if-id}" = ""; then - python $SONIC_CLI_ROOT/sonic-cli-if.py get_openconfig_interfaces_interfaces show_interface.j2 ${__full_line} - else - python $SONIC_CLI_ROOT/sonic-cli-if.py get_openconfig_interfaces_interfaces_interface Ethernet${phy-if-id} show_interface_id.j2 ${__full_line} - fi - fi - - - - - - - - python $SONIC_CLI_ROOT/sonic-cli-if.py get_openconfig_vlan_interfaces_interface_ethernet_switched_vlan_state show_vlan.j2 - - - - - - - - - - - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface_config_description ${iface} ${desc} - - - python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface_config_description ${iface} "" - - - - python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface_config_mtu ${iface} ${mtu} - - - python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface_config_mtu ${iface} 9100 - - - 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 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + if test "${if-subcommands}" = "status"; then + python $SONIC_CLI_ROOT/sonic-cli-if.py get_openconfig_interfaces_interfaces show_interface_status.j2 + elif test "${if-subcommands}" = "counters"; then + python $SONIC_CLI_ROOT/sonic-cli-if.py get_openconfig_interfaces_interfaces show_interface_counters.j2 + else + if test "${phy-if-id}" = ""; then + python $SONIC_CLI_ROOT/sonic-cli-if.py get_openconfig_interfaces_interfaces show_interface.j2 + else + python $SONIC_CLI_ROOT/sonic-cli-if.py get_openconfig_interfaces_interfaces_interface Ethernet${phy-if-id} show_interface_id.j2 + fi + fi + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + + python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface_config_description ${iface} ${desc} + + + python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface_config_description ${iface} "" + + + + python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface_config_mtu ${iface} ${mtu} + + + python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface_config_mtu ${iface} 9100 + + + + + + + + + + + + + - diff --git a/src/CLI/clitree/cli-xml/sflow.xml b/src/CLI/clitree/cli-xml/sflow.xml new file mode 100755 index 0000000000..abc5e1ff71 --- /dev/null +++ b/src/CLI/clitree/cli-xml/sflow.xml @@ -0,0 +1,42 @@ + + + + + + +]> + + + + python $SONIC_CLI_ROOT/sonic-cli-sflow.py get_openconfig_lldp_lldp_interfaces show_sflow.j2 + + + + python $SONIC_CLI_ROOT/sonic-cli-sflow.py get_openconfig_lldp_lldp_interfaces 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 %} + From 23546dd2d93bd96f1500ca03232f712a4edf2308 Mon Sep 17 00:00:00 2001 From: Garrick He Date: Tue, 1 Oct 2019 13:41:35 -0700 Subject: [PATCH 2/4] Fix interface.xml * Fix some changes made in interface.xml Signed-off-by: Garrick He --- src/CLI/clitree/cli-xml/interface.xml | 444 +++++++++++++++++++++----- 1 file changed, 362 insertions(+), 82 deletions(-) diff --git a/src/CLI/clitree/cli-xml/interface.xml b/src/CLI/clitree/cli-xml/interface.xml index 19e7cb7784..47fc5e311c 100644 --- a/src/CLI/clitree/cli-xml/interface.xml +++ b/src/CLI/clitree/cli-xml/interface.xml @@ -1,85 +1,365 @@ - - - - - - -]> - - + + + + + - - - - - + + + + + + + + + + + + + if test "${if-subcommands}" = "status"; then + python $SONIC_CLI_ROOT/sonic-cli-if.py get_openconfig_interfaces_interfaces show_interface_status.j2 ${__full_line} + elif test "${if-subcommands}" = "counters"; then + python $SONIC_CLI_ROOT/sonic-cli-if.py get_openconfig_interfaces_interfaces show_interface_counters.j2 ${__full_line} + else + if test "${phy-if-id}" = ""; then + python $SONIC_CLI_ROOT/sonic-cli-if.py get_openconfig_interfaces_interfaces show_interface.j2 ${__full_line} + else + python $SONIC_CLI_ROOT/sonic-cli-if.py get_openconfig_interfaces_interfaces_interface Ethernet${phy-if-id} show_interface_id.j2 ${__full_line} + fi + fi + + + + + + + + python $SONIC_CLI_ROOT/sonic-cli-if.py get_openconfig_vlan_interfaces_interface_ethernet_switched_vlan_state show_vlan.j2 + + + + + + + + + + + - - - if test "${if-subcommands}" = "status"; then - python $SONIC_CLI_ROOT/sonic-cli-if.py get_openconfig_interfaces_interfaces show_interface_status.j2 - elif test "${if-subcommands}" = "counters"; then - python $SONIC_CLI_ROOT/sonic-cli-if.py get_openconfig_interfaces_interfaces show_interface_counters.j2 - else - if test "${phy-if-id}" = ""; then - python $SONIC_CLI_ROOT/sonic-cli-if.py get_openconfig_interfaces_interfaces show_interface.j2 - else - python $SONIC_CLI_ROOT/sonic-cli-if.py get_openconfig_interfaces_interfaces_interface Ethernet${phy-if-id} show_interface_id.j2 - fi - fi - - - - - - - - - - - - - - - - - - - - - - - - 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 - - - - python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface_config_description ${iface} ${desc} - - - python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface_config_description ${iface} "" - - - - python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface_config_mtu ${iface} ${mtu} - - - python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface_config_mtu ${iface} 9100 - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface_config_description ${iface} ${desc} + + + python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface_config_description ${iface} "" + + + + python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface_config_mtu ${iface} ${mtu} + + + python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface_config_mtu ${iface} 9100 + + + 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 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From e412d8acaf23c62f0347c57f90142b5361a7c168 Mon Sep 17 00:00:00 2001 From: Garrick He Date: Tue, 1 Oct 2019 13:41:35 -0700 Subject: [PATCH 3/4] Bugfixes * Fix changes in interfaces.xml not picked up during merge * Sort list of interfaces in display Signed-off-by: Garrick He --- src/CLI/actioner/sonic-cli-sflow.py | 3 +- src/CLI/clitree/cli-xml/interface.xml | 444 +++++++++++++++++++++----- src/CLI/clitree/cli-xml/sflow.xml | 53 +-- 3 files changed, 397 insertions(+), 103 deletions(-) mode change 100755 => 100644 src/CLI/clitree/cli-xml/sflow.xml diff --git a/src/CLI/actioner/sonic-cli-sflow.py b/src/CLI/actioner/sonic-cli-sflow.py index e49d9b7998..7ac8ac4d5d 100755 --- a/src/CLI/actioner/sonic-cli-sflow.py +++ b/src/CLI/actioner/sonic-cli-sflow.py @@ -3,7 +3,6 @@ import time import json import ast -import sonic_sflow_client from collections import OrderedDict from scripts.render_cli import show_cli_output @@ -35,7 +34,7 @@ def run(func, args): sflow_info = {'sflow' : {'admin_state' : 'enabled', 'polling-interval' : 20, 'agent-id' : 'default'}} else: sflow_info = {} - sflow_info['sflow'] = {} + 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) diff --git a/src/CLI/clitree/cli-xml/interface.xml b/src/CLI/clitree/cli-xml/interface.xml index 19e7cb7784..47fc5e311c 100644 --- a/src/CLI/clitree/cli-xml/interface.xml +++ b/src/CLI/clitree/cli-xml/interface.xml @@ -1,85 +1,365 @@ - - - - - - -]> - - + + + + + - - - - - + + + + + + + + + + + + + if test "${if-subcommands}" = "status"; then + python $SONIC_CLI_ROOT/sonic-cli-if.py get_openconfig_interfaces_interfaces show_interface_status.j2 ${__full_line} + elif test "${if-subcommands}" = "counters"; then + python $SONIC_CLI_ROOT/sonic-cli-if.py get_openconfig_interfaces_interfaces show_interface_counters.j2 ${__full_line} + else + if test "${phy-if-id}" = ""; then + python $SONIC_CLI_ROOT/sonic-cli-if.py get_openconfig_interfaces_interfaces show_interface.j2 ${__full_line} + else + python $SONIC_CLI_ROOT/sonic-cli-if.py get_openconfig_interfaces_interfaces_interface Ethernet${phy-if-id} show_interface_id.j2 ${__full_line} + fi + fi + + + + + + + + python $SONIC_CLI_ROOT/sonic-cli-if.py get_openconfig_vlan_interfaces_interface_ethernet_switched_vlan_state show_vlan.j2 + + + + + + + + + + + - - - if test "${if-subcommands}" = "status"; then - python $SONIC_CLI_ROOT/sonic-cli-if.py get_openconfig_interfaces_interfaces show_interface_status.j2 - elif test "${if-subcommands}" = "counters"; then - python $SONIC_CLI_ROOT/sonic-cli-if.py get_openconfig_interfaces_interfaces show_interface_counters.j2 - else - if test "${phy-if-id}" = ""; then - python $SONIC_CLI_ROOT/sonic-cli-if.py get_openconfig_interfaces_interfaces show_interface.j2 - else - python $SONIC_CLI_ROOT/sonic-cli-if.py get_openconfig_interfaces_interfaces_interface Ethernet${phy-if-id} show_interface_id.j2 - fi - fi - - - - - - - - - - - - - - - - - - - - - - - - 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 - - - - python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface_config_description ${iface} ${desc} - - - python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface_config_description ${iface} "" - - - - python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface_config_mtu ${iface} ${mtu} - - - python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface_config_mtu ${iface} 9100 - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface_config_description ${iface} ${desc} + + + python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface_config_description ${iface} "" + + + + python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface_config_mtu ${iface} ${mtu} + + + python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface_config_mtu ${iface} 9100 + + + 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 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/CLI/clitree/cli-xml/sflow.xml b/src/CLI/clitree/cli-xml/sflow.xml old mode 100755 new mode 100644 index abc5e1ff71..95dfb5ff67 --- a/src/CLI/clitree/cli-xml/sflow.xml +++ b/src/CLI/clitree/cli-xml/sflow.xml @@ -1,22 +1,37 @@ - - - - - - -]> - - - - python $SONIC_CLI_ROOT/sonic-cli-sflow.py get_openconfig_lldp_lldp_interfaces show_sflow.j2 - - - - python $SONIC_CLI_ROOT/sonic-cli-sflow.py get_openconfig_lldp_lldp_interfaces show_sflow_intf.j2 - - - + + + + + + + + + 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 + + From 3701f8144fa4bb957858f404fc88790794bea551 Mon Sep 17 00:00:00 2001 From: Garrick He Date: Thu, 3 Oct 2019 14:29:24 -0700 Subject: [PATCH 4/4] Add missing sFlow configuration commands * Add missing sFlow configuration commands * Updated some CLIs to follow CLISH guidelines Signed-off-by: Garrick He --- src/CLI/clitree/cli-xml/interface.xml | 26 ++++++---- src/CLI/clitree/cli-xml/sflow.xml | 74 +++++++++++++++++---------- 2 files changed, 61 insertions(+), 39 deletions(-) diff --git a/src/CLI/clitree/cli-xml/interface.xml b/src/CLI/clitree/cli-xml/interface.xml index 1de96dd859..d429b75669 100644 --- a/src/CLI/clitree/cli-xml/interface.xml +++ b/src/CLI/clitree/cli-xml/interface.xml @@ -365,18 +365,22 @@ limitations under the License. - - + + - - - - - - - - - + + + + + + + + + + + + + - - - - 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 - - - - - - - - - - - - - - - - + + + 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 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +