Skip to content

CLI skeleton for Port channel #134

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

Merged
merged 5 commits into from
Oct 2, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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
72 changes: 72 additions & 0 deletions src/CLI/actioner/sonic-cli-if.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,78 @@ def run(func, args):
c.verify_ssl = False
aa = openconfig_interfaces_client.OpenconfigInterfacesApi(api_client=openconfig_interfaces_client.ApiClient(configuration=c))

# Code for PortChannel cli skeleton

#create a port-channel
if "PortChannel" in args[0] and func.__name__ == 'patch_openconfig_interfaces_interfaces_interface':
return

dummy_data= {
"openconfig-interfaces:interface": [
{
"members": [
"Ethernet56",
"Ethernet60"
],
"min-links": 2,
"mtu": 9100,
"admin_status": "up",
"oper_status": "down",
"name": "PortChannel1"
},
{
"members": [],
"min-links": 1,
"mtu": 9100,
"admin_status": "up",
"oper_status": "down",
"name": "PortChannel2"
},
{
"members": [],
"min-links": 1,
"mtu": 9100,
"admin_status": "up",
"oper_status": "down",
"name": "PortChannel3"
}
]
}

#show given port-channel details
if "PortChannel" in args[0] and func.__name__ == 'get_openconfig_if_aggregate_interfaces_interface_aggregation_state':
for dict in dummy_data['openconfig-interfaces:interface']:
if dict["name"] == "PortChannel3":
show_cli_output("show_portchannel_id.j2", dict)
return
print("%Error: Entry not found")
return

#show port-channels summary
if "PortChannel" in args[0] and func.__name__ == 'get_openconfig_interfaces_interfaces':
show_cli_output("show_portchannel.j2", dummy_data)
return

#add members to port-channel
if func.__name__ == 'patch_openconfig_if_aggregate_interfaces_interface_ethernet_config_aggregate_id':
return

#remove members from port-channel
if func.__name__ == 'delete_openconfig_if_aggregate_interfaces_interface_ethernet_config_aggregate_id':
return

#config mtu for port-channel
if "po" in args[0] and func.__name__ == 'patch_openconfig_interfaces_interfaces_interface_config_mtu':
return

#delete port-channel
if "PortChannel" in args[0] and func.__name__ == 'delete_openconfig_interfaces_interfaces_interface':
return

#config min-links in port-channel
if func.__name__ == 'patch_openconfig_if_aggregate_interfaces_interface_aggregation_config_min_links':
return

# create a body block
keypath, body = generate_body(func, args)

Expand Down
147 changes: 147 additions & 0 deletions src/CLI/clitree/cli-xml/interface.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,28 @@ limitations under the License.
</ACTION>
</COMMAND>

<COMMAND
name="show port-channel"
help="Show vlan commands"
ptype="SUBCOMMAND"
mode="subcommand"
>
<PARAM
name="lag-id"
help="PortChannel identifier"
ptype="UINT"
optional="true"
>
</PARAM>
<ACTION>
if test "${lag-id}" = ""; then&#xA;
python $SONIC_CLI_ROOT/sonic-cli-if.py get_openconfig_interfaces_interfaces PortChannel show_portchannel.j2&#xA;
else&#xA;
python $SONIC_CLI_ROOT/sonic-cli-if.py get_openconfig_if_aggregate_interfaces_interface_aggregation_state PortChannel${lag-id} show_portchannel_id.j2#xA;
fi
</ACTION>
</COMMAND>

</VIEW>

<VIEW
Expand Down Expand Up @@ -139,6 +161,23 @@ limitations under the License.
<ACTION builtin="clish_nop"></ACTION>
</COMMAND>

<COMMAND
name="interface port-channel"

Choose a reason for hiding this comment

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

Example, it has to be interface PortChannel

help="port-channel Interface Configuration"
mode="subcommand"
ptype="SUBCOMMAND"
view="configure-lag-view"
viewid="po_id=po${lag-id}"
>
<PARAM
name="lag-id"
help="port-channel identifier(1-128)"
ptype="UINT"
>
</PARAM>
<ACTION>python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface PortChannel${lag-id}</ACTION>
</COMMAND>

<!-- no interface commands -->
<COMMAND
name="no interface"
Expand All @@ -162,10 +201,23 @@ limitations under the License.
ptype="VLAN_ID"
/>
</PARAM>
<PARAM
name="port-channel"

Choose a reason for hiding this comment

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

Before merging, need one thing to get clarified. "port-channel" is represented as PortChannel in Kernel, so need to get confirmation on what naming convention we go for interface name commands. Say for Interface, we go as Ethernet . I guess it would be better to go with the same name for CLI command. Let me confirm with Joyas, will get back soon.

Choose a reason for hiding this comment

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

Just talked with @joyas-joseph , lets have the name "PortChannel" (name used in Kernel) to be consistent across all the CLI. Sorry for not pointing this out earlier. I did it wrong for vlan too, I will fix it.

