Skip to content

Commit 8f67a66

Browse files
authored
Merge pull request #134 from project-arlo/cli-portChannel
CLI skeleton for Port channel
2 parents 1e06004 + 4474149 commit 8f67a66

File tree

4 files changed

+259
-1
lines changed

4 files changed

+259
-1
lines changed

src/CLI/actioner/sonic-cli-if.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,72 @@ def run(func, args):
9595
c.verify_ssl = False
9696
aa = openconfig_interfaces_client.OpenconfigInterfacesApi(api_client=openconfig_interfaces_client.ApiClient(configuration=c))
9797

98+
# Code for PortChannel cli skeleton
99+
100+
#create a port-channel
101+
if "PortChannel" in args[0] and func.__name__ == 'patch_openconfig_interfaces_interfaces_interface':
102+
return
103+
104+
#show port-channels summary
105+
if "PortChannel" in args[0] and func.__name__ == 'get_openconfig_interfaces_interfaces':
106+
107+
dummy_resp= {
108+
"PORTCHANNEL": [
109+
{
110+
"members": [
111+
"Ethernet56",
112+
"Ethernet60"
113+
],
114+
"min-links": 2,
115+
"mtu": 9100,
116+
"admin_status": "up",
117+
"oper_status": "down",
118+
"name": "PortChannel1",
119+
"id": "1"
120+
},
121+
{
122+
"members": [],
123+
"min-links": 1,
124+
"mtu": 9100,
125+
"admin_status": "up",
126+
"oper_status": "down",
127+
"name": "PortChannel12",
128+
"id": "12"
129+
},
130+
{
131+
"members": [],
132+
"min-links": 1,
133+
"mtu": 9100,
134+
"admin_status": "up",
135+
"oper_status": "down",
136+
"name": "PortChannel3",
137+
"id": "3"
138+
}
139+
]
140+
}
141+
show_cli_output(args[1], dummy_resp)
142+
return
143+
144+
#add members to port-channel
145+
if func.__name__ == 'patch_openconfig_if_aggregate_interfaces_interface_ethernet_config_aggregate_id':
146+
return
147+
148+
#remove members from port-channel
149+
if func.__name__ == 'delete_openconfig_if_aggregate_interfaces_interface_ethernet_config_aggregate_id':
150+
return
151+
152+
#config mtu for port-channel
153+
if "po" in args[0] and func.__name__ == 'patch_openconfig_interfaces_interfaces_interface_config_mtu':
154+
return
155+
156+
#delete port-channel
157+
if "PortChannel" in args[0] and func.__name__ == 'delete_openconfig_interfaces_interfaces_interface':
158+
return
159+
160+
#config min-links in port-channel
161+
if func.__name__ == 'patch_openconfig_if_aggregate_interfaces_interface_aggregation_config_min_links':
162+
return
163+
98164
# create a body block
99165
keypath, body = generate_body(func, args)
100166

src/CLI/clitree/cli-xml/interface.xml

Lines changed: 169 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,20 @@ limitations under the License.
9696
</ACTION>
9797
</COMMAND>
9898

99+
<COMMAND
100+
name="show PortChannel"
101+
help="LAG status and configuration"
102+
ptype="SUBCOMMAND"
103+
mode="subcommand" />
104+
<COMMAND
105+
name="show PortChannel summary"
106+
help="LAG status and configurationn"
107+
mode="subcommand">
108+
<ACTION>
109+
python $SONIC_CLI_ROOT/sonic-cli-if.py get_openconfig_interfaces_interfaces PortChannel show_portchannel.j2
110+
</ACTION>
111+
</COMMAND>
112+
99113
</VIEW>
100114

101115
<VIEW
@@ -139,6 +153,23 @@ limitations under the License.
139153
<ACTION builtin="clish_nop"></ACTION>
140154
</COMMAND>
141155

