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

CLI skeleton for Port channel #134

Merged
merged 5 commits into from
Oct 2, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
66 changes: 66 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,72 @@ 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

#show port-channels summary
if "PortChannel" in args[0] and func.__name__ == 'get_openconfig_interfaces_interfaces':

dummy_resp= {
"PORTCHANNEL": [
{
"members": [
"Ethernet56",
"Ethernet60"
],
"min-links": 2,
"mtu": 9100,
"admin_status": "up",
"oper_status": "down",
"name": "PortChannel1",
"id": "1"
},
{
"members": [],
"min-links": 1,
"mtu": 9100,
"admin_status": "up",
"oper_status": "down",
"name": "PortChannel12",
"id": "12"
},
{
"members": [],
"min-links": 1,
"mtu": 9100,
"admin_status": "up",
"oper_status": "down",
"name": "PortChannel3",
"id": "3"
}
]
}
show_cli_output(args[1], dummy_resp)
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
170 changes: 169 additions & 1 deletion src/CLI/clitree/cli-xml/interface.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,20 @@ limitations under the License.
</ACTION>
</COMMAND>

<COMMAND
name="show PortChannel"
help="LAG status and configuration"
ptype="SUBCOMMAND"
mode="subcommand" />
<COMMAND

Choose a reason for hiding this comment

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

Better to add PARAM as summary and keep optional="true", rather than adding every PARAM as separate command.

Copy link
Collaborator Author

@Tejaswi-Goel Tejaswi-Goel Sep 30, 2019

Choose a reason for hiding this comment

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

Done it like this here so that summary option selected or not, it is part of command on pressing enter

name="show PortChannel summary"
help="LAG status and configurationn"
mode="subcommand">
<ACTION>
python $SONIC_CLI_ROOT/sonic-cli-if.py get_openconfig_interfaces_interfaces PortChannel show_portchannel.j2
</ACTION>
</COMMAND>

</VIEW>

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

<COMMAND
name="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="PortChannel identifier"
ptype="LAG_ID"
>
</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 +193,23 @@ limitations under the License.
ptype="VLAN_ID"
/>
</PARAM>
<PARAM
name="PortChannel"
help="Delete PortChannel"
mode="subcommand"
ptype="SUBCOMMAND"
>
<PARAM
name="lag-id"
help="PortChannel identifier"
ptype="LAG_ID"
/>
</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,7 +253,47 @@ 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="channel-group"
help="Configure port channel parameters"
>
<!-- channel-group <number> -->
<PARAM
name="lag-id"
help="Specify a port channel number"
ptype="LAG_ID"
>
<!-- channel-group <number> mode [active] -->
<PARAM
name="mode"
help="Set the LACP actor mode, default: ACTIVE"
ptype="SUBCOMMAND"
mode="subcommand"
optional="true">
<PARAM
name="portchannel-mode-switch"
help="Specify channeling mode"
ptype="SUBCOMMAND"
mode="switch"
>
<PARAM
name="active"
help="Set channeling mode to ACTIVE"
ptype="SUBCOMMAND"
mode="subcommand"
/>
</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>

<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">
<ACTION>python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface_config_enabled ${iface} False </ACTION>
Expand Down Expand Up @@ -350,5 +434,89 @@ 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 PortChannel">
<PARAM
name="min-links"
help="Configure the minimum number of links in a PortChannel"
ptype="MIN_LINK" />
<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">
<ACTION builtin="clish_nop"></ACTION>
</COMMAND>
<COMMAND
name="no shutdown"
help="Enable the interface">
<ACTION builtin="clish_nop"></ACTION>
</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" />
<ACTION builtin="clish_nop"></ACTION>
</COMMAND>

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

14 changes: 14 additions & 0 deletions src/CLI/clitree/cli-xml/sonic_types.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@ limitations under the License.
help=""
/>
<!--=======================================================-->
<PTYPE
name="LAG_ID"
method="integer"
pattern="0..9999"

Choose a reason for hiding this comment

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

Does it have to be 1..128? Please confirm.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I initially had it 1..128, but then I found out on Sonic NOS the allowed range is '<0-9999>'

help=""
/>
<!--=======================================================-->
<PTYPE
name="MIN_LINK"
method="integer"
pattern="1..255"
help=""
/>
<!--=======================================================-->
<PTYPE
name="UNIT_ID"
method="integer"
Expand Down
10 changes: 10 additions & 0 deletions src/CLI/renderer/templates/show_portchannel.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% set just_var = 2 %}
Flags: D - Down
U - Up (PortChannel)

{{'----------------------------------------------------------------------------------------------------------------------------'}}
{{'%-20s'|format("Group")}}{{'%-30s'|format("Port-Channel")}}{{'%-20s'|format("Type")}}{{'%-15s'|format("Protocol")}}{{'%-15s'|format("Member Ports")}}
{{'----------------------------------------------------------------------------------------------------------------------------'}}
{% for dict in json_output['PORTCHANNEL'] %}
{{'%-20s'|format(dict['id']|string)}}{{'%-18s'|format(dict['name'])}}{{'%-12s'|format("(D)")}}{{'%-20s'|format("Eth")}}{{'%-15s'|format("LACP")}}{{'%-15s'|format(dict['members']|string|replace("[", "")|replace("]", ""))}}
{% endfor %}