Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sFlow CLI Template #147

Merged
merged 7 commits into from
Oct 3, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:])
23 changes: 17 additions & 6 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 @@ -181,7 +181,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 @@ -209,12 +209,12 @@ limitations under the License.
help="Remove MTU">
<ACTION>python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface_config_mtu ${iface} 9100 </ACTION>
</COMMAND>
<COMMAND
<COMMAND
name="shutdown"
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 @@ -281,8 +281,19 @@ limitations under the License.
</PARAM>
<ACTION builtin="clish_nop"></ACTION>
</COMMAND>
<COMMAND name="sflow" help="enable sflow">
<PARAM name="sampling-rate" help="sFlow sampling rate" ptype="SUBCOMMAND" mode="subcommand" optional="true">
<PARAM name="rate" help="sampling rate" ptype="UINT"/>
</PARAM>
<PARAM name="admin-status" help="sFlow status for interface" ptype="SUBCOMMAND" mode="subcommand" optional="true">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In your HLD, this parameter was called enable rather than admin-status.

If both of the PARAMs under here are optional="true" then will this result in a user being able to configure just sflow by itself? I don't think we should allow that.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, I think enable is a better keyword than admin-status, since "admin status" is typically used to describe the enable/disable of an interface.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will change.

</PARAM>
<ACTION builtin="clish_nop"/>
</COMMAND>
<COMMAND name="no sflow" help="disable sflow">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be no sflow enable

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will change.

<ACTION builtin="clish_nop"/>
</COMMAND>

<COMMAND
<COMMAND
name="no switchport"
help="Remove switchport parameters"
>
Expand Down
57 changes: 57 additions & 0 deletions src/CLI/clitree/cli-xml/sflow.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?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>
</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>
</COMMAND>
</VIEW>
<VIEW name="configure-view">
<COMMAND name="sflow" help="enable sflow">
<PARAM name="collector" help="Collector name" ptype="SUBCOMMAND" mode="subcommand" optional="true">
<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"/>
</PARAM>
<PARAM name="agent-id" help="Collector agent interface" ptype="SUBCOMMAND" mode="subcommand" optional="true">
<PARAM name="interface" help="Interface name" ptype="STRING"/>
</PARAM>
<ACTION builtin="clish_nop"/>
<PARAM name="polling-interval" help="Collector polling interval" ptype="SUBCOMMAND" mode="subcommand" optional="true">
<PARAM name="interval" help="Interval" ptype="UINT"/>
</PARAM>
</COMMAND>
<COMMAND name="no sflow" help="disable sflow">
<PARAM name="collector" help="Collector name" ptype="SUBCOMMAND" mode="subcommand" optional="true">
<PARAM name="collector-name" help="Collector name" ptype="STRING"/>
</PARAM>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you missing no sflow agent-id and no sflow polling-interval?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will add these.

<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 %}