06-22-2020 12:37 PM - edited 06-22-2020 12:41 PM
Hello,
I'm trying to delete all elements from a list. My YANG is like:
container wlan-cfg-data { container wlan-cfg-entries { list wlan-cfg-entry { key "profile-name";
So basically I want to remove all wlan-cfg-entry from wlan-cfg-entries. I've tried this:
entries = Cisco_IOS_XE_wireless_wlan_cfg.WlanCfgData.WlanCfgEntries() entries.yfilter = YFilter.delete service.delete(provider, entries)
But it doesn't work. It issues a DELETE (Restconf) on /data/Cisco-IOS-XE-wireless-wlan-cfg:wlan-cfg-data rather than /data/Cisco-IOS-XE-wireless-wlan-cfg:wlan-cfg-data/wlan-cfg-entries. I know that the latter path would work instead. I tried to follow the example here http://ydk.cisco.com/py/docs/guides/crud_guide.html#deleting-a-list but it doesn't seem to delete a list, it rather deletes an element from a list.
06-22-2020 03:20 PM
Hi Val
There are multiple errors in your script. Here is how you should do it:
# First you need to read existing configuration
cfg_data = Cisco_IOS_XE_wireless_wlan_cfg.WlanCfgData()
wlan_cfg = service.read_config(provider, cfg_data)
# Then delete all elements in the list in one operation
if len(wlan_cfg.wlan_cfg_entries.wlan_cfg_entry) > 0: wlan_cfg.wlan_cfg_entries.wlan_cfg_entry.yfilter = YFilter.delete
service.update(provider, wlan_cfg)
I suggest you to run your script with logging level INFO so you could clearly see RPCs sent and received.
06-23-2020 02:15 AM
Hi Yan,
thanks for your reply. This is actually failing for the same reason:
2020-06-23T11:11:38: %AETEST-ERROR: File "/nobackup/pyats/lib/python3.6/site-packages/ydk/errors/error_handler.py", line 112, in helper 2020-06-23T11:11:38: %AETEST-ERROR: return func(self, provider, entity, *args, **kwargs) 2020-06-23T11:11:38: %AETEST-ERROR: File "/nobackup/pyats/lib/python3.6/site-packages/ydk/services/crud_service.py", line 53, in delete 2020-06-23T11:11:38: %AETEST-ERROR: return _crud_update(provider, entity, self._crud.delete) 2020-06-23T11:11:38: %AETEST-ERROR: File "/nobackup/pyats/lib/python3.6/site-packages/ydk/services/crud_service.py", line 70, in _crud_update 2020-06-23T11:11:38: %AETEST-ERROR: return crud_call(provider, entity) 2020-06-23T11:11:38: %AETEST-ERROR: File "/auto/pysw/cel8x/python64/3.6.10/lib/python3.6/contextlib.py", line 99, in __exit__ 2020-06-23T11:11:38: %AETEST-ERROR: self.gen.throw(type, value, traceback) 2020-06-23T11:11:38: %AETEST-ERROR: File "/nobackup/pyats/lib/python3.6/site-packages/ydk/errors/error_handler.py", line 82, in handle_runtime_error 2020-06-23T11:11:38: %AETEST-ERROR: _raise(_exc) 2020-06-23T11:11:38: %AETEST-ERROR: File "/nobackup/pyats/lib/python3.6/site-packages/ydk/errors/error_handler.py", line 54, in _raise 2020-06-23T11:11:38: %AETEST-ERROR: exec("raise exc from None") 2020-06-23T11:11:38: %AETEST-ERROR: File "<string>", line 1, in <module> 2020-06-23T11:11:38: %AETEST-ERROR: ydk.errors.YError: invalid format string
What I want to do is to exercise the following API:
DELETE /data/Cisco-IOS-XE-wireless-wlan-cfg:wlan-cfg-data/wlan-cfg-entries
However what I can see from logs is:
2020-06-23T11:14:19: %YDK-INFO: Executing CRUD update operation on [Cisco-IOS-XE-wireless-wlan-cfg:wlan-cfg-data] 2020-06-23T11:14:19: %YDK-INFO: Performing PATCH on URL /data/Cisco-IOS-XE-wireless-wlan-cfg:wlan-cfg-data. Payload: 2020-06-23T11:14:19: %YDK-INFO: { 2020-06-23T11:14:19: %YDK-INFO: "Cisco-IOS-XE-wireless-wlan-cfg:wlan-cfg-data": { 2020-06-23T11:14:19: %YDK-INFO: "wlan-cfg-entries": { 2020-06-23T11:14:19: %YDK-INFO: "wlan-cfg-entry": [ 2020-06-23T11:14:19: %YDK-INFO: { 2020-06-23T11:14:19: %YDK-INFO: "@": { 2020-06-23T11:14:19: %YDK-INFO: "ietf-netconf:operation":"delete" 2020-06-23T11:14:19: %YDK-INFO: }, 2020-06-23T11:14:19: %YDK-INFO: "profile-name": "new_wlan", [...]
And PATCH is not exactly what I want.
Regards,
Val
06-23-2020 05:24 AM
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