Hello, everyone
As mentioned in my previous post, I was planning to include this under the Device Programmability lesson since it covers APIs, RESTCONF, NETCONF, etc, but I actually have rather long questions about every individual protocol and having it all in 1 post would be hard to read and very long, so I decided to separate them this way.
My first question regarding NETCONF is… how do you guys configure it? What are the best practices? I feel it’s quite complex to actually open up and go through all the YANG models and figure out what container to use, what to configure, etc. A lot of resources use ietf-interfaces as example because it’s short and easy to use, but the others aren’t very easy to work with.
What I usually do is I create one loopback as a test and then retrieve the running configuration. I then use the relevant tags to create the other ones.
In YANG terms, what exactly is a key? I see that every list has one.
Here comes the NETCONF part.
from ncclient import manager
from xml.dom import minidom
device = {
"host": "192.168.170.200",
"port": 830,
"username": "admin",
"password": "cisco",
"hostkey_verify": False
}
ospf_config= """
<config>
<native>
<router operation="merge">
<router-ospf>
<ospf>
<process-id>
<id>110</id>
<network>
<ip>0.0.0.0</ip>
<wildcard>255.255.255.255</wildcard>
<area>0</area>
</network>
</process-id>
</ospf>
</router-ospf>
</router>
</native>
</config>
"""
with manager.connect(**device) as netconnect:
result = netconnect.edit_config(target="running", config=ospf_config).xml
print(minidom.parseString(result).toprettyxml())
This configuration on its own refuses to work unless I do this with the ospf_config variable
ospf_config= """
<config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">
<router operation="merge">
<router-ospf xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-ospf">
<ospf>
<process-id>
<id>110</id>
<network>
<ip>0.0.0.0</ip>
<wildcard>255.255.255.255</wildcard>
<area>0</area>
</network>
</process-id>
</ospf>
</router-ospf>
</router>
</native>
</config>
"""
Basically, the <config>
part has xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"
added and native
plus router-ospf
also have an xmlns that refers to the YANG model they come from
Is this part absolutely necessary for the code to work? Without it, the device doesn’t get configured.
That’s all, thank you.
David