04-04-2022 02:16 PM
Hello Everyone,
I am doing a simple config push to Cisco Sandbox and hitting an issue. Any help to know what's wrong is very appreciated.
from ncclient import manager import xmltodict if __name__ == '__main__': ios_xe={'address' : 'sandbox-iosxe-latest-1.cisco.com' , 'port' : '830' , 'username' : 'developer' , 'password': 'C1sco12345' } netconf_filter=open('filterconfigusername-iosxe.xml').read() print(netconf_filter) with manager.connect(host=ios_xe['address'], port=ios_xe['port'], username=ios_xe['username'], password=ios_xe['password'], hostkey_verify=False, look_for_keys=False) as m: result = m.edit_config(target = 'running' , config =netconf_filter) print(result) reply = m.commit() print(reply)
Execution of it fails as below:
/usr/local/bin/python3 /Users/amandes4/Documents/Python/Devnet-Study/NetConf/NetConf-IOS-XE/5.edit_user_config.py !!!!!This is the Configuration push!!!!!! <config> <native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native"> <username> <name>restconf</name> <privilege>15</privilege> <secret> <encryption>0</encryption> <secret>restconf</secret> </secret> </username> </native> </config> Traceback (most recent call last): File "/Users/user/Documents/Python/NetConf/NetConf-IOS-XE/5.edit_user_config.py", line 18, in <module> result = m.edit_config(target = 'running' , config =netconf_filter) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/ncclient/manager.py", line 226, in execute return cls(self._session, File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/ncclient/operations/edit.py", line 69, in request return self._request(node) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/ncclient/operations/rpc.py", line 360, in _request raise self._reply.error ncclient.operations.rpc.RPCError: {'type': 'protocol', 'tag': 'unknown-element', 'app_tag': None, 'severity': 'error', 'info': '<?xml version="1.0" encoding="UTF-8"?><error-info xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><bad-element>config</bad-element>\n</error-info>\n', 'path': '\n /rpc/edit-config\n ', 'message': None}
Could be due to some code changes that also affect 'edit-config' operation like 'get-config' operation discussed in "https://community.cisco.com/t5/yang-tools/netconf-error-in-ios-xe-on-csr-latest-code-always-on-devnet/m-p/4451438"
csr1000v-1#show version
Cisco IOS XE Software, Version 17.03.01a
Regards
Aman
04-19-2022 09:53 AM
Hi @amandes4,
I would try reformatting the code based on the examples on page 26, 49 and 51 of Introduction to Model Driven Programmability: Breaking down YANG, NETCONF, and RESTCONF.
Best,
Alex S.
01-07-2023 09:18 AM
Hi @amandes4 ,
the problem you are facing is at the tag <config>, so you suhld replace it with <config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
The new XML should be :
<config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> <native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native"> <username> <name>restconf</name> <privilege>15</privilege> <secret> <encryption>0</encryption> <secret>restconf</secret> </secret> </username> </native> </config>
This should solve your problem, also keep in mind different IOS XE Software, Version has different YANG structures
Best of luck
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