help="Delete port-channel"
mode="subcommand"
ptype="SUBCOMMAND"
>
<PARAM
name="lag-id"
help="port-channel identifier(1-128)"
ptype="UINT"
/>
</PARAM>
</PARAM>
<ACTION builtin="clish_nop"></ACTION>
</COMMAND>
</VIEW>

<VIEW
name="configure-if-view"
prompt="${SYSTEM_NAME}(conf-if-${iface})# "
Expand Down Expand Up @@ -209,6 +261,20 @@ 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
name="channel-group"
help="Configure port channel parameters">
<PARAM
name="lag-id"
help="Specify a port channel number"
ptype="UINT" />
<ACTION>python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_if_aggregate_interfaces_interface_ethernet_config_aggregate_id ${iface} ${lag-id} </ACTION>
</COMMAND>
<COMMAND
name="no channel-group"
help="Remove from port channel group">
<ACTION>python $SONIC_CLI_ROOT/sonic-cli-if.py delete_openconfig_if_aggregate_interfaces_interface_ethernet_config_aggregate_id ${iface} </ACTION>
</COMMAND>
<COMMAND
name="shutdown"
help="Disable the interface">
Expand Down Expand Up @@ -350,5 +416,86 @@ limitations under the License.
completion="false"
/>
</VIEW>
<VIEW
name="configure-lag-view"
prompt="${SYSTEM_NAME}(conf-if-${po_id})# "
depth="2"
>
<!-- Inheritance -->
<NAMESPACE
ref="configure-view"
help="false"
completion="false"
/>

<COMMAND
name="no"
help="Negate a command or set its defaults"
/>
<COMMAND
name="min-links"
help="Configure the minimum number of links in a port-channel">
<PARAM
name="min-links"
help="Configure the minimum number of links in a port-channel"
ptype="UINT" />
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we know max. no. of ports that can be added to port-channel?

<ACTION>python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_if_aggregate_interfaces_interface_aggregation_config_min_links ${po_id} ${min-links} </ACTION>
</COMMAND>
<COMMAND
name="no min-links"
help="Default the minimum number of links in a port channel" >
<ACTION>python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_if_aggregate_interfaces_interface_aggregation_config_min_links ${po_id} 1 </ACTION>
</COMMAND>
<COMMAND
name="mtu"
help="Configure 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>
</COMMAND>
<COMMAND
name="no mtu"
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
name="shutdown"
help="Disable the interface">
</COMMAND>
<COMMAND
name="no shutdown"
help="Enable the interface">
</COMMAND>
<COMMAND
name="ip"
help="Interface Internet Protocol config commands"
/>
<COMMAND
name="no ip"
help="Interface Internet Protocol config commands"
>
</COMMAND>

<COMMAND
name="ip address"
help="IP address" >
<PARAM
name="addr"
help="IP address with mask"
ptype="IP_ADDR_MASK" />
</COMMAND>

<COMMAND
name="no ip address"
help="Interface Internet Protocol config commands"
>
<PARAM
name="addr"
help="IP address"
ptype="IP_ADDR" />
</COMMAND>
</VIEW>
</CLISH_MODULE>

9 changes: 9 additions & 0 deletions src/CLI/renderer/templates/show_portchannel.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% set just_var = 2 %}

Flags: A - Active, Dw - Oper status down
{{'----------------------------------------------------------------------------------------------------------------------------'}}
{{'%-20s'|format("Port-Channel")}}{{'%-20s'|format("min-links")}}{{'%-20s'|format("Protocol")}}{{'%-15s'|format("MTU")}}{{'%-15s'|format("Admin")}}{{'%-15s'|format("port-members")}}
{{'----------------------------------------------------------------------------------------------------------------------------'}}
{% for dict in json_output['openconfig-interfaces:interface'] %}
{{'%-20s'|format(dict['name']|string)}}{{'%-20s'|format(dict['min-links'])}}{{'%-20s'|format("LACP(A)(Dw)")}}{{'%-15s'|format(dict['mtu'])}}{{'%-15s'|format(dict['admin_status'])}}{{'%-15s'|format(dict['members']|string|replace("[", "")|replace("]", ""))}}
{% endfor %}
8 changes: 8 additions & 0 deletions src/CLI/renderer/templates/show_portchannel_id.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% set just_var = 2 %}

Flags: A - Active, Dw - Oper status down
{{'----------------------------------------------------------------------------------------------------------------------------'}}
{{'%-20s'|format("Port-Channel")}}{{'%-20s'|format("min-links")}}{{'%-20s'|format("Protocol")}}{{'%-15s'|format("MTU")}}{{'%-15s'|format("Admin")}}{{'%-15s'|format("port-members")}}
{{'----------------------------------------------------------------------------------------------------------------------------'}}
{% set dict = json_output %}
{{'%-20s'|format(dict['name']|string)}}{{'%-20s'|format(dict['min-links'])}}{{'%-20s'|format("LACP(A)")}}{{'%-15s'|format(dict['mtu'])}}{{'%-15s'|format(dict['admin_status'])}}{{'%-15s'|format(dict['members']|string|replace("[", "")|replace("]", ""))}}