cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
259
Views
0
Helpful
2
Replies

NETconf - editconfig - add Loopback

Netmart
Level 1
Level 1

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.

1 Accepted Solution

Accepted Solutions

Marcel Zehnder
Spotlight
Spotlight

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>

 

 

 

View solution in original post

2 Replies 2

Marcel Zehnder
Spotlight
Spotlight

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>

 

 

 

Thank you Marcel.

Yes, this was missing.