09-10-2020 02:29 AM
I'm testing interface configuration using NetconfService, but i get the following error:
Traceback (most recent call last): File "test.py", line 32, in <module> service.edit_config(provider=provider, target=Datastore.candidate, config=ifc) File "/home/sima-dev/.local/lib/python3.6/site-packages/ydk/services/netconf_service.py", line 103, in edit_config default_operation, test_option, error_option) File "/usr/lib/python3.6/contextlib.py", line 99, in __exit__ self.gen.throw(type, value, traceback) File "/home/sima-dev/.local/lib/python3.6/site-packages/ydk/errors/error_handler.py", line 82, in handle_runtime_error _raise(_exc) File "/home/sima-dev/.local/lib/python3.6/site-packages/ydk/errors/error_handler.py", line 54, in _raise exec("raise exc from None") File "<string>", line 1, in <module> ydk.errors.YServiceProviderError: Unsupported capability :candidate
And I found this in the output of the logger:
<error-message xml:lang="en">Unsupported capability :candidate</error-message>
Should Datastore.candidate be a supported capability on the device? I thought this was implied as long as the device supported netconf!
Here is the code: (This is my first time configuring via netconf, so it might also be something that I'm doing wrong in the code)
import logging import ydk.models.cisco_ios_xe.Cisco_IOS_XE_interfaces_oper as ifc_oper from ydk.services.netconf_service import NetconfService from ydk.services import Datastore from ydk.providers.netconf_provider import NetconfServiceProvider def enable_logging(level): log = logging.getLogger('ydk') log.setLevel(level) handler = logging.StreamHandler() formatter = logging.Formatter( "%(asctime)s - %(name)s - %(levelname)s - %(message)s") handler.setFormatter(formatter) log.addHandler(handler) if __name__ == "__main__": enable_logging(logging.INFO) service = NetconfService() provider = NetconfServiceProvider(address="ip", username="username", password="password") model = ifc_oper.Interfaces() ifc = ifc_oper.Interfaces.Interface() ifc.name = "GigabitEthernet0/0/7" ifc.description = "test description" model.interface.append(ifc) service.edit_config(provider=provider, target=Datastore.candidate, config=ifc) interface = service.get(provider=provider, read_filter=ifc) print(interface.description)
Solved! Go to Solution.
09-15-2020 10:26 AM
Hi Mahdi
The issue here is that you are using status model Cisco_IOS_XE_interfaces_oper to do the interface configuration. That is why you are getting not-writable error. Please use Cisco_IOS_XE_interfaces_cfg model for interface configuration, then you can use status model to get interface status.
09-10-2020 10:36 PM
Hi Mahdi
The script looks fine. The issue could be with the router, which apparently does not support candidate datastore. Try simply replace this line:
service.edit_config(provider=provider, target=Datastore.running, config=ifc)
09-11-2020 01:47 AM
I get this when I run the code with Datastore.running:
Traceback (most recent call last): File "/home/sima-dev/simon_dev/pyenivest/customer_unit/test.py", line 33, in <module> service.edit_config(provider=provider, target=Datastore.running, config=ifc) File "/home/sima-dev/.local/lib/python3.6/site-packages/ydk/services/netconf_service.py", line 103, in edit_config default_operation, test_option, error_option) File "/usr/lib/python3.6/contextlib.py", line 99, in exit self.gen.throw(type, value, traceback) File "/home/sima-dev/.local/lib/python3.6/site-packages/ydk/errors/error_handler.py", line 82, in handle_runtime_error _raise(_exc) File "/home/sima-dev/.local/lib/python3.6/site-packages/ydk/errors/error_handler.py", line 54, in _raise exec("raise exc from None") File "<string>", line 1, in <module> ydk.errors.YServiceProviderError: object is not writable 2020-09-11 08:28:32,136 - ydk - INFO - Disconnected from device
What are the best practices for configuration? using running datastore or candidate?
09-11-2020 09:13 AM
When you connect to the Netconf service using NetconfServiceProvider, it reads device capabilities (logged only on DEBUG level). Here example for Cisco IOS XE. YDK sends request RPC:
2020-09-11 08:56:04,605 - ydk - DEBUG - Trace: Writing message (session
<?xml version="1.0" encoding="UTF-8"?>
<hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<capabilities>
<capability>urn:ietf:params:netconf:base:1.0</capability
<capability>urn:ietf:params:netconf:base:1.1</capability>
<capability>urn:ietf:params:netconf:capability:writable-running:1.0</capability>
<capability>urn:ietf:params:netconf:capability:candidate:1.0</capability>
<capability>urn:ietf:params:netconf:capability:startup:1.0</capability>
<capability>urn:ietf:params:netconf:capability:rollback-on-error:1.0</capability>
</capabilities>
</hello>
Receives from device:
2020-09-11 08:56:05,133 - ydk - DEBUG - Trace: Received message (session
<?xml version="1.0" encoding="UTF-8"?>
<hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<capabilities>
<capability>urn:ietf:params:netconf:base:1.0</capability>
<capability>urn:ietf:params:netconf:base:1.1</capability>
<capability>urn:ietf:params:netconf:capability:writable-running:1.0</capability>
<capability>urn:ietf:params:netconf:capability:xpath:1.0</capability>
<capability>urn:ietf:params:netconf:capability:validate:1.0</capability>
<capability>urn:ietf:params:netconf:capability:validate:1.1</capability>
<capability>urn:ietf:params:netconf:capability:rollback-on-error:1.0</capability>
<capability>urn:ietf:params:netconf:capability:notification:1.0</capability>
<capability>urn:ietf:params:netconf:capability:interleave:1.0</capability>
<capability>urn:ietf:params:netconf:capability:with-defaults:1.0?basic-mode=explicit&also-supported=report-all-tagged</capability>
<capability>urn:ietf:params:netconf:capability:yang-library:1.0?revision=2016-06-21&module-set-id=730825758336af65af9606c071685c05</capability>
<capability>http://tail-f.com/ns/netconf/actions/1.0</capability>
Here you can see that the device supports only running datastore, which means you can write configuration directly to running configuration.
Alternatively, the IOS XR supports candidate configuration, which means that all device configurations must be done in the candidate datastore and then committed to the running config.
Please run your script with DEBUG logging level and check what capabilities your device is supporting. Attach the log to the post for better understanding of what is going on.
09-12-2020 12:16 AM
09-12-2020 06:10 PM - edited 09-15-2020 10:17 AM
Something wrong with connectivity to the device - the YDK connects to device, gets all the capabilities, gets YANG1.1 capabilities and then unexpectedly sends disconnect request.
2020-09-12 07:09:31,568 - ydk - INFO - Connected to FRD-ASR920-Utviklingtest01 on port 830 using ssh with timeout of -1
2020-09-12 07:09:31,575 - ydk - INFO - Disconnected from device
2020-09-12 07:09:31,576 - ydk - DEBUG - Trace: Writing message (session 102):
<?xml version="1.0" encoding="UTF-8"?>
<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="2">
<close-session/>
</rpc>
2020-09-12 07:09:31,618 - ydk - DEBUG - Trace: Received message (session 102):
<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="2"><ok/></rpc-reply>
There are no error messages. Very strange!
Could you please try to pass top entity to the netconf service call, like this:
ifcs = ifc_oper.Interfaces() ifc = ifc_oper.Interfaces.Interface() ifc.name = "GigabitEthernet0/0/7" ifc.description = "test description" ifcs.interface.append(ifc)
service.edit_config(provider=provider, target=Datastore.running, config=ifcs)
interfaces = service.get(provider=provider, read_filter=ifc_oper.Interfaces())
09-13-2020 11:11 PM
09-14-2020 09:14 AM
Again, you are trying to write to 'candidate' datastore, which is not supported on your device. Error:
<error-message xml:lang="en">Unsupported capability :candidate</error-message>
You need to write directly to the 'running' datastore.
09-14-2020 01:24 PM
09-15-2020 10:26 AM
Hi Mahdi
The issue here is that you are using status model Cisco_IOS_XE_interfaces_oper to do the interface configuration. That is why you are getting not-writable error. Please use Cisco_IOS_XE_interfaces_cfg model for interface configuration, then you can use status model to get interface status.
09-15-2020 11:04 AM
Aahh of course, I see now!
Should've checked the first lines in the script and not obsessed over the code and the logger output.
Thanks a lot! everything works flawlessly now.
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