-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig-port-7750-json.py
81 lines (71 loc) · 2.06 KB
/
config-port-7750-json.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
from device_info import Lab_7750
from ncclient import manager
import xmltodict
import logging
import json
# Enable logging
#logging.basicConfig(level=logging.DEBUG)
device = {
"host": Lab_7750["address"],
"port": Lab_7750["port"],
"username":Lab_7750["username"],
"password":Lab_7750["password"],
"hostkey_verify":False
}
# NETCONF Config Payload
#config_payload = """
#<config>
# <configure xmlns="urn:nokia.com:sros:ns:yang:sr:conf">
# <port>
# <port-id>1/1/c4/1</port-id>
# <description>config-by-netconf</description>
# <ethernet>
# <mode>hybrid</mode>
# </ethernet>
# </port>
# </configure>
#</config>
#"""
config_payload_json = {
"config": {
"configure": {
"@xmlns": "urn:nokia.com:sros:ns:yang:sr:conf",
"port": {
"port-id": "1/1/c4/1",
"description": "config-by-netconf",
"ethernet": {
"mode": "hybrid"
}
}
}
}
}
#def main():
# # Build the XML Configuration to Send
# try:
# with manager.connect(**device) as m:
# print("Connected to {}".format(Lab_7750["address"]))
# response = m.edit_config(target="candidate", config=config_payload)
# print(response)
# m.commit()
#
# print("Configuration committed.")
#
# except Exception as e:
# print("An error occurred: {}".format(e))
def main():
# Build the XML Configuration to Send
try:
with manager.connect(**device) as m:
print("Connected to {}".format(Lab_7750["address"]))
config_xml = xmltodict.unparse(config_payload_json)
print(config_xml)
response = m.edit_config(target="candidate", config=config_xml)
print(response)
m.validate()
m.commit()
print("Configuration committed.")
except Exception as e:
print("An error occurred: {}".format(e))
if __name__ == '__main__':
main()