/
async_edit_config_iosxr.py
63 lines (50 loc) · 1.68 KB
/
async_edit_config_iosxr.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
"""async_edit_config_iosxr"""
import asyncio
from scrapli_netconf import AsyncNetconfDriver
IOSXR_DEVICE = {
"host": "172.18.0.13",
"auth_username": "vrnetlab",
"auth_password": "VR-netlab9",
"auth_strict_key": False,
"transport": "asyncssh",
}
EDIT_INTERFACE_G_0_0_0_0 = """
<config>
<interface-configurations xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-cfg">
<interface-configuration>
<active>act</active>
<interface-name>GigabitEthernet0/0/0/0</interface-name>
<description>skfasjdlkfjdsf</description>
<ipv4-network xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ipv4-io-cfg">
<addresses>
<primary>
<address>10.10.0.1</address>
<netmask>255.255.255.0</netmask>
</primary>
</addresses>
</ipv4-network>
</interface-configuration>
</interface-configurations>
</config>
"""
async def main():
"""Edit config example"""
# create scrapli_netconf connection just like with scrapli, open the connection
conn = AsyncNetconfDriver(**IOSXR_DEVICE)
await conn.open()
# lock the candidate config before starting because why not
result = await conn.lock(target="candidate")
print(result.result)
config = EDIT_INTERFACE_G_0_0_0_0
result = await conn.edit_config(config=config, target="candidate")
print(result.result)
# commit config changes
result = await conn.commit()
print(result.result)
# unlock the candidate now that we're done
result = await conn.unlock(target="candidate")
print(result.result)
# close the session
await conn.close()
if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())