12-05-2021 08:30 PM
Hello,
I wrote following code to fetch ospf configuration from the CSR router but not able to obtain it. Please see the output. Can anyone please help me know what's wrong?
from xml.dom import minidom
from ncclient import manager
m = manager.connect(host = "10.10.20.48",
port = 830,
username = "developer",
password = "C1sco12345",
hostkey_verify = False)
print(m.connected)
filter_routing = """
<filter>
<ospf xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-ospf">
</ospf>
</filter>
"""
running = m.get_config("running", filter_routing)
running_xml = minidom.parseString(running.xml)
print(running_xml.toprettyxml(indent = " "))
OUTPUT:
C:\Users\Image\PycharmProjects\Netconf\venv\Scripts\python.exe C:/Users/Image/PycharmProjects/Netconf/Routing.py
True
<?xml version="1.0" ?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="urn:uuid:902cbaa2-aea3-4e00-b19a-2278007b50f0">
<data/>
</rpc-reply>
The actual ospf configuration on router is following:
csr1000v-1#sh run | section ospf
router ospf 1
network 172.16.24.0 0.0.0.255 area 0
Attached is the XML output of running configuration.
Thanks,
Qamber
Solved! Go to Solution.
12-06-2021 09:33 AM
You could also use the native model
rpc = ''' <config> <native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native"> <router> <ospf xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-ospf"> </ospf> </router> </native> </config> '''
12-06-2021 09:10 AM
Hello @sqambera,
You are on the right track! Cisco Code Exchange will help you complete the task. I searched there for “ospf, yang, netconf”:
Examples found therein:
Of course, you will need to adjust your code, including filtering results for ospf.
12-06-2021 09:33 AM
You could also use the native model
rpc = ''' <config> <native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native"> <router> <ospf xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-ospf"> </ospf> </router> </native> </config> '''
12-06-2021 11:46 AM - edited 12-06-2021 11:46 AM
Hello @sqambera,
I'm running IOS-XR, so things may be different, but I was able to run the following command on the router to determine the available OSPF namespaces
show netconf-yang capabilities | in ospf
show netconf-yang capabilities | in ospf Mon Dec 6 19:25:57.698 UTC http://cisco.com/ns/yang/Cisco-IOS-XR-ipv4-ospf-act |2016-09-14| http://cisco.com/ns/yang/Cisco-IOS-XR-ipv4-ospf-cfg |2018-05-14| http://cisco.com/ns/yang/Cisco-IOS-XR-ipv4-ospf-oper |2018-04-18| http://cisco.com/ns/yang/Cisco-IOS-XR-ipv6-ospfv3-act |2016-09-14| http://cisco.com/ns/yang/Cisco-IOS-XR-ipv6-ospfv3-cfg |2018-05-14| http://cisco.com/ns/yang/Cisco-IOS-XR-ipv6-ospfv3-oper |2018-06-15|
After a bit of trial and error, I found that I could produce useful output with the following filter:
filter_routing = """ <filter> <ospf xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ipv4-ospf-cfg"> </ospf> </filter> """
The following is a portion of the output:
>>> print(running_xml.toprettyxml(indent = " ")) <?xml version="1.0" ?> <rpc-reply xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="urn:uuid:f7d22dbd-db09-43b1-b0e9-c43909a359f4"> <data> <ospf xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ipv4-ospf-cfg"> <processes> <process> <process-name>10</process-name> <nsr>true</nsr> <default-vrf> <adjacency-changes>detail</adjacency-changes>
Hope this helps!!!
fjm
@ittybittypacket
12-06-2021 11:51 AM
Hello@sqambera,
By the way, THANKS for your post!!
This gave me an opportunity to actually take the leap and start exploring netconf in the lab.
fjm
@ittybittypacket
12-06-2021 08:10 PM
Thank you
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide