cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
677
Views
0
Helpful
1
Replies

Trying to write an xml file based on yang module on IOS-XE (NETCONF)

aalnemer
Cisco Employee
Cisco Employee

Hi, I am trying to create a location identifier in IOS-XE using python and xml. 

The yang schema is here: https://github.com/YangModels/yang/blob/main/vendor/cisco/xe/1671/Cisco-IOS-XE-native.yang

This is my try to write the xml file based on the yang schema

my_try = '''
<config>
    <location xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native"> 
        <civic-location>
            <identifier>
                <identifier>"Hello"</identifier>
                <building>"Amsterdam Building"</building>
                <floor>"4th floor"</floor>
                <landmark>"IKEA"</landmark>
                <name>"Abdulmohsen"</name>
             </identifier>
        </civic-location>
    </location> 
 </config>
'''

And this the python code I used to edit the config in IOS-XE:

with manager.connect(**router,hostkey_verify=False) as m:
    response1 = m.edit_config(my_try,target='running')
    result_dict = xmltodict.parse(response1.xml)
    print(result_dict)

 But I get this error: 

Traceback (most recent call last):
  File "/Users/aalnemer/DevNetPractise/ENAUTO/IOS-XE.py", line 84, in <module>
    response1 = m.edit_config(my_try,target='running')
  File "/Users/aalnemer/DevNetPractise/ENAUTO/lib/python3.9/site-packages/ncclient/manager.py", line 246, in execute
    return cls(self._session,
  File "/Users/aalnemer/DevNetPractise/ENAUTO/lib/python3.9/site-packages/ncclient/operations/edit.py", line 76, in request
    return self._request(node)
  File "/Users/aalnemer/DevNetPractise/ENAUTO/lib/python3.9/site-packages/ncclient/operations/rpc.py", line 375, in _request
    raise self._reply.error
ncclient.operations.rpc.RPCError: {'type': 'application', '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>location</bad-element>\n</error-info>\n', 'path': '\n    /nc:rpc/nc:edit-config/nc:config/ios:location\n  ', 'message': None}
1 Accepted Solution

Accepted Solutions

aalnemer
Cisco Employee
Cisco Employee

I found my mistake. Thanks! 

View solution in original post

1 Reply 1

aalnemer
Cisco Employee
Cisco Employee

I found my mistake. Thanks!