156+
<COMMAND
157+
name="interface PortChannel"
158+
help="Port channel Interface Configuration"
159+
mode="subcommand"
160+
ptype="SUBCOMMAND"
161+
view="configure-lag-view"
162+
viewid="po_id=po${lag-id}"
163+
>
164+
<PARAM
165+
name="lag-id"
166+
help="PortChannel identifier"
167+
ptype="LAG_ID"
168+
>
169+
</PARAM>
170+
<ACTION>python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface PortChannel${lag-id}</ACTION>
171+
</COMMAND>
172+
142173
<!-- no interface commands -->
143174
<COMMAND
144175
name="no interface"
@@ -162,10 +193,23 @@ limitations under the License.
162193
ptype="VLAN_ID"
163194
/>
164195
</PARAM>
196+
<PARAM
197+
name="PortChannel"
198+
help="Delete PortChannel"
199+
mode="subcommand"
200+
ptype="SUBCOMMAND"
201+
>
202+
<PARAM
203+
name="lag-id"
204+
help="PortChannel identifier"
205+
ptype="LAG_ID"
206+
/>
207+
</PARAM>
165208
</PARAM>
166209
<ACTION builtin="clish_nop"></ACTION>
167210
</COMMAND>
168211
</VIEW>
212+
169213
<VIEW
170214
name="configure-if-view"
171215
prompt="${SYSTEM_NAME}(conf-if-${iface})# "
@@ -209,7 +253,47 @@ limitations under the License.
209253
help="Remove MTU">
210254
<ACTION>python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface_config_mtu ${iface} 9100 </ACTION>
211255
</COMMAND>
212-
<COMMAND
256+
<COMMAND
257+
name="channel-group"
258+
help="Configure port channel parameters"
259+
>
260+
<!-- channel-group <number> -->
261+
<PARAM
262+
name="lag-id"
263+
help="Specify a port channel number"
264+
ptype="LAG_ID"
265+
>
266+
<!-- channel-group <number> mode [active] -->
267+
<PARAM
268+
name="mode"
269+
help="Set the LACP actor mode, default: ACTIVE"
270+
ptype="SUBCOMMAND"
271+
mode="subcommand"
272+
optional="true">
273+
<PARAM
274+
name="portchannel-mode-switch"
275+
help="Specify channeling mode"
276+
ptype="SUBCOMMAND"
277+
mode="switch"
278+
>
279+
<PARAM
280+
name="active"
281+
help="Set channeling mode to ACTIVE"
282+
ptype="SUBCOMMAND"
283+
mode="subcommand"
284+
/>
285+
</PARAM>
286+
</PARAM>
287+
</PARAM>
288+
<ACTION>python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_if_aggregate_interfaces_interface_ethernet_config_aggregate_id ${iface} ${lag-id} </ACTION>
289+
</COMMAND>
290+
291+
<COMMAND
292+
name="no channel-group"
293+
help="Remove from port channel group">
294+
<ACTION>python $SONIC_CLI_ROOT/sonic-cli-if.py delete_openconfig_if_aggregate_interfaces_interface_ethernet_config_aggregate_id ${iface} </ACTION>
295+
</COMMAND>
296+
<COMMAND
213297
name="shutdown"
214298
help="Disable the interface">
215299
<ACTION>python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface_config_enabled ${iface} False </ACTION>
@@ -350,5 +434,89 @@ limitations under the License.
350434
completion="false"
351435
/>
352436
</VIEW>
437+
<VIEW
438+
name="configure-lag-view"
439+
prompt="${SYSTEM_NAME}(conf-if-${po_id})# "
440+
depth="2"
441+
>
442+
<!-- Inheritance -->
443+
<NAMESPACE
444+
ref="configure-view"
445+
help="false"
446+
completion="false"
447+
/>
448+
449+
<COMMAND
450+
name="no"
451+
help="Negate a command or set its defaults"
452+
/>
453+
<COMMAND
454+
name="min-links"
455+
help="Configure the minimum number of links in a PortChannel">
456+
<PARAM
457+
name="min-links"
458+
help="Configure the minimum number of links in a PortChannel"
459+
ptype="MIN_LINK" />
460+
<ACTION>python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_if_aggregate_interfaces_interface_aggregation_config_min_links ${po_id} ${min-links} </ACTION>
461+
</COMMAND>
462+
<COMMAND
463+
name="no min-links"
464+
help="Default the minimum number of links in a port channel" >
465+
<ACTION>python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_if_aggregate_interfaces_interface_aggregation_config_min_links ${po_id} 1 </ACTION>
466+
</COMMAND>
467+
<COMMAND
468+
name="mtu"
469+
help="Configure MTU">
470+
<PARAM
471+
name="mtu"
472+
help="MTU of the interface"
473+
ptype="RANGE_MTU" />
474+
<ACTION>python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface_config_mtu ${po_id} ${mtu} </ACTION>
475+
</COMMAND>
476+
<COMMAND
477+
name="no mtu"
478+
help="Remove MTU">
479+
<ACTION>python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface_config_mtu ${po_id} 9100 </ACTION>
480+
</COMMAND>
481+
<COMMAND
482+
name="shutdown"
483+
help="Disable the interface">
484+
<ACTION builtin="clish_nop"></ACTION>
485+
</COMMAND>
486+
<COMMAND
487+
name="no shutdown"
488+
help="Enable the interface">
489+
<ACTION builtin="clish_nop"></ACTION>
490+
</COMMAND>
491+
<COMMAND
492+
name="ip"
493+
help="Interface Internet Protocol config commands"
494+
/>
495+
<COMMAND
496+
name="no ip"
497+
help="Interface Internet Protocol config commands"
498+
>
499+
</COMMAND>
500+
<COMMAND
501+
name="ip address"
502+
help="IP address" >
503+
<PARAM
504+
name="addr"
505+
help="IP address with mask"
506+
ptype="IP_ADDR_MASK" />
507+
<ACTION builtin="clish_nop"></ACTION>
508+
</COMMAND>
509+
510+
<COMMAND
511+
name="no ip address"
512+
help="Interface Internet Protocol config commands"
513+
>
514+
<PARAM
515+
name="addr"
516+
help="IP address"
517+
ptype="IP_ADDR" />
518+
<ACTION builtin="clish_nop"></ACTION>
519+
</COMMAND>
520+
</VIEW>
353521
</CLISH_MODULE>
354522

src/CLI/clitree/cli-xml/sonic_types.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,20 @@ limitations under the License.
4141
help=""
4242
/>
4343
<!--=======================================================-->
44+
<PTYPE
45+
name="LAG_ID"
46+
method="integer"
47+
pattern="0..9999"
48+
help=""
49+
/>
50+
<!--=======================================================-->
51+
<PTYPE
52+
name="MIN_LINK"
53+
method="integer"
54+
pattern="1..255"
55+
help=""
56+
/>
57+
<!--=======================================================-->
4458
<PTYPE
4559
name="UNIT_ID"
4660
method="integer"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{% set just_var = 2 %}
2+
Flags: D - Down
3+
U - Up (PortChannel)
4+
5+
{{'----------------------------------------------------------------------------------------------------------------------------'}}
6+
{{'%-20s'|format("Group")}}{{'%-30s'|format("Port-Channel")}}{{'%-20s'|format("Type")}}{{'%-15s'|format("Protocol")}}{{'%-15s'|format("Member Ports")}}
7+
{{'----------------------------------------------------------------------------------------------------------------------------'}}
8+
{% for dict in json_output['PORTCHANNEL'] %}
9+
{{'%-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("]", ""))}}
10+
{% endfor %}

0 commit comments

Comments
 (0)