forked from jeremycohoe/IOSXE-Zero-Touch-Provisioning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ztp-netconf.py
46 lines (36 loc) · 1.46 KB
/
ztp-netconf.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
Run these CLI first with CLIP
iosp_client -f netconf_enable guestshell 830
iosp_client -f netconf_enable_passwordless guestshell guestshell
from ncclient import manager
import sys
import xml.dom.minidom
HOST = '127.0.0.1'
# use the NETCONF port for your device
PORT = 830
# use the user credentials for your device
USER = 'guestshell'
PASS = 'it will use the key specified and does not use this one here ok'
FILTER = '''
<filter xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">
<hostname></hostname>
</native>
</filter>
'''
def main():
"""
Main method that prints netconf capabilities of remote device.
"""
# Create a NETCONF session to the router with ncclient
with manager.connect(host=HOST, port=PORT, username=USER,
password=PASS, hostkey_verify=False,
device_params={'name': 'default'},
key_filename="/home/guestshell/.ssh/id_rsa_netconf",
allow_agent=False, look_for_keys=True) as m:
# Retrieve the configuraiton
results = m.get_config('running', FILTER)
# Print the output in a readable format
print(xml.dom.minidom.parseString(results.xml).toprettyxml())
if __name__ == '__main__':
sys.exit(main())
print("\n\n *** Finished NETCONF example... *** \n\n")