Skip to content

Commit 006737e

Browse files
committed
Changes to remove dummy json file
Signed-off-by: Tejaswi Goel <[email protected]>
1 parent fffeffc commit 006737e

File tree

5 files changed

+50
-118
lines changed

5 files changed

+50
-118
lines changed

src/CLI/actioner/port_channel_dummy_data.json

Lines changed: 0 additions & 48 deletions
This file was deleted.

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

Lines changed: 43 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import time
2222
import json
2323
import ast
24-
import yaml
2524
import openconfig_interfaces_client
2625
from rpipe_utils import pipestr
2726
from openconfig_interfaces_client.rest import ApiException
@@ -94,95 +93,76 @@ def run(func, args):
9493
c.verify_ssl = False
9594
aa = openconfig_interfaces_client.OpenconfigInterfacesApi(api_client=openconfig_interfaces_client.ApiClient(configuration=c))
9695

97-
# Code for Portchannel cli skeleton, reading and writing data to port_channel_dummy_data json file
96+
# Code for PortChannel cli skeleton
97+
9898
#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")
99+
if "PortChannel" in args[0] and func.__name__ == 'patch_openconfig_interfaces_interfaces_interface':
116100
return
117101

102+
dummy_data= {
103+
"openconfig-interfaces:interface": [
104+
{
105+
"members": [
106+
"Ethernet56",
107+
"Ethernet60"
108+
],
109+
"min-links": 2,
110+
"mtu": 9100,
111+
"admin_status": "up",
112+
"oper_status": "down",
113+
"name": "PortChannel1"
114+
},
115+
{
116+
"members": [],
117+
"min-links": 1,
118+
"mtu": 9100,
119+
"admin_status": "up",
120+
"oper_status": "down",
121+
"name": "PortChannel2"
122+
},
123+
{
124+
"members": [],
125+
"min-links": 1,
126+
"mtu": 9100,
127+
"admin_status": "up",
128+
"oper_status": "down",
129+
"name": "PortChannel3"
130+
}
131+
]
132+
}
133+
118134
#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]:
135+
if "PortChannel" in args[0] and func.__name__ == 'get_openconfig_if_aggregate_interfaces_interface_aggregation_state':
136+
for dict in dummy_data['openconfig-interfaces:interface']:
137+
if dict["name"] == "PortChannel3":
124138
show_cli_output("show_portchannel_id.j2", dict)
125139
return
126140
print("%Error: Entry not found")
127141
return
128142

129143
#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)
144+
if "PortChannel" in args[0] and func.__name__ == 'get_openconfig_interfaces_interfaces':
145+
show_cli_output("show_portchannel.j2", dummy_data)
134146
return
135147

136148
#add members to port-channel
137149
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")
149150
return
150151

151152
#remove members from port-channel
152153
if func.__name__ == 'delete_openconfig_if_aggregate_interfaces_interface_ethernet_config_aggregate_id':
153-
return("Success")
154+
return
154155

155156
#config mtu for port-channel
156157
if "po" in args[0] and func.__name__ == 'patch_openconfig_interfaces_interfaces_interface_config_mtu':
157-
return("Success")
158+
return
158159

159160
#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")
161+
if "PortChannel" in args[0] and func.__name__ == 'delete_openconfig_interfaces_interfaces_interface':
171162
return
172163

173164
#config min-links in port-channel
174165
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")
186166
return
187167

188168
# create a body block

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ limitations under the License.
6363
>
6464
<PARAM
6565
name="lag-id"
66-
help="Portchannel identifier"
66+
help="PortChannel identifier"
6767
ptype="UINT"
6868
optional="true"
6969
>
@@ -84,9 +84,9 @@ limitations under the License.
8484
python $SONIC_CLI_ROOT/sonic-cli-if.py get_openconfig_interfaces_interfaces show_interface_counters.j2&#xA;
8585
elif test "${if-subcommands}" = "port-channel"; then&#xA;
8686
if test "${lag-id}" = ""; then&#xA;
87-
python $SONIC_CLI_ROOT/sonic-cli-if.py get_openconfig_interfaces_interfaces Portchannel show_portchannel.j2&#xA;
87+
python $SONIC_CLI_ROOT/sonic-cli-if.py get_openconfig_interfaces_interfaces PortChannel show_portchannel.j2&#xA;
8888
else&#xA;
89-
python $SONIC_CLI_ROOT/sonic-cli-if.py get_openconfig_if_aggregate_interfaces_interface_aggregation_state Portchannel${lag-id} show_portchannel_id.j2#xA;
89+
python $SONIC_CLI_ROOT/sonic-cli-if.py get_openconfig_if_aggregate_interfaces_interface_aggregation_state PortChannel${lag-id} show_portchannel_id.j2#xA;
9090
fi
9191
else&#xA;
9292
if test "${phy-if-id}" = ""; then&#xA;
@@ -151,7 +151,7 @@ limitations under the License.
151151
ptype="UINT"
152152
>
153153
</PARAM>
154-
<ACTION>python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface Portchannel${lag-id}</ACTION>
154+
<ACTION>python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface PortChannel${lag-id}</ACTION>
155155
</COMMAND>
156156

157157
<!-- no interface commands -->
@@ -195,7 +195,7 @@ limitations under the License.
195195
python $SONIC_CLI_ROOT/sonic-cli-if.py delete_openconfig_interfaces_interfaces_interface Vlan${vlan-id}&#xA;
196196
fi&#xA;
197197
if test "${if-subcommands}" = "port-channel"; then&#xA;
198-
python $SONIC_CLI_ROOT/sonic-cli-if.py delete_openconfig_interfaces_interfaces_interface Portchannel${lag-id}&#xA;
198+
python $SONIC_CLI_ROOT/sonic-cli-if.py delete_openconfig_interfaces_interfaces_interface PortChannel${lag-id}&#xA;
199199
fi
200200
</ACTION>
201201
</COMMAND>

src/CLI/renderer/templates/show_portchannel.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ Flags: A - Active, Dw - Oper status down
55
{{'%-20s'|format("Port-Channel")}}{{'%-20s'|format("min-links")}}{{'%-20s'|format("Protocol")}}{{'%-15s'|format("MTU")}}{{'%-15s'|format("Admin")}}{{'%-15s'|format("port-members")}}
66
{{'----------------------------------------------------------------------------------------------------------------------------'}}
77
{% for dict in json_output['openconfig-interfaces:interface'] %}
8-
{{'%-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("]", ""))}}
8+
{{'%-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("]", ""))}}
99
{% endfor %}

src/CLI/renderer/templates/show_portchannel_id.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ Flags: A - Active, Dw - Oper status down
55
{{'%-20s'|format("Port-Channel")}}{{'%-20s'|format("min-links")}}{{'%-20s'|format("Protocol")}}{{'%-15s'|format("MTU")}}{{'%-15s'|format("Admin")}}{{'%-15s'|format("port-members")}}
66
{{'----------------------------------------------------------------------------------------------------------------------------'}}
77
{% set dict = json_output %}
8-
{{'%-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("]", ""))}}
8+
{{'%-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("]", ""))}}

0 commit comments

Comments
 (0)