-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnetconf.py
50 lines (46 loc) · 1.72 KB
/
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
47
48
49
50
import paramiko,time
devices = ['172.16.13.15','172.16.13.14']
conn = paramiko.SSHClient()
conn.set_missing_host_key_policy(paramiko.AutoAddPolicy)
for device in devices:
print(f'Connecting to {device}')
conn.connect(device,
username='admin',
password='admin',
port=22,
look_for_keys=False)
ch = conn.get_transport().open_session()
ch.invoke_subsystem('netconf')
print(f'Sending hello message to {device}')
hello = '<?xml version="1.0"?><nc:hello xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:capabilities><nc:capability>urn:ietf:params:xml:ns:netconf:base:1.0</nc:capability></nc:capabilities></nc:hello>]]>]]>'
ch.send(hello)
print(f'Sending rpc message to {device}')
cmd = '''<?xml version="1.0"?>
<nc:rpc message-id="1" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"
xmlns="http://www.cisco.com/nxos:1.0:if_manager">
<nc:edit-config>
<nc:target>
<nc:running/>
</nc:target>
<nc:config>
<configure>
<__XML__MODE__exec_configure>
<interface>
<ethernet>
<interface>1/42</interface>
<__XML__MODE_if-ethernet>
<__XML__MODE_if-eth-base>
<description>
<desc_line>CSCO_CSSN</desc_line>
</description>
</__XML__MODE_if-eth-base>
</__XML__MODE_if-ethernet>
</ethernet>
</interface>
</__XML__MODE__exec_configure>
</configure>
</nc:config>
</nc:edit-config>
</nc:rpc>]]>]]>'''
ch.send(cmd)
conn.close()