-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenauto_functions_iosxe_ebo.py
259 lines (220 loc) · 8.63 KB
/
enauto_functions_iosxe_ebo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
#------MODEL--------------------------
import requests
from enauto_rest_functions_ebo import *
#------USER INTERFACE (VIEW)----------
import tkinter as tk
from enauto_gui_functions_ebo import *
#------CONTROLLER--------------------
import json
import base64
from enauto_functions_interface_ebo import *
#-------------IOS NETCONF OPTIONS-----------
def IOSXE_NETCONF_GET_YANG_INTERFACES(ans1,text_box):
netconf_reply=GET_SCHEMA_IOS_NETCONF(ans1,identifier="ietf-interfaces")
#BORRO LO QUE ESTÁ EN EL TEXT BOX
text_box.config(state="normal") #habilito la escritura
text_box.delete("1.0", tk.END) #para borrar el texto
# text_box.config(state="disabled") #solo lectura
#IMPRIMO EN EL TEXT BOX
text_box.config(state="normal") #habilito la escritura
text_box.insert(tk.END,netconf_reply['rpc-reply']['data']['#text']+"\n")
text_box.config(state="disabled") #solo lectura
def IOSXE_NETCONF_GET_INTERFACES(ans1,text_box):
source="running"
netconf_filter="""
<filter>
<interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces">
<interface></interface>
</interfaces>
</filter>"""
netconf_reply=GET_IOS_NETCONF(ans1,source,netconf_filter)
#BORRO LO QUE ESTÁ EN EL TEXT BOX
text_box.config(state="normal") #habilito la escritura
text_box.delete("1.0", tk.END) #para borrar el texto
# text_box.config(state="disabled") #solo lectura
#IMPRIMO EN EL TEXT BOX
PRINT_RESPONSE(netconf_reply['rpc-reply']['data']['interfaces'],text_box)
def IOSXE_NETCONF_ADD_INTERFACES(ans1,text_box):
target="running"
name="Loopback99"
if_type="ianaift:softwareLoopback"
status="true"
ip_address="192.168.10.2"
mask="255.255.255.0"
netconf_interface_template="""
<config>
<interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces">
<interface>
<name>{name}</name>
<type xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">{if_type}</type>
<enabled>{status}</enabled>
<ipv4 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip">
<address>
<ip>{ip_address}</ip>
<netmask>{mask}</netmask>
</address>
</ipv4>
</interface>
</interfaces>
</config>"""
netconf_data = netconf_interface_template.format(
name = name,
if_type = if_type,
status = status,
ip_address = ip_address,
mask = mask
)
netconf_reply=EDIT_IOS_NETCONF(ans1,target,netconf_data)
#BORRO Y ESCRIBO RESPUESTA EN EL TEXT BOX
text_box.config(state="normal") #habilito la escritura
text_box.delete("1.0", tk.END) #para borrar el texto
PRINT_RESPONSE(netconf_reply,text_box)
def IOSXE_NETCONF_MERGE_DESCRIPTION(ans1,text_box):
target="running"
name="Loopback99"
if_type="ianaift:softwareLoopback"
desc="Testin NETCONF EBO"
netconf_interface_template="""
<config>
<interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces">
<interface operation="merge">
<name>{name}</name>
<type xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">{if_type}</type>
<description>{desc}</description>
</interface>
</interfaces>
</config>"""
netconf_data = netconf_interface_template.format(
name = name,
if_type=if_type,
desc=desc
)
netconf_reply=EDIT_IOS_NETCONF(ans1,target,netconf_data)
#BORRO Y ESCRIBO RESPUESTA EN EL TEXT BOX
text_box.config(state="normal") #habilito la escritura
text_box.delete("1.0", tk.END) #para borrar el texto
PRINT_RESPONSE(netconf_reply,text_box)
def IOSXE_NETCONF_EDIT_INTERFACES(ans1,text_box):
target="running"
name="Loopback99"
desc="Testin NETCONF EBO (change IP ADDRESS)"
if_type="ianaift:softwareLoopback"
ip_address="192.168.10.99"
mask="255.255.255.0"
netconf_interface_template="""
<config>
<interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces">
<interface operation="replace">
<name>{name}</name>
<type xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">{if_type}</type>
<description>{desc}</description>
<ipv4 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip">
<address>
<ip>{ip_address}</ip>
<netmask>{mask}</netmask>
</address>
</ipv4>
</interface>
</interfaces>
</config>"""
netconf_data = netconf_interface_template.format(
name = name,
if_type=if_type,
desc=desc,
ip_address = ip_address,
mask = mask
)
netconf_reply=EDIT_IOS_NETCONF(ans1,target,netconf_data)
#BORRO Y ESCRIBO RESPUESTA EN EL TEXT BOX
text_box.config(state="normal") #habilito la escritura
text_box.delete("1.0", tk.END) #para borrar el texto
PRINT_RESPONSE(netconf_reply,text_box)
def IOSXE_NETCONF_DEL_INTERFACES(ans1,text_box):
target="running"
name="Loopback99"
netconf_interface_template = """
<config>
<interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces">
<interface operation="delete">
<name>{name}</name>
</interface>
</interfaces>
</config>"""
netconf_data = netconf_interface_template.format(
name = name)
netconf_reply=EDIT_IOS_NETCONF(ans1,target,netconf_data)
#BORRO Y ESCRIBO RESPUESTA EN EL TEXT BOX
text_box.config(state="normal") #habilito la escritura
text_box.delete("1.0", tk.END) #para borrar el texto
PRINT_RESPONSE(netconf_reply,text_box)
#-------------IOS RESTCONF OPTIONS-----------
def IOSXE_RESTCONF_GET_HEADERS(ans1,text_box):
headers=SANDBOX_AUTHENTICATION(ans1,text_box)
return headers
def IOSXE_RESTCONF_GET_YANG_INTERFACES(ans1,headers,text_box):
services="netconf-state/capabilities"
response=GET_FUNCTION_EBO(ans1,services,headers,text_box)
PRINT_RESPONSE_JSON(response,text_box)
def IOSXE_RESTCONF_GET_INTERFACES(ans1,headers,text_box):
services="ietf-interfaces:interfaces"
response=GET_FUNCTION_EBO(ans1,services,headers,text_box)
PRINT_RESPONSE_JSON(response,text_box)
def IOSXE_RESTCONF_ADD_INTERFACES(ans1,headers,text_box):
services="ietf-interfaces:interfaces"
data = {
"ietf-interfaces:interface": {
"name": "Loopback99",
"type": "iana-if-type:softwareLoopback",
"enabled": "true",
"ietf-ip:ipv4": {
"address": [
{
"ip": "192.168.10.2",
"netmask": "255.255.255.0"
}
]
},
"ietf-ip:ipv6": {
}
}
}
response=POST_FUNCTION_EBO(ans1,services,headers,text_box,json.dumps(data))
PRINT_STATUS_CODE(response,text_box)
def IOSXE_RESTCONF_MERGE_DESCRIPTION(ans1,headers,text_box):
services="ietf-interfaces:interfaces/interface=Loopback99"
data = {
"ietf-interfaces:interface": {
"name": "Loopback99",
"description": "Testing RESTCONF EBO",
"type": "iana-if-type:softwareLoopback",
"enabled": "true",
}
}
response=PATCH_FUNCTION_EBO(ans1,services,headers,text_box,json.dumps(data))
PRINT_STATUS_CODE(response,text_box)
def IOSXE_RESTCONF_EDIT_INTERFACES(ans1,headers,text_box):
services="ietf-interfaces:interfaces/interface=Loopback99"
data = {
"ietf-interfaces:interface": {
"name": "Loopback99",
"description": "Testing RESTCONF EBO changing IP ADDRESS",
"type": "iana-if-type:softwareLoopback",
"enabled": "true",
"ietf-ip:ipv4": {
"address": [
{
"ip": "192.168.10.99",
"netmask": "255.255.255.0"
}
]
},
"ietf-ip:ipv6": {
}
}
}
response=PUT_FUNCTION_EBO(ans1,services,headers,text_box,json.dumps(data))
PRINT_STATUS_CODE(response,text_box)
def IOSXE_RESTCONF_DEL_INTERFACES(ans1,headers,text_box):
services="ietf-interfaces:interfaces/interface=Loopback99"
response=DELETE_FUNCTION_EBO(ans1,services,headers,text_box)
PRINT_STATUS_CODE(response,text_box)