07-27-2020 01:56 AM
When I use RestconfServiceProvider passing as repo:
repo = Repo()
I get this error:
2020-07-27T10:51:20: %YDK-INFO: Ready to communicate with http://10.51.65.19:80/restconf using http 2020-07-27T10:51:20: %YDK-INFO: Path where models are to be downloaded: /users/vadigreg/.ydk 2020-07-27T10:51:20: %YDK-ERROR: Data is invalid according to the yang model. Libyang error: Data model "ydk" not found. 2020-07-27T10:51:20: %YDK-ERROR: Data is invalid according to the yang model. Libyang error: Data model "ietf-netconf" not found. 2020-07-27T10:51:25: %YDK-ERROR: Data is invalid according to the yang model. Libyang error: Data model "ydk" not found. 2020-07-27T10:51:25: %YDK-ERROR: Data is invalid according to the yang model. Libyang error: Module not found. Path: '/ydk' 2020-07-27T10:51:25: %AETEST-ERROR: Caught an exception while executing section wlan_sample: 2020-07-27T10:51:25: %AETEST-ERROR: Traceback (most recent call last): [...] 2020-07-27T10:51:25: %AETEST-ERROR: File "/nobackup/vadigreg/pyats/lib/python3.6/site-packages/ydk/errors/error_handler.py", line 112, in helper 2020-07-27T10:51:25: %AETEST-ERROR: return func(self, provider, entity, *args, **kwargs) 2020-07-27T10:51:25: %AETEST-ERROR: File "/nobackup/vadigreg/pyats/lib/python3.6/site-packages/ydk/services/crud_service.py", line 57, in update 2020-07-27T10:51:25: %AETEST-ERROR: return _crud_update(provider, entity, self._crud.update) 2020-07-27T10:51:25: %AETEST-ERROR: File "/nobackup/vadigreg/pyats/lib/python3.6/site-packages/ydk/services/crud_service.py", line 70, in _crud_update 2020-07-27T10:51:25: %AETEST-ERROR: return crud_call(provider, entity) 2020-07-27T10:51:25: %AETEST-ERROR: File "/auto/pysw/cel8x/python64/3.6.10/lib/python3.6/contextlib.py", line 99, in __exit__ 2020-07-27T10:51:25: %AETEST-ERROR: self.gen.throw(type, value, traceback) 2020-07-27T10:51:25: %AETEST-ERROR: File "/nobackup/vadigreg/pyats/lib/python3.6/site-packages/ydk/errors/error_handler.py", line 82, in handle_runtime_error 2020-07-27T10:51:25: %AETEST-ERROR: _raise(_exc) 2020-07-27T10:51:25: %AETEST-ERROR: File "/nobackup/vadigreg/pyats/lib/python3.6/site-packages/ydk/errors/error_handler.py", line 54, in _raise 2020-07-27T10:51:25: %AETEST-ERROR: exec("raise exc from None") 2020-07-27T10:51:25: %AETEST-ERROR: File "<string>", line 1, in <module> 2020-07-27T10:51:25: %AETEST-ERROR: ydk.errors.YInvalidArgumentError: Path is invalid: ydk:update
This doesn't happen when I use NetconfServiceProvider. Also if I run NetconfServiceProvider first, this downloads all models in my ~/.ydk. Then if I use RestconfServiceProvider everything is working just fine.
I have 2 questions:
1. Can I force RestconfServiceProvider to download models like NetconfServiceProvider does?
2. Even in successful runs I get a lot of errors like "Data is invalid according to the yang model. Libyang error: Data model "whatever" not found.". Any clue?
Thanks,
Val
Solved! Go to Solution.
07-28-2020 11:15 AM
YANG models are needed in YDK to build schema and data models internally (implemented in Libyang). These are used to verify specified data and perform serialization/deserialization to/from XML or JSON encoded strings - payload, which are then used to build and decode RPCs. If YANG models are not specified when building repository, the YDK internally, as a convenience feature, downloads them from device to temporary location under $HOME/.ydk/. This convenience feature works only with Netconf services as these operations defined in IETF standard. The Restconf or gNMI services do not have this capability and therefore the user working with these services must provide the YANG model repository. When you generate a bundle, the original YANG models are always included in _yang directory; the last ultimately can be used as a repository. Here is simple example:
from ydk.path import Repository
import ydk.models.cisco_ios_xe as xe
repo = Repository(xe.__path__[0]+'/_yang')
root_schema = repo.create_root_schema([])
I understand that generation of API for each YANG model version looks somewhat inconvenient for the end user. If that is the case, the YDK offers unique capability to get around that challenge. It is called Path API method, which allows to build internal data models using YANG data node paths (XPath). Obviously, for each YANG model version the user must provide different repository. But a convenience is always comes at a cost. With this method instead of dealing with programming language objects, the user is forced to work with raw data - Datanode objects. The user also needs take care of data node serialization/deserialization, building and processing RPCs. The documentation has lots of examples on how the Path API can be used for certain tasks and I encourage you to try it for your application.
Also, I know there are some efforts inside Cisco to make Path API approach more simple to use. The approach instead of data node paths operates with XML or JSON encoded strings, which obviously needs knowledge of YANG model. In my opinion, this approach is good for single requests to get data from server, but it is not usable for big scale applications like automated test or network management systems.
07-27-2020 09:48 AM
Hi Val
1. This is expected behavior, because the Restconf protocol does not have means to retrieve YANG models from server like Netconf does. That is why it is necessary during Repository initialization specify location of YANG model repository (directory), which has complete set of models needed for your application.
repo = Repository("/path/to/YANG/model/repository")
2. Sometimes this error can be ignored, usually this is a case when YDK can get around the issue. And sometimes the YDK cannot find a model, which is needed to build schema or data tree; in this case the YDK develops YModelError exception.
07-27-2020 10:11 AM
Thanks Yan, is there a way to download the models like NetconfServiceProvider does? I mean even with another protocol. Should I instantiate a NetconfServiceProvider just for that purpose? Is there a proper way?
Thanks.
07-28-2020 02:50 AM
Also I don't understand why the need of downloading models. I autogenerated python from a specific version of YANG files. I'm targeting that version and any other will potentially bring to failures. My YDK python bundle should include the original definitions so that I can rely on those. Having to download them from the box, looks to me a non sense.
07-28-2020 11:15 AM
YANG models are needed in YDK to build schema and data models internally (implemented in Libyang). These are used to verify specified data and perform serialization/deserialization to/from XML or JSON encoded strings - payload, which are then used to build and decode RPCs. If YANG models are not specified when building repository, the YDK internally, as a convenience feature, downloads them from device to temporary location under $HOME/.ydk/. This convenience feature works only with Netconf services as these operations defined in IETF standard. The Restconf or gNMI services do not have this capability and therefore the user working with these services must provide the YANG model repository. When you generate a bundle, the original YANG models are always included in _yang directory; the last ultimately can be used as a repository. Here is simple example:
from ydk.path import Repository
import ydk.models.cisco_ios_xe as xe
repo = Repository(xe.__path__[0]+'/_yang')
root_schema = repo.create_root_schema([])
I understand that generation of API for each YANG model version looks somewhat inconvenient for the end user. If that is the case, the YDK offers unique capability to get around that challenge. It is called Path API method, which allows to build internal data models using YANG data node paths (XPath). Obviously, for each YANG model version the user must provide different repository. But a convenience is always comes at a cost. With this method instead of dealing with programming language objects, the user is forced to work with raw data - Datanode objects. The user also needs take care of data node serialization/deserialization, building and processing RPCs. The documentation has lots of examples on how the Path API can be used for certain tasks and I encourage you to try it for your application.
Also, I know there are some efforts inside Cisco to make Path API approach more simple to use. The approach instead of data node paths operates with XML or JSON encoded strings, which obviously needs knowledge of YANG model. In my opinion, this approach is good for single requests to get data from server, but it is not usable for big scale applications like automated test or network management systems.
07-28-2020 02:04 PM
Thanks a lot for the explanation. This helped a lot to solve my issue.
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