Skip to content

Commit

Permalink
sFlow CLI Template (#147)
Browse files Browse the repository at this point in the history
* sFlow CLI template

* Add XML skeleton for the sFlow CLI
* Add actioner script
* Add renderer template

Signed-off-by: Garrick He <garrick_he@dell.com>
  • Loading branch information
GarrickHe authored and jeff-yin committed Oct 3, 2019
1 parent 1043f56 commit ecec01e
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 13 deletions.
45 changes: 45 additions & 0 deletions src/CLI/actioner/sonic-cli-sflow.py
Original file line number Diff line number Diff line change
@@ -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:])
41 changes: 28 additions & 13 deletions src/CLI/clitree/cli-xml/interface.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2019 Dell, Inc.
Copyright 2019 Dell, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -13,7 +13,7 @@ distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
-->

<CLISH_MODULE
xmlns="http://www.dellemc.com/sonic/XMLSchema"
Expand Down Expand Up @@ -261,7 +261,7 @@ limitations under the License.
name="no"
help="Negate a command or set its defaults"
/>
<COMMAND
<COMMAND
name="description"
help="Textual description">
<PARAM
Expand Down Expand Up @@ -319,7 +319,7 @@ limitations under the License.
mode="subcommand"
/>
</PARAM>
</PARAM>
</PARAM>
</PARAM>
<ACTION>python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_if_aggregate_interfaces_interface_ethernet_config_aggregate_id ${iface} ${lag-id} </ACTION>
</COMMAND>
Expand All @@ -334,7 +334,7 @@ limitations under the License.
help="Disable the interface">
<ACTION>python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface_config_enabled ${iface} False </ACTION>
</COMMAND>
<COMMAND
<COMMAND
name="no shutdown"
help="Enable the interface">
<ACTION>python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface_config_enabled ${iface} True </ACTION>
Expand Down Expand Up @@ -401,8 +401,23 @@ limitations under the License.
</PARAM>
<ACTION builtin="clish_nop"></ACTION>
</COMMAND>

