Skip to content

Commit fffeffc

Browse files
committed
CLI skeleton for Port channel
Signed-off-by: Tejaswi Goel <[email protected]>
1 parent 50a2380 commit fffeffc

File tree

5 files changed

+553
-38
lines changed

5 files changed

+553
-38
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"openconfig-interfaces:interface": [
3+
{
4+
"members": [
5+
"Ethernet56",
6+
"Ethernet60"
7+
],
8+
"min-links": 2,
9+
"mtu": 9100,
10+
"admin-status": "up",
11+
"name": "Portchannel0"
12+
},
13+
{
14+
"members": [
15+
"Ethernet64",
16+
"Ethernet68"
17+
],
18+
"min-links": 1,
19+
"mtu": 9100,
20+
"admin-status": "up",
21+
"name": "Portchannel1"
22+
},
23+
{
24+
"members": [
25+
"Ethernet24",
26+
"Ethernet12"
27+
],
28+
"min-links": 1,
29+
"mtu": 9100,
30+
"admin-status": "up",
31+
"name": "Portchannel2"
32+
},
33+
{
34+
"members": [],
35+
"min-links": 1,
36+
"mtu": 9100,
37+
"admin-status": "up",
38+
"name": "Portchannel3"
39+
},
40+
{
41+
"members": [],
42+
"min-links": 1,
43+
"mtu": 9100,
44+
"admin-status": "up",
45+
"name": "Portchannel4"
46+
}
47+
]
48+
}

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

Lines changed: 92 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import time
2222
import json
2323
import ast
24+
import yaml
2425
import openconfig_interfaces_client
2526
from rpipe_utils import pipestr
2627
from openconfig_interfaces_client.rest import ApiException
@@ -44,7 +45,6 @@ def call_method(name, args):
4445

4546
def generate_body(func, args):
4647
body = None
47-
# Get the rules of all ACL table entries.
4848
if func.__name__ == 'patch_openconfig_interfaces_interfaces_interface_config_description':
4949
keypath = [ args[0] ]
5050
body = { "openconfig-interfaces:description": args[1] }
@@ -94,6 +94,97 @@ def run(func, args):
9494
c.verify_ssl = False
9595
aa = openconfig_interfaces_client.OpenconfigInterfacesApi(api_client=openconfig_interfaces_client.ApiClient(configuration=c))
9696

97+
# Code for Portchannel cli skeleton, reading and writing data to port_channel_dummy_data json file
98+
#create a port-channel
99+
if "Portchannel" in args[0] and func.__name__ == 'patch_openconfig_interfaces_interfaces_interface':
100+
with open('port_channel_dummy_data.json', 'r') as f:
101+
data= yaml.safe_load(f)
102+
for dict in data['openconfig-interfaces:interface']:
103+
if dict["name"] == args[0]:
104+
return
105+
body = {
106+
"name": args[0],
107+
"min-links": 1,
108+
"mtu": 9100,
109+
"admin-status": "up",
110+
"members": []
111+
}
112+
data['openconfig-interfaces:interface'].append(body)
113+
with open('port_channel_dummy_data.json', 'w') as f:
114+
json.dump(data, f, sort_keys=True, indent=4)
115+
print ("Success")
116+
return
117+
118+
#show given port-channel details
119+
if "Portchannel" in args[0] and func.__name__ == 'get_openconfig_if_aggregate_interfaces_interface_aggregation_state':
120+
with open('port_channel_dummy_data.json', 'r') as f:
121+
data= yaml.safe_load(f)
122+
for dict in data['openconfig-interfaces:interface']:
123+
if dict["name"] == args[0]:
124+
show_cli_output("show_portchannel_id.j2", dict)
125+
return
126+
print("%Error: Entry not found")
127+
return
128+
129+
#show port-channels summary
130+
if "Portchannel" in args[0] and func.__name__ == 'get_openconfig_interfaces_interfaces':
131+
with open('port_channel_dummy_data.json', 'r') as f:
132+
data= yaml.safe_load(f)
133+
show_cli_output("show_portchannel.j2", data)
134+
return
135+
136+
#add members to port-channel
137+
if func.__name__ == 'patch_openconfig_if_aggregate_interfaces_interface_ethernet_config_aggregate_id':
138+
port_c = 'Portchannel' + args[1]
139+
with open('port_channel_dummy_data.json', 'r') as readf:
140+
data= yaml.safe_load(readf)
141+
for dict in data['openconfig-interfaces:interface']:
142+
if dict["name"] == port_c:
143+
dict["members"].append(args[0])
144+
with open('port_channel_dummy_data.json', 'w') as writef:
145+
json.dump(data, writef, sort_keys=True, indent=4)
146+
print ("Success")
147+
return
148+
print ("Failed-entry not found")
149+
return
150+
151+
#remove members from port-channel
152+
if func.__name__ == 'delete_openconfig_if_aggregate_interfaces_interface_ethernet_config_aggregate_id':
153+
return("Success")
154+
155+
#config mtu for port-channel
156+
if "po" in args[0] and func.__name__ == 'patch_openconfig_interfaces_interfaces_interface_config_mtu':
157+
return("Success")
158+
159+
#delete port-channel
160+
if "Portchannel" in args[0] and func.__name__ == 'delete_openconfig_interfaces_interfaces_interface':
161+
with open('port_channel_dummy_data.json', 'r') as f:
162+
data= yaml.safe_load(f)
163+
for dict in data['openconfig-interfaces:interface']:
164+
if dict["name"] == args[0]:
165+
data['openconfig-interfaces:interface'].remove(dict)
166+
with open('port_channel_dummy_data.json', 'w') as writef:
167+
json.dump(data, writef, sort_keys=True, indent=4)
168+
print ("Success")
169+
return
170+
print ("Failed-entry not found")
171+
return
172+
173+
#config min-links in port-channel
174+
if func.__name__ == 'patch_openconfig_if_aggregate_interfaces_interface_aggregation_config_min_links':
175+
with open('port_channel_dummy_data.json', 'r') as f:
176+
data= yaml.safe_load(f)
177+
port_c = 'Portchannel'+args[0][2:]
178+
for dict in data['openconfig-interfaces:interface']:
179+
if dict["name"] == port_c:
180+
dict["min-links"]=args[1]
181+
with open('port_channel_dummy_data.json', 'w') as f:
182+
json.dump(data, f, sort_keys=True, indent=4)
183+
print ("Success")
184+
return
185+
print ("Failed-entry not found")
186+
return
187+
97188
# create a body block
98189
keypath, body = generate_body(func, args)
99190

0 commit comments

Comments
 (0)