10-08-2017 10:10 AM
Hi,
I am running some scripts against the NETCONF-YANG and RESTCONF sandbox, and appear to be having a problem with deleting configuration. Instantiating a crud object with crud = CrudService() is fine, and works with crud.create(provider, native), however if I try crud.delete(provider, native) I recieve a bad cli error. To check the payload being sent I also have the CodecService instantiated and printing out the XML.
Here is the XML from CodecService
<native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">
<interface>
<GigabitEthernet>
<name>2</name>
<description>CONNECTS TO R1 (gigabitethernet3)</description>
<load-interval>30</load-interval>
<mtu>9192</mtu>
<ip>
<address>
<primary>
<address>198.168.1.1</address>
<mask>255.255.255.0</mask>
</primary>
</address>
</ip>
</GigabitEthernet>
</interface>
</native>
And here is the error being returned when attempting crud.delete
ydk.errors.YPYServiceProviderError: <?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="1">
<rpc-error>
<error-type>application</error-type>
<error-tag>invalid-value</error-tag>
<error-severity>error</error-severity>
<error-message xml:lang="en">inconsistent value: Device refused one or more commands</error-message>
<error-info>
<severity xmlns="http://cisco.com/yang/cisco-ia">error_cli</severity>
<detail xmlns="http://cisco.com/yang/cisco-ia">
<bad-cli>
<bad-command>no redundancy</bad-command>
<error-location>6</error-location>
</bad-cli>
</detail>
</error-info>
I get the same error with crud.delete, irrespective of the configuration generated.
Attached is a copy of the script
I am using the YDK 0.6.0 and have imported the native XE models.
Any advice appreciated
Simon
Solved! Go to Solution.
10-09-2017 02:22 PM
Simon,
Apologies for taking so long to get back to you. I've got a working sample for you to use as a template. The code below will delete the primary and secondary addresses off of an interface, and you should be able to adapt it to other scenarios fairly easily:
#! /usr/bin/env python3
__author__ = 'einarnn'
'''
Working with YDK 0.6.1, XE models against IOS-XE
'''
from ydk.services import CRUDService
from ydk.providers import NetconfServiceProvider
from ydk.filters import YFilter
from ydk.models.cisco_ios_xe import Cisco_IOS_XE_native as xe
import logging
if __name__=='__main__':
logger = logging.getLogger("ydk")
logger.setLevel(logging.INFO)
handler = logging.StreamHandler()
formatter = logging.Formatter(("%(asctime)s - %(name)s - "
"%(levelname)s - %(message)s"))
handler.setFormatter(formatter)
logger.addHandler(handler)
crud = CRUDService()
# set up the thing we want to delete
del_native = xe.Native()
del_intf = xe.Native.Interface.GigabitEthernet()
del_intf.name = "4"
del_intf.ip.address.primary.yfilter = YFilter.remove
del_native.interface.gigabitethernet.append(del_intf)
# connect to the device
provider = NetconfServiceProvider(address='172.16.20.1',
port=2223,
username='vagrant',
password='vagrant',
protocol='ssh')
crud.update(provider, del_native)
And here's a sample log from running the test now:
$ python basic.py
2017-10-09 22:17:11,752 - ydk - INFO - Path where models are to be downloaded: /home/cisco/.ydk/172.16.20.1:2223
2017-10-09 22:17:11,758 - ydk - INFO - Connected to 172.16.20.1 on port 2223 using ssh with timeout of -1
2017-10-09 22:17:11,758 - ydk - INFO - Connected to 172.16.20.1 on port 2223 using ssh with timeout of -1
2017-10-09 22:17:11,758 - ydk - INFO - Executing CRUD update operation
2017-10-09 22:17:11,868 - ydk - ERROR - Libyang ERROR: Schema node not found. Path: 'address'
2017-10-09 22:17:11,869 - ydk - ERROR - Libyang ERROR: Schema node not found. Path: 'primary'
2017-10-09 22:17:11,905 - ydk - INFO - =============Generating payload to send to device=============
2017-10-09 22:17:11,906 - ydk - INFO - <rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"><edit-config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<target>
<running/>
</target>
<error-option>rollback-on-error</error-option>
<config><native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" nc:operation="merge">
<interface>
<GigabitEthernet>
<name>4</name>
<ip>
<address>
<primary nc:operation="remove"/>
</address>
</ip>
</GigabitEthernet>
</interface>
</native>
</config>
</edit-config>
</rpc>
2017-10-09 22:17:11,906 - ydk - INFO -
2017-10-09 22:17:11,914 - ydk - INFO - =============Reply payload received from device=============
2017-10-09 22:17:11,915 - ydk - INFO - <?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="1">
<ok/>
</rpc-reply>
2017-10-09 22:17:11,915 - ydk - INFO -
2017-10-09 22:17:11,915 - ydk - INFO - Operation succeeded
2017-10-09 22:17:11,915 - ydk - INFO - Disconnected from device
2017-10-09 22:17:11,915 - ydk - INFO - Disconnected from device
Hope this helps!!
Cheers,
Einar
10-08-2017 12:30 PM
Simon,
What are you tying to delete? You can’t delete GigabitEthernet2, for example, and the error you see below is one which you would get if that’s what you’re trying to do.
Can you enable the YDK debuts that show what is getting sent to the device? And also post a copy of the code you are using?
Cheers,
Einar
10-08-2017 12:45 PM
Hi Einar,
The script is attached to the original post.
I do not want to delete GigabitEthernet 2, more the configuration assigned to it (ip address, description, mtu etc.)
Lastly, how do I enable YDK debuts?
Thanks
10-08-2017 01:06 PM
Ahh, made the mistake of not looking at the actual port!
See here for how to enable YDK debuts:
https://github.com/CiscoDevNet/ydk-py-samples/blob/master/samples/basic/crud/models/cisco-ios-xe/Cisco-IOS-XE-native/native/router/ospf/nc-create-xe-native-router-ospf-20-ydk.py#L69
Cheers,
Einar
10-08-2017 02:22 PM
Debug, not debuts
The debug for crud.create and crud.delete below. Can you advise how would I delete just ip address and mask?
2017-10-08 22:17:19,924 - ydk - INFO - Executing CRUD create operation
2017-10-08 22:17:20,032 - ydk - ERROR - Libyang ERROR: Schema node not found. Path: 'address'
2017-10-08 22:17:20,032 - ydk - ERROR - Libyang ERROR: Schema node not found. Path: 'primary'
2017-10-08 22:17:20,065 - ydk - INFO - =============Generating payload to send to device=============
2017-10-08 22:17:20,065 - ydk - INFO - <rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"><edit-config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<target>
<running/>
</target>
<error-option>rollback-on-error</error-option>
<config><native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" nc:operation="merge">
<interface>
<GigabitEthernet>
<name>2</name>
<description>CONNECTS TO R1 (gigabitethernet3)</description>
<load-interval>30</load-interval>
<mtu>9192</mtu>
<ip>
<address>
<primary>
<address>198.168.1.1</address>
<mask>255.255.255.0</mask>
</primary>
</address>
</ip>
</GigabitEthernet>
</interface>
</native>
</config>
</edit-config>
</rpc>
2017-10-08 22:17:20,065 - ydk - INFO -
2017-10-08 22:17:20,480 - ydk - INFO - =============Reply payload received from device=============
2017-10-08 22:17:20,481 - ydk - INFO - <?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="1">
<ok/>
</rpc-reply>
2017-10-08 22:17:20,481 - ydk - INFO -
2017-10-08 22:17:20,481 - ydk - INFO - Operation succeeded
2017-10-08 22:17:20,481 - ydk - INFO - Disconnected from device
2017-10-08 22:17:20,481 - ydk - INFO - Disconnected from device
And here is the debug for crud.delete
2017-10-08 22:20:19,042 - ydk - INFO - Executing CRUD delete operation
2017-10-08 22:20:19,151 - ydk - ERROR - Libyang ERROR: Schema node not found. Path: 'address'
2017-10-08 22:20:19,151 - ydk - ERROR - Libyang ERROR: Schema node not found. Path: 'primary'
2017-10-08 22:20:19,183 - ydk - INFO - =============Generating payload to send to device=============
2017-10-08 22:20:19,183 - ydk - INFO - <rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"><edit-config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<target>
<running/>
</target>
<error-option>rollback-on-error</error-option>
<config><native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" nc:operation="delete">
<interface>
<GigabitEthernet>
<name>2</name>
<description>CONNECTS TO R1 (gigabitethernet3)</description>
<load-interval>30</load-interval>
<mtu>9192</mtu>
<ip>
<address>
<primary>
<address>198.168.1.1</address>
<mask>255.255.255.0</mask>
</primary>
</address>
</ip>
</GigabitEthernet>
</interface>
</native>
</config>
</edit-config>
</rpc>
2017-10-08 22:20:19,183 - ydk - INFO -
2017-10-08 22:20:27,698 - ydk - INFO - =============Reply payload received from device=============
2017-10-08 22:20:27,698 - ydk - INFO - <?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="1">
<rpc-error>
<error-type>application</error-type>
<error-tag>invalid-value</error-tag>
<error-severity>error</error-severity>
<error-message xml:lang="en">inconsistent value: Device refused one or more commands</error-message>
<error-info>
<severity xmlns="http://cisco.com/yang/cisco-ia">error_cli</severity>
<detail xmlns="http://cisco.com/yang/cisco-ia">
<bad-cli>
<bad-command>no redundancy</bad-command>
<error-location>6</error-location>
</bad-cli>
</detail>
</error-info>
</rpc-error>
</rpc-reply>
2017-10-08 22:20:27,698 - ydk - INFO -
2017-10-08 22:20:27,698 - ydk - ERROR - No ok in reply received from device
Traceback (most recent call last):
File "/Users/sihart/PycharmProjects/ydk_6_0/acl_lists_loop.py", line 88, in <module>
crud.delete(provider, native)
File "/Users/sihart/mycode/ydk_py/venv/lib/python3.6/site-packages/ydk/errors/error_handler.py", line 112, in helper
return func(self, provider, entity, *args, **kwargs)
File "/Users/sihart/mycode/ydk_py/venv/lib/python3.6/site-packages/ydk/services/crud_service.py", line 50, in delete
return self._crud.delete(provider, entity)
File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/contextlib.py", line 99, in __exit__
self.gen.throw(type, value, traceback)
File "/Users/sihart/mycode/ydk_py/venv/lib/python3.6/site-packages/ydk/errors/error_handler.py", line 82, in handle_runtime_error
_raise(_exc)
File "/Users/sihart/mycode/ydk_py/venv/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.YPYServiceProviderError: <?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="1">
<rpc-error>
<error-type>application</error-type>
<error-tag>invalid-value</error-tag>
<error-severity>error</error-severity>
<error-message xml:lang="en">inconsistent value: Device refused one or more commands</error-message>
<error-info>
<severity xmlns="http://cisco.com/yang/cisco-ia">error_cli</severity>
<detail xmlns="http://cisco.com/yang/cisco-ia">
<bad-cli>
<bad-command>no redundancy</bad-command>
<error-location>6</error-location>
</bad-cli>
</detail>
</error-info>
</rpc-error>
</rpc-reply>
2017-10-08 22:20:28,061 - ydk - INFO - Disconnected from device
2017-10-08 22:20:28,061 - ydk - INFO - Disconnected from device
libc++abi.dylib: terminating with uncaught exception of type pybind11::error_already_set: NameError: name 'open' is not defined
At:
/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/logging/__init__.py(1059): _open
/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/logging/__init__.py(1069): emit
/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/logging/__init__.py(865): handle
/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/logging/__init__.py(1514): callHandlers
/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/logging/__init__.py(1452): handle
/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/logging/__init__.py(1442): _log
/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/logging/__init__.py(1306): info
10-09-2017 06:42 AM
To test this further I have tried deletion of a created access - LoACL. I am receiving a similar error when invoking and sending crud.delete, e.g. <bad-cli><bad-command>no redundancy</bad-command>
The script and logging posted below
from ydk.services import CRUDService
from ydk.providers import NetconfServiceProvider
from ydk.providers import CodecServiceProvider
from ydk.services.codec_service import CodecService
from ydk.models.cisco_ios_xe import Cisco_IOS_XE_native \
as xe_native
from ydk.types import Empty
import logging
provider = NetconfServiceProvider(address='',
port=830,
username='root',
password='',
protocol='ssh')
empty =Empty()
codec = CodecService()
crud = CRUDService()
codec_provider = CodecServiceProvider(type='xml')
def config_native(native):
standard = native.ip.access_list.Standard()
standard.name = 'LoACL'
native.ip.access_list.standard.append(standard)
logger = logging.getLogger("ydk")
logging.basicConfig(filename='access.log',level=logging.DEBUG)
logger.setLevel(logging.INFO)
handler = logging.StreamHandler()
formatter = logging.Formatter(("%(asctime)s - %(name)s - "
"%(levelname)s - %(message)s"))
handler.setFormatter(formatter)
logger.addHandler(handler)
native = xe_native.Native()# create object
config_native(native) # Call configuration function using object
crud.delete(provider, native)
Logging information below
2017-10-09 14:13:31,162 - ydk - INFO - Executing CRUD delete operation
<native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">
<ip>
<access-list>
<standard xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-acl">
<name>LoACL</name>
</standard>
</access-list>
</ip>
</native>
2017-10-09 14:13:31,386 - ydk - INFO - =============Generating payload to send to device=============
2017-10-09 14:13:31,386 - ydk - INFO - <rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"><edit-config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<target>
<running/>
</target>
<error-option>rollback-on-error</error-option>
<config><native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" nc:operation="delete">
<ip>
<access-list>
<standard xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-acl">
<name>LoACL</name>
</standard>
</access-list>
</ip>
</native>
</config>
</edit-config>
</rpc>
2017-10-09 14:13:31,386 - ydk - INFO -
2017-10-09 14:13:39,698 - ydk - INFO - =============Reply payload received from device=============
2017-10-09 14:13:39,698 - ydk - INFO - <?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="1">
<rpc-error>
<error-type>application</error-type>
<error-tag>invalid-value</error-tag>
<error-severity>error</error-severity>
<error-message xml:lang="en">inconsistent value: Device refused one or more commands</error-message>
<error-info>
<severity xmlns="http://cisco.com/yang/cisco-ia">error_cli</severity>
<detail xmlns="http://cisco.com/yang/cisco-ia">
<bad-cli>
<bad-command>no redundancy</bad-command>
<error-location>6</error-location>
</bad-cli>
</detail>
</error-info>
</rpc-error>
</rpc-reply>
2017-10-09 14:13:39,698 - ydk - INFO -
2017-10-09 14:13:39,698 - ydk - ERROR - No ok in reply received from device
Traceback (most recent call last):
File "/Users/sihart/PycharmProjects/ydk_6_0/acl_lists_loop.py", line 110, in <module>
crud.delete(provider, native)
File "/Users/sihart/mycode/ydk_py/venv/lib/python3.6/site-packages/ydk/errors/error_handler.py", line 112, in helper
return func(self, provider, entity, *args, **kwargs)
File "/Users/sihart/mycode/ydk_py/venv/lib/python3.6/site-packages/ydk/services/crud_service.py", line 50, in delete
return self._crud.delete(provider, entity)
File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/contextlib.py", line 99, in __exit__
self.gen.throw(type, value, traceback)
File "/Users/sihart/mycode/ydk_py/venv/lib/python3.6/site-packages/ydk/errors/error_handler.py", line 82, in handle_runtime_error
_raise(_exc)
File "/Users/sihart/mycode/ydk_py/venv/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.YPYServiceProviderError: <?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="1">
<rpc-error>
<error-type>application</error-type>
<error-tag>invalid-value</error-tag>
<error-severity>error</error-severity>
<error-message xml:lang="en">inconsistent value: Device refused one or more commands</error-message>
<error-info>
<severity xmlns="http://cisco.com/yang/cisco-ia">error_cli</severity>
<detail xmlns="http://cisco.com/yang/cisco-ia">
<bad-cli>
<bad-command>no redundancy</bad-command>
<error-location>6</error-location>
</bad-cli>
</detail>
</error-info>
</rpc-error>
</rpc-reply>
10-09-2017 02:22 PM
Simon,
Apologies for taking so long to get back to you. I've got a working sample for you to use as a template. The code below will delete the primary and secondary addresses off of an interface, and you should be able to adapt it to other scenarios fairly easily:
#! /usr/bin/env python3
__author__ = 'einarnn'
'''
Working with YDK 0.6.1, XE models against IOS-XE
'''
from ydk.services import CRUDService
from ydk.providers import NetconfServiceProvider
from ydk.filters import YFilter
from ydk.models.cisco_ios_xe import Cisco_IOS_XE_native as xe
import logging
if __name__=='__main__':
logger = logging.getLogger("ydk")
logger.setLevel(logging.INFO)
handler = logging.StreamHandler()
formatter = logging.Formatter(("%(asctime)s - %(name)s - "
"%(levelname)s - %(message)s"))
handler.setFormatter(formatter)
logger.addHandler(handler)
crud = CRUDService()
# set up the thing we want to delete
del_native = xe.Native()
del_intf = xe.Native.Interface.GigabitEthernet()
del_intf.name = "4"
del_intf.ip.address.primary.yfilter = YFilter.remove
del_native.interface.gigabitethernet.append(del_intf)
# connect to the device
provider = NetconfServiceProvider(address='172.16.20.1',
port=2223,
username='vagrant',
password='vagrant',
protocol='ssh')
crud.update(provider, del_native)
And here's a sample log from running the test now:
$ python basic.py
2017-10-09 22:17:11,752 - ydk - INFO - Path where models are to be downloaded: /home/cisco/.ydk/172.16.20.1:2223
2017-10-09 22:17:11,758 - ydk - INFO - Connected to 172.16.20.1 on port 2223 using ssh with timeout of -1
2017-10-09 22:17:11,758 - ydk - INFO - Connected to 172.16.20.1 on port 2223 using ssh with timeout of -1
2017-10-09 22:17:11,758 - ydk - INFO - Executing CRUD update operation
2017-10-09 22:17:11,868 - ydk - ERROR - Libyang ERROR: Schema node not found. Path: 'address'
2017-10-09 22:17:11,869 - ydk - ERROR - Libyang ERROR: Schema node not found. Path: 'primary'
2017-10-09 22:17:11,905 - ydk - INFO - =============Generating payload to send to device=============
2017-10-09 22:17:11,906 - ydk - INFO - <rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"><edit-config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<target>
<running/>
</target>
<error-option>rollback-on-error</error-option>
<config><native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" nc:operation="merge">
<interface>
<GigabitEthernet>
<name>4</name>
<ip>
<address>
<primary nc:operation="remove"/>
</address>
</ip>
</GigabitEthernet>
</interface>
</native>
</config>
</edit-config>
</rpc>
2017-10-09 22:17:11,906 - ydk - INFO -
2017-10-09 22:17:11,914 - ydk - INFO - =============Reply payload received from device=============
2017-10-09 22:17:11,915 - ydk - INFO - <?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="1">
<ok/>
</rpc-reply>
2017-10-09 22:17:11,915 - ydk - INFO -
2017-10-09 22:17:11,915 - ydk - INFO - Operation succeeded
2017-10-09 22:17:11,915 - ydk - INFO - Disconnected from device
2017-10-09 22:17:11,915 - ydk - INFO - Disconnected from device
Hope this helps!!
Cheers,
Einar
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