cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
3273
Views
11
Helpful
3
Replies

Having Problemas Editing a File NETCONF

Hi I'm having some trouble running this script. I'm trying to edit the configuration I have but I encounter this:

 

CODE

============================================================

from ncclient import manager

HOST = "ios-xe-mgmt.cisco.com"
NETCONF_PORT = 10000
USER = "developer"
PASS = "C1sco12345"

netconf_template = """
<config>
  <interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces">
    <interface>
      <name>{int_name}</name>
      <description>{int_desc}</description>
      <type xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">ianaift:ethernetCsmacd</type>
      <enabled>true</enabled>
      <ipv4 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip">
        <address>
          <ip>{ip_address}</ip>
          <netmask>{subnet_mask}</netmask>
        </address>
      </ipv4>
    </interface>
  </interfaces>
</config>
"""

if __name__ == "__main__":

    netconf_payload = netconf_template.format(int_name="GigabitEthernet2",
                                            int_desc="Configured on real time",
                                            ip_address="10.255.255.1",
                                            subnet_mask="255.255.255.0"
                                            )

    print("Configuration Payload:")
    print("==========================")
    print(netconf_payload)

    with manager.connect(
        host=HOST,
        port=NETCONF_PORT,
        username=USER,
        password=PASS,
        hostkey_verify=False
        ) as m:

        netconf_reply = m.edit_config(netconf_payload, target="running")

        print(netconf_reply)
===========================================================
ERROR
File "c:/Users/Administrator/OneDrive/Documentos/Visual Studio Code/config_try1.py", line 47, in <module>
netconf_reply = m.edit_config(netconf_payload, target="running")
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38-32\lib\site-packages\ncclient\manager.py", line 231, in execute
return cls(self._session,
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38-32\lib\site-packages\ncclient\operations\edit.py", line 67, in request
return self._request(node)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38-32\lib\site-packages\ncclient\operations\rpc.py", line 349, in _request
raise self._reply.error
ncclient.operations.rpc.RPCError: Unsupported capability :writable-running
 
I guess it's because I can't edit a file when its actually running, what could be the other option for target
 
Thanks!!
1 Accepted Solution

Accepted Solutions

Hello guys again! I've editing my code and the thing is that if you delete from the netconf_reply variable the target you will receive the RPC-reply ok 

 

 netconf_reply = m.edit_config(netconf_payload)

 

Sorry! And I hope it helps!

View solution in original post

3 Replies 3

Hello guys again! I've editing my code and the thing is that if you delete from the netconf_reply variable the target you will receive the RPC-reply ok 

 

 netconf_reply = m.edit_config(netconf_payload)

 

Sorry! And I hope it helps!

I was having the same problem but when I remove the target I will get a ok reply but the configuration is not changing 

Hi there,

 

The solution specified will not work since you are not changing anything if you do not specify the target. You will still receive the "OK" message but the changes you have done will not affect the device.

According to ncclient docs "Where a method takes a source or target argument, usually, a datastore name or URL is expected. The latter depends on the: URL capability and on whether the specific URL scheme is supported. Either must be specified as a string. For example, “running”, “ftp://user:pass@host/config”."

You probably have the configuration

netconf-yang feature candidate-datastore

which will transform "running" mode to "candidate".

To solve an issue you can remove the command from a device as follows,

no netconf-yang feature candidate-datastore

It works even if you change target="candidate". You will still receiving OK message but actually nothing changed in the device. To make changes transfer to running-config you need to send m.commit() command within the script after edit_config command.

According to ncclient documentation commit(confirmed=False, timeout=None, persist=None)

A confirmed commit (i.e. if confirmed is True) is reverted if there is no followup commit within the timeout interval. If no timeout is specified the confirm timeout defaults to 600 seconds (10 minutes). A confirming commit may have the confirmed parameter but this is not required. It depends on the: confirmed-commit capability.

 

My device is ASR1004 with IOS XE 16.9.4 just for info.

Hope it will help those who struggle on it like I was struggling while watching "Cisco Life"))