|
21 | 21 | import time
|
22 | 22 | import json
|
23 | 23 | import ast
|
24 |
| -import yaml |
25 | 24 | import openconfig_interfaces_client
|
26 | 25 | from rpipe_utils import pipestr
|
27 | 26 | from openconfig_interfaces_client.rest import ApiException
|
@@ -94,95 +93,76 @@ def run(func, args):
|
94 | 93 | c.verify_ssl = False
|
95 | 94 | aa = openconfig_interfaces_client.OpenconfigInterfacesApi(api_client=openconfig_interfaces_client.ApiClient(configuration=c))
|
96 | 95 |
|
97 |
| -# Code for Portchannel cli skeleton, reading and writing data to port_channel_dummy_data json file |
| 96 | +# Code for PortChannel cli skeleton |
| 97 | + |
98 | 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") |
| 99 | + if "PortChannel" in args[0] and func.__name__ == 'patch_openconfig_interfaces_interfaces_interface': |
116 | 100 | return
|
117 | 101 |
|
| 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 | + |
118 | 134 | #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": |
124 | 138 | show_cli_output("show_portchannel_id.j2", dict)
|
125 | 139 | return
|
126 | 140 | print("%Error: Entry not found")
|
127 | 141 | return
|
128 | 142 |
|
129 | 143 | #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) |
134 | 146 | return
|
135 | 147 |
|
136 | 148 | #add members to port-channel
|
137 | 149 | 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 | 150 | return
|
150 | 151 |
|
151 | 152 | #remove members from port-channel
|
152 | 153 | if func.__name__ == 'delete_openconfig_if_aggregate_interfaces_interface_ethernet_config_aggregate_id':
|
153 |
| - return("Success") |
| 154 | + return |
154 | 155 |
|
155 | 156 | #config mtu for port-channel
|
156 | 157 | if "po" in args[0] and func.__name__ == 'patch_openconfig_interfaces_interfaces_interface_config_mtu':
|
157 |
| - return("Success") |
| 158 | + return |
158 | 159 |
|
159 | 160 | #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': |
171 | 162 | return
|
172 | 163 |
|
173 | 164 | #config min-links in port-channel
|
174 | 165 | 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 | 166 | return
|
187 | 167 |
|
188 | 168 | # create a body block
|
|
0 commit comments