-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathnetconf_final.py
88 lines (71 loc) · 2.87 KB
/
netconf_final.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
from ncclient import manager
import xmltodict
m = manager.connect(
host="<!!!REPLACEME with router IP address!!!>",
port=<!!!REPLACEME with NETCONF Port number!!!>,
username="admin",
password="cisco",
hostkey_verify=False
)
def create():
netconf_config = """<!!!REPLACEME with YANG data!!!>"""
try:
netconf_reply = netconf_edit_config(netconf_config)
xml_data = netconf_reply.xml
print(xml_data)
if '<ok/>' in xml_data:
return "<!!!REPLACEME with proper message!!!>"
except:
print("Error!")
def delete():
netconf_config = """<!!!REPLACEME with YANG data!!!>"""
try:
netconf_reply = netconf_edit_config(netconf_config)
xml_data = netconf_reply.xml
print(xml_data)
if '<ok/>' in xml_data:
return "<!!!REPLACEME with proper message!!!>"
except:
print("Error!")
def enable():
netconf_config = """<!!!REPLACEME with YANG data!!!>"""
try:
netconf_reply = netconf_edit_config(netconf_config)
xml_data = netconf_reply.xml
print(xml_data)
if '<ok/>' in xml_data:
return "<!!!REPLACEME with proper message!!!>"
except:
print("Error!")
def disable():
netconf_config = """<!!!REPLACEME with YANG data!!!>"""
try:
netconf_reply = netconf_edit_config(netconf_config)
xml_data = netconf_reply.xml
print(xml_data)
if '<ok/>' in xml_data:
return "<!!!REPLACEME with proper message!!!>"
except:
print("Error!")
def netconf_edit_config(netconf_config):
return m.<!!!REPLACEME with the proper Netconf operation!!!>(target="<!!!REPLACEME with NETCONF Datastore!!!>", config=<!!!REPLACEME with netconf_config!!!>)
def status():
netconf_filter = """<!!!REPLACEME with YANG data!!!>"""
try:
# Use Netconf operational operation to get interfaces-state information
netconf_reply = m.<!!!REPLACEME with the proper Netconf operation!!!>(filter=<!!!REPLACEME with netconf_filter!!!>)
print(netconf_reply)
netconf_reply_dict = xmltodict.<!!!REPLACEME with the proper method!!!>(netconf_reply.xml)
# if there data return from netconf_reply_dict is not null, the operation-state of interface loopback is returned
if <!!!REPLACEME with the proper condition!!!>:
# extract admin_status and oper_status from netconf_reply_dict
admin_status = <!!!REPLACEME!!!>
oper_status = <!!!REPLACEME !!!>
if admin_status == 'up' and oper_status == 'up':
return "<!!!REPLACEME with proper message!!!>"
elif admin_status == 'down' and oper_status == 'down':
return "<!!!REPLACEME with proper message!!!>"
else: # no operation-state data
return "<!!!REPLACEME with proper message!!!>"
except:
print("Error!")