<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Netconf to retrieve ospf configuration using Python in Tools</title>
    <link>https://community.cisco.com/t5/tools/netconf-to-retrieve-ospf-configuration-using-python/m-p/4514253#M1415</link>
    <description>&lt;P&gt;Thank you&lt;/P&gt;</description>
    <pubDate>Tue, 07 Dec 2021 04:10:36 GMT</pubDate>
    <dc:creator>sqambera</dc:creator>
    <dc:date>2021-12-07T04:10:36Z</dc:date>
    <item>
      <title>Netconf to retrieve ospf configuration using Python</title>
      <link>https://community.cisco.com/t5/tools/netconf-to-retrieve-ospf-configuration-using-python/m-p/4513552#M1410</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;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?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;from &lt;/SPAN&gt;xml.dom &lt;SPAN&gt;import &lt;/SPAN&gt;minidom&lt;BR /&gt;&lt;SPAN&gt;from &lt;/SPAN&gt;ncclient &lt;SPAN&gt;import &lt;/SPAN&gt;manager&lt;BR /&gt;&lt;BR /&gt;m = manager.connect(&lt;SPAN&gt;host &lt;/SPAN&gt;= &lt;SPAN&gt;"10.10.20.48"&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;BR /&gt;&lt;/SPAN&gt;                     &lt;SPAN&gt;port &lt;/SPAN&gt;= &lt;SPAN&gt;830&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;BR /&gt;&lt;/SPAN&gt;                     &lt;SPAN&gt;username &lt;/SPAN&gt;= &lt;SPAN&gt;"developer"&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;BR /&gt;&lt;/SPAN&gt;                     &lt;SPAN&gt;password &lt;/SPAN&gt;= &lt;SPAN&gt;"C1sco12345"&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;BR /&gt;&lt;/SPAN&gt;                     &lt;SPAN&gt;hostkey_verify &lt;/SPAN&gt;= &lt;SPAN&gt;False&lt;/SPAN&gt;)&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;print&lt;/SPAN&gt;(m.connected)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;filter_routing = &lt;SPAN&gt;"""&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;lt;filter&amp;gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;lt;ospf xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-ospf"&amp;gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;lt;/ospf&amp;gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;lt;/filter&amp;gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;"""&lt;BR /&gt;&lt;/SPAN&gt;running = m.get_config(&lt;SPAN&gt;"running"&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;filter_routing)&lt;BR /&gt;running_xml = minidom.parseString(running.xml)&lt;BR /&gt;&lt;SPAN&gt;print&lt;/SPAN&gt;(running_xml.toprettyxml(&lt;SPAN&gt;indent &lt;/SPAN&gt;= &lt;SPAN&gt;"  "&lt;/SPAN&gt;))&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;OUTPUT:&lt;BR /&gt;&lt;BR /&gt;C:\Users\Image\PycharmProjects\Netconf\venv\Scripts\python.exe C:/Users/Image/PycharmProjects/Netconf/Routing.py&lt;BR /&gt;True&lt;BR /&gt;&amp;lt;?xml version="1.0" ?&amp;gt;&lt;BR /&gt;&amp;lt;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"&amp;gt;&lt;BR /&gt;&amp;lt;data/&amp;gt;&lt;BR /&gt;&amp;lt;/rpc-reply&amp;gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;The actual ospf configuration on router is following:&lt;BR /&gt;&lt;BR /&gt;csr1000v-1#sh run | section ospf&lt;BR /&gt;router ospf 1&lt;BR /&gt;network 172.16.24.0 0.0.0.255 area 0&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Attached is the XML output of running configuration.&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Qamber&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 Dec 2021 04:30:34 GMT</pubDate>
      <guid>https://community.cisco.com/t5/tools/netconf-to-retrieve-ospf-configuration-using-python/m-p/4513552#M1410</guid>
      <dc:creator>sqambera</dc:creator>
      <dc:date>2021-12-06T04:30:34Z</dc:date>
    </item>
    <item>
      <title>Re: Netconf to retrieve ospf configuration using Python</title>
      <link>https://community.cisco.com/t5/tools/netconf-to-retrieve-ospf-configuration-using-python/m-p/4514032#M1411</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.cisco.com/t5/user/viewprofilepage/user-id/257193"&gt;@sqambera&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="p1"&gt;You are on the right track! Cisco Code Exchange will help you complete the task. I searched there for “ospf, yang, netconf”:&lt;/P&gt;
&lt;P class="p2"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="p3"&gt;&lt;SPAN class="s1"&gt;&lt;A href="https://developer.cisco.com/codeexchange/" target="_blank" rel="noopener"&gt;Cisco Code Exchange&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class="p2"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="p1"&gt;Examples found therein:&lt;/P&gt;
&lt;P class="p2"&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL class="ul1"&gt;
&lt;LI class="li3"&gt;&lt;SPAN class="s1"&gt;&lt;STRONG&gt;&lt;A href="https://github.com/CiscoDevNet/python_code_samples_network/blob/master/NC-get-config/NC-get-config.py" target="_blank" rel="noopener"&gt;NC-get-config.py&lt;/A&gt;&amp;nbsp;&lt;/STRONG&gt;- This script retrieves entire configuration from a network element via NETCONF&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI class="li3"&gt;&lt;SPAN class="s1"&gt;&lt;STRONG&gt;&lt;A href="https://github.com/CiscoDevNet/netconf-examples/blob/master/netconf-102/get_config_csr1000V.py" target="_blank" rel="noopener"&gt;get_config_csr1000V.py&lt;/A&gt;&amp;nbsp;&lt;/STRONG&gt;- Get configured interfaces using Netconf&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI class="li1"&gt;&lt;A href="https://github.com/ncclient/ncclient/blob/master/examples/base/nc02.py" target="_blank" rel="noopener"&gt;ncclinet/nc02.py&lt;/A&gt;&amp;nbsp;- Retrieve the running config from the NETCONF server&lt;/LI&gt;
&lt;/UL&gt;
&lt;P class="p2"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="p1"&gt;Of course, you will need to adjust your code, including filtering results for ospf.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Dec 2021 17:10:05 GMT</pubDate>
      <guid>https://community.cisco.com/t5/tools/netconf-to-retrieve-ospf-configuration-using-python/m-p/4514032#M1411</guid>
      <dc:creator>Alexander Stevenson</dc:creator>
      <dc:date>2021-12-06T17:10:05Z</dc:date>
    </item>
    <item>
      <title>Re: Netconf to retrieve ospf configuration using Python</title>
      <link>https://community.cisco.com/t5/tools/netconf-to-retrieve-ospf-configuration-using-python/m-p/4514050#M1412</link>
      <description>&lt;P&gt;You could also use the native model&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;        rpc = '''
                &amp;lt;config&amp;gt;
                    &amp;lt;native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native"&amp;gt;
                        &amp;lt;router&amp;gt;
                            &amp;lt;ospf xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-ospf"&amp;gt;
                            &amp;lt;/ospf&amp;gt;
                        &amp;lt;/router&amp;gt;
                    &amp;lt;/native&amp;gt;
                &amp;lt;/config&amp;gt;
            '''&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 Dec 2021 17:33:33 GMT</pubDate>
      <guid>https://community.cisco.com/t5/tools/netconf-to-retrieve-ospf-configuration-using-python/m-p/4514050#M1412</guid>
      <dc:creator>bigevilbeard</dc:creator>
      <dc:date>2021-12-06T17:33:33Z</dc:date>
    </item>
    <item>
      <title>Re: Netconf to retrieve ospf configuration using Python</title>
      <link>https://community.cisco.com/t5/tools/netconf-to-retrieve-ospf-configuration-using-python/m-p/4514099#M1413</link>
      <description>&lt;P&gt;Hello &lt;a href="https://community.cisco.com/t5/user/viewprofilepage/user-id/257193"&gt;@sqambera&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;show netconf-yang capabilities | in ospf&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;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|&lt;/PRE&gt;&lt;P&gt;After a bit of trial and error, I found that I could produce useful output with the following filter:&lt;/P&gt;&lt;PRE&gt;filter_routing = """
&amp;lt;filter&amp;gt;            
&amp;lt;ospf xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ipv4-ospf-cfg"&amp;gt;
&amp;lt;/ospf&amp;gt;  
&amp;lt;/filter&amp;gt;
"""&lt;/PRE&gt;&lt;P&gt;The following is a portion of the output:&lt;/P&gt;&lt;PRE&gt;&amp;gt;&amp;gt;&amp;gt; print(running_xml.toprettyxml(indent = "  "))
&amp;lt;?xml version="1.0" ?&amp;gt;
&amp;lt;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"&amp;gt;
  
 
  &amp;lt;data&amp;gt;
    
  
    &amp;lt;ospf xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ipv4-ospf-cfg"&amp;gt;
      
   
      &amp;lt;processes&amp;gt;
        
    
        &amp;lt;process&amp;gt;
          
     
          &amp;lt;process-name&amp;gt;10&amp;lt;/process-name&amp;gt;
          
     
          &amp;lt;nsr&amp;gt;true&amp;lt;/nsr&amp;gt;
          
     
          &amp;lt;default-vrf&amp;gt;
            
      
            &amp;lt;adjacency-changes&amp;gt;detail&amp;lt;/adjacency-changes&amp;gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps!!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;fjm&lt;/P&gt;&lt;P&gt;@ittybittypacket&lt;/P&gt;</description>
      <pubDate>Mon, 06 Dec 2021 19:46:58 GMT</pubDate>
      <guid>https://community.cisco.com/t5/tools/netconf-to-retrieve-ospf-configuration-using-python/m-p/4514099#M1413</guid>
      <dc:creator>fracjackmac</dc:creator>
      <dc:date>2021-12-06T19:46:58Z</dc:date>
    </item>
    <item>
      <title>Re: Netconf to retrieve ospf configuration using Python</title>
      <link>https://community.cisco.com/t5/tools/netconf-to-retrieve-ospf-configuration-using-python/m-p/4514103#M1414</link>
      <description>&lt;P&gt;Hello&lt;a href="https://community.cisco.com/t5/user/viewprofilepage/user-id/257193"&gt;@sqambera&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;By the way, THANKS for your post!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This gave me an opportunity to actually take the leap and start exploring netconf in the lab.&amp;nbsp;&amp;nbsp; &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;fjm&lt;/P&gt;&lt;P&gt;@ittybittypacket&lt;/P&gt;</description>
      <pubDate>Mon, 06 Dec 2021 19:51:22 GMT</pubDate>
      <guid>https://community.cisco.com/t5/tools/netconf-to-retrieve-ospf-configuration-using-python/m-p/4514103#M1414</guid>
      <dc:creator>fracjackmac</dc:creator>
      <dc:date>2021-12-06T19:51:22Z</dc:date>
    </item>
    <item>
      <title>Re: Netconf to retrieve ospf configuration using Python</title>
      <link>https://community.cisco.com/t5/tools/netconf-to-retrieve-ospf-configuration-using-python/m-p/4514253#M1415</link>
      <description>&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Tue, 07 Dec 2021 04:10:36 GMT</pubDate>
      <guid>https://community.cisco.com/t5/tools/netconf-to-retrieve-ospf-configuration-using-python/m-p/4514253#M1415</guid>
      <dc:creator>sqambera</dc:creator>
      <dc:date>2021-12-07T04:10:36Z</dc:date>
    </item>
  </channel>
</rss>