<COMMAND
<COMMAND name="sflow" help="interface sFlow settings"/>
<COMMAND name="sflow sampling-rate" help="Set sampling-rate" ptype="SUBCOMMAND" mode="subcommand">
<PARAM name="rate" help="sampling rate" ptype="UINT"/>
<ACTION builtin="clish_nop"/>
</COMMAND>
<COMMAND name="sflow enable" help="enable sflow" ptype="SUBCOMMAND" mode="subcommand">
<ACTION builtin="clish_nop"/>
</COMMAND>
<COMMAND name="no sflow" help="disable sflow"/>
<COMMAND name="no sflow sampling-rate" help="set sampling rate to default" ptype="SUBCOMMAND" mode="subcommand">
<PARAM name="rate" help="sampling rate" ptype="UINT"/>
<ACTION builtin="clish_nop"/>
</COMMAND>
<COMMAND name="no sflow enable" help="disable sFlow" ptype="SUBCOMMAND" mode="subcommand">
<ACTION builtin="clish_nop"/>
</COMMAND>
<COMMAND
name="no switchport"
help="Remove switchport parameters"
>
Expand Down Expand Up @@ -486,10 +501,10 @@ limitations under the License.
name="no"
help="Negate a command or set its defaults"
/>
<COMMAND
<COMMAND
name="min-links"
help="Configure the minimum number of links in a PortChannel">
<PARAM
<PARAM
name="min-links"
help="Configure the minimum number of links in a PortChannel"
ptype="MIN_LINK" />
Expand All @@ -503,8 +518,8 @@ limitations under the License.
<COMMAND
name="mtu"
help="Configure MTU">
<PARAM
name="mtu"
<PARAM
name="mtu"
help="MTU of the interface"
ptype="RANGE_MTU" />
<ACTION>python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface_config_mtu ${po_id} ${mtu} </ACTION>
Expand All @@ -514,12 +529,12 @@ limitations under the License.
help="Remove MTU">
<ACTION>python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface_config_mtu ${po_id} 9100 </ACTION>
</COMMAND>
<COMMAND
<COMMAND
name="shutdown"
help="Disable the interface">
<ACTION builtin="clish_nop"></ACTION>
</COMMAND>
<COMMAND
<COMMAND
name="no shutdown"
help="Enable the interface">
<ACTION builtin="clish_nop"></ACTION>
Expand Down
75 changes: 75 additions & 0 deletions src/CLI/clitree/cli-xml/sflow.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
Copyright 2019 Dell, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<CLISH_MODULE
xmlns="http://www.dellemc.com/sonic/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xi="http://www.w3.org/2001/XInclude"
xsi:schemaLocation="http://www.dellemc.com/sonic/XMLSchema
http://www.dellemc.com/sonic/XMLSchema/clish.xsd"
>
<VIEW name="enable-view">
<COMMAND name="show sflow" help="Show sFlow information">
<ACTION> python $SONIC_CLI_ROOT/sonic-cli-sflow.py get_sflow show_sflow.j2 </ACTION>
<xi:include href="include/pipe.xml"/>
</COMMAND>
<COMMAND name="show sflow interface" help="Show sFlow interface information">
<ACTION> python $SONIC_CLI_ROOT/sonic-cli-sflow.py get_sflow_interface show_sflow_intf.j2 </ACTION>
<xi:include href="include/pipe.xml"/>
</COMMAND>
</VIEW>
<VIEW name="configure-view">
<COMMAND name="sflow" help="sFlow Configurations"/>
<COMMAND name="sflow collector" help="Collector name" ptype="SUBCOMMAND" mode="subcommand">
<PARAM name="collector-name" help="Collector name" ptype="STRING"/>
<PARAM name="collector-ip" help="Collector IP address" ptype="STRING"/>
<PARAM name="collector-port" help="Collector port number" ptype="UINT" optional="true"/>
<ACTION builtin="clish_nop"/>
</COMMAND>
<COMMAND name="sflow enable" help="Enable sFlow" ptype="SUBCOMMAND" mode="subcommand">
<ACTION builtin="clish_nop"/>
</COMMAND>
<COMMAND name="sflow agent-id" help="Collector agent interface" ptype="SUBCOMMAND" mode="subcommand">
<PARAM name="interface" help="Interface name" ptype="STRING"/>
<ACTION builtin="clish_nop"/>
</COMMAND>
<COMMAND name="sflow polling-interval" help="Collector polling interval" ptype="SUBCOMMAND" mode="subcommand">
<PARAM name="interval" help="Interval" ptype="UINT"/>
<ACTION builtin="clish_nop"/>
</COMMAND>

<COMMAND name="no sflow" help="Negate sFlow configurations"/>
<COMMAND name="no sflow collector" help="Remove a collector" ptype="SUBCOMMAND" mode="subcommand">
<PARAM name="collector-name" help="Collector name" ptype="STRING"/>
<PARAM name="collector-ip" help="Collector IP address" ptype="STRING"/>
<PARAM name="collector-port" help="Collector port number" ptype="UINT" optional="true"/>
<ACTION builtin="clish_nop"/>
</COMMAND>
<COMMAND name="no sflow enable" help="Disable sFlow" ptype="SUBCOMMAND" mode="subcommand">
<ACTION builtin="clish_nop"/>
</COMMAND>
<COMMAND name="no sflow agent-id" help="Set default agent-id" ptype="SUBCOMMAND" mode="subcommand">
<PARAM name="interface" help="Interface name" ptype="STRING"/>
<ACTION builtin="clish_nop"/>
</COMMAND>
<COMMAND name="no sflow polling-interval" help="Set default polling interval" ptype="SUBCOMMAND" mode="subcommand">
<PARAM name="interval" help="Interval" ptype="UINT"/>
<ACTION builtin="clish_nop"/>
</COMMAND>
</VIEW>
</CLISH_MODULE>
9 changes: 9 additions & 0 deletions src/CLI/renderer/templates/show_sflow.j2
Original file line number Diff line number Diff line change
@@ -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 %}
10 changes: 10 additions & 0 deletions src/CLI/renderer/templates/show_sflow_intf.j2
Original file line number Diff line number Diff line change
@@ -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 %}

0 comments on commit ecec01e

Please sign in to comment.