-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnect_netconf_test.py
65 lines (48 loc) · 1.3 KB
/
connect_netconf_test.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
import ncclient, xmltodict, json, pprint
from xml.etree import ElementTree
from ncclient import manager
from device_info import Lab_7750
import logging
#logging.basicConfig(
# level=logging.DEBUG,
#)
conn = manager.connect(host=Lab_7750["address"],
port=Lab_7750["port"],
username=Lab_7750["username"],
password=Lab_7750["password"],
hostkey_verify=False)
rtr = conn.server_capabilities
print(type(rtr))
print(rtr)
#for x in conn.server_capabilities:
# if "port" in x:
# print(x)
# print(x)
schema = conn.get_schema("nokia-types-port")
print(schema)
#result = conn.get_config('running')
#print(result.xml)
#interfacefilter = """
#<filter>
# <configure xmlns="urn:nokia.com:sros:ns:yang:sr:conf">
# <router>
#
# </router>
# </configure>
#</filter>
#"""
portfilter = """
<filter>
<configure xmlns="urn:nokia.com:sros:ns:yang:sr:conf">
<port>
</port>
</configure>
</filter>
"""
#result = conn.get_config('running', filter=interfacefilter)
#print(result.xml)
result = conn.get_config('running', filter=portfilter)
config = xmltodict.parse(result.xml)["rpc-reply"]["data"]
jsonconfig = json.dumps(config, indent=4)
print(jsonconfig)
conn.close_session()