cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
598
Views
20
Helpful
3
Replies

Using CRUDService to delete all elements in a list

vadigreg
Cisco Employee
Cisco Employee

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.

 
Any help is appreciated.
 
Thanks,
Val
3 Replies 3

yangorelik
Spotlight
Spotlight

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.

Yan Gorelik
YDK Solutions

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

So it seems this:

entries = Cisco_IOS_XE_wireless_wlan_cfg.WlanCfgData.WlanCfgEntries()
entries.yfilter = YFilter.delete
result = service.update(restconf_provider, entries)

works well only if provider is started with XML encoding. Using JSON encoding doesn't work on IOS-XE and Cat9k device.