09-29-2024 08:26 PM
Hello,
Attached you will a find a script to add a loopback interface to a Cisco device.
And when the config is sent to the device, I am receiving the following error:
$ python3 add_loopback2.py
What loopback number to add? 10
What description to use? tes_loop10
What IP address? 100.0.0.10
What network mask? 255.0.0.0
The configuration payload to be sent over NETCONF.
<config>
<interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces">
<interface>
<name>Loopback10</name>
<description>tes_loop10</description>
<type xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">
ianaift:softwareLoopback
</type>
<enabled>true</enabled>
<ipv4 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip">
<address>
<ip>100.0.0.10</ip>
<netmask>255.0.0.0</netmask>
</address>
</ipv4>
</interface>
</interfaces>
</config>
Opening NETCONF Connection to sandbox-iosxe-recomm-1.cisco.com
Sending a <edit-config> operation to the device.
Traceback (most recent call last):
File "add_loopback2.py", line 102, in <module>
netconf_reply = m.edit_config(netconf_data, target = 'running')
File "/usr/local/lib/python3.8/dist-packages/ncclient/manager.py", line 212, in execute
return cls(self._session,
File "/usr/local/lib/python3.8/dist-packages/ncclient/operations/edit.py", line 67, in request
return self._request(node)
File "/usr/local/lib/python3.8/dist-packages/ncclient/operations/rpc.py", line 341, in _request
raise self._reply.error
ncclient.operations.rpc.RPCError: {'type': 'protocol', 'tag': 'unknown-element', '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}
This lab is based on Exploring IOS XE YANG Data Models with NETCONF.
I would appreciate any helo/advise.
Thanks.
Solved! Go to Solution.
09-30-2024 12:12 AM - edited 09-30-2024 12:15 AM
Hi @Netmart
Make sure your script adds the NETCONF namespace to the config-tag, your payload should look like this (notice the change in the first line):
<config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces">
<interface>
<name>Loopback10</name>
<description>tes_loop10</description>
<type xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">ianaift:softwareLoopback</type>
<enabled>true</enabled>
<ipv4 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip">
<address>
<ip>100.0.0.10</ip>
<netmask>255.0.0.0</netmask>
</address>
</ipv4>
</interface>
</interfaces>
</config>
09-30-2024 12:12 AM - edited 09-30-2024 12:15 AM
Hi @Netmart
Make sure your script adds the NETCONF namespace to the config-tag, your payload should look like this (notice the change in the first line):
<config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces">
<interface>
<name>Loopback10</name>
<description>tes_loop10</description>
<type xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">ianaift:softwareLoopback</type>
<enabled>true</enabled>
<ipv4 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip">
<address>
<ip>100.0.0.10</ip>
<netmask>255.0.0.0</netmask>
</address>
</ipv4>
</interface>
</interfaces>
</config>
10-06-2024 10:52 PM
Thank you Marcel.
Yes, this was missing.
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