21
21
import time
22
22
import json
23
23
import ast
24
+ import yaml
24
25
import openconfig_interfaces_client
25
26
from rpipe_utils import pipestr
26
27
from openconfig_interfaces_client .rest import ApiException
@@ -44,7 +45,6 @@ def call_method(name, args):
44
45
45
46
def generate_body (func , args ):
46
47
body = None
47
- # Get the rules of all ACL table entries.
48
48
if func .__name__ == 'patch_openconfig_interfaces_interfaces_interface_config_description' :
49
49
keypath = [ args [0 ] ]
50
50
body = { "openconfig-interfaces:description" : args [1 ] }
@@ -94,6 +94,97 @@ def run(func, args):
94
94
c .verify_ssl = False
95
95
aa = openconfig_interfaces_client .OpenconfigInterfacesApi (api_client = openconfig_interfaces_client .ApiClient (configuration = c ))
96
96
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
+
97
188
# create a body block
98
189
keypath , body = generate_body (func , args )
99
190
0 commit comments