08-28-2020 05:41 AM
Hi Sir,
Below code is from Cisco DevNet PPT presentation. I copy/paste to my VScode and run it.
But it has some issues. I am not clear what's the matter. Could you please kindly give me some support?
Much much appreciate!
from ydk.services import CRUDService
from ydk.providers import NetconfServiceProvider
from ydk.models.cisco_ios_xe import Cisco_IOS_XE_native as xe_native
if __name__ == "__main__":
"""Main execution path"""
# create NETCONF session
provider = NetconfServiceProvider(address="ios-xe-mgmt-latest.cisco.com",
port=10000,
username="developer",
password="C1sco12345",
protocol="ssh")
# create CRUD service
crud = CRUDService()
# create system time object
native = xe_native.Native()
native.hostname = "access_switch"
# read system time from device
crud.create(provider, native)
provider.close()
Solved! Go to Solution.
08-31-2020 10:24 AM
Hi Jacky
Here are my answers to your questions.
1. In order to operate on certain set of YANG models the YDK must specify location of the model repository (directory where YANG files are located). In case of Netconf service provider, the protocol allows to download models from device. This capability is used by YDK to create repository in runtime. The temporary repository location is $HOME/.ydk/your-device-name-ip. Other protocols like Restconf or gNMI do not have capability to download models, therefore the repository location is must be present parameter in corresponding service provider initialization. When YDK loads modules it looks for needed one in the repository and, if it is not present, attempts download it from device. That gives user unique opportunity manually change files in the repository, which I suggested you as a workaround for your original issue.
2. How to see the YDK version. If you use for installation precompiled core package, the deployment file name reflects full version notation: libydk-major.minor.patch-build.rpm. If you generate core package from source, look at the content of
file sdk/version. e.x:
ygorelik$ cat sdk/version.json
{
"core": "0.8.5",
"version": "0.8.5",
"ietf": "0.1.5-post2",
"openconfig": "0.1.8",
"cisco_ios_xr": "6.6.2",
"cisco_ios_xe": "16.9.3",
"cisco_nx_os": "9.3.1"
}
And the last one is for Python installation:
ygorelik$ pip list | grep ydk
ydk 0.8.5
ydk-models-cisco-ios-xe 16.9.3.post1
ydk-models-cisco-ios-xr 6.6.3
ydk-models-ietf 0.1.5.post2
ydk-models-openconfig 0.1.8
ydk-models-ydktest 0.1.0
ydk-models-ydktest-oc-nis 0.1.0
ydk-service-gnmi 0.4.0.post5
3. How to generate model package/bundle. Yes, you need clone ydk-gen from GitHub in order to generate packages. The whole process is documented here. As an example for package profile you can use this file ./ydk-gen/profiles/bundles/cisco-ios-xe_16_9_3.json. Note that for your specific application the package not necessarily should include all the modules, like in the example above. You can use any complete set of modules, for example the ones located in your temporary repository. The "complete" means that the command 'pyang *' issued in the repository directory does not give you error messages.
08-28-2020 10:19 AM
Hi Jacky
If you were enabled logging, you would see the real error message:
2020-08-28 09:39:56,544 - ydk - INFO - Executing 'get' RPC on [Cisco-IOS-XE-native:native] from running
2020-08-28 09:40:41,910 - ydk - ERROR - Data is invalid according to the yang model. Libyang error: Invalid keyword "changing ingress-replication from container back to leaf to take care of\
backward compatibility "".
2020-08-28 09:40:41,910 - ydk - ERROR - Data is invalid according to the yang model. Libyang error: Submodule "Cisco-IOS-XE-interfaces" parsing failed.
2020-08-28 09:40:41,911 - ydk - ERROR - Data is invalid according to the yang model. Libyang error: Including "Cisco-IOS-XE-interfaces" module into "Cisco-IOS-XE-native" failed.
2020-08-28 09:40:41,911 - ydk - ERROR - Data is invalid according to the yang model. Libyang error: Module "Cisco-IOS-XE-native" parsing failed.
The error appeared due to syntax error in the submodule Cisco-IOS-XE-interfaces.yang, which use character "\" in the description node (the libyang did not like it).
revision 2019-01-27 {
description
"changing ingress-replication from container back to leaf to take care of\
backward compatibility ";
}
When I removed the character by modifying corresponding file in the temporary repository $HOME/.ydk/ios-xe-mgmt-latest.cisco.com, the script was executed with no issue. By the way, the device ios-xe-mgmt-latest.cisco.com is running IOS XE version 16.11.01a. The models on that device are different from version 16.9.3 and might have conflicts with your cisco-ios-xe package. To be confident, you should generate your own package for new device version, or use Path API.
08-30-2020 09:56 PM
Hi Yan,
Much appreciate for your help.
The issue was fixed by your solution. It is my first successful YDK program.:)
Thank you again!
There is a lot of important/valuable information in your mail. Could you please kindly review it if I got your point or if you could give me some advice. Thanks a lot.
1 When I follow your mail's guidance to access below folder.($HOME/.ydk/ios-xe-mgmt-latest.cisco.com) I was surprised that there are some yang files in this folder. Can you let me know why there are so many yang files. Does it mean these yang files were downloaded from CSR1000v router ? When I install YDK, Yang files are installed in /user/local/lib/python2.7/dist-packages/ydk/models/cisco_ios_xe/_yang/ folder. I check "Cisco-IOS-XE-interfaces.py" in /user/local/lib/python2.7/dist-packages/ydk/models/cisco_ios_xe/_yang/folder. I haven't seen any issue syntax "\". So I guess there is conflict between YDK yang file and CSRv1000 yang file.
root@YDK64:/home/jzhang/.ydk/ios-xe-mgmt-latest.cisco.com# ll
total 820
drwx------ 2 jzhang jzhang 4096 8月 31 12:12 ./
drwx------ 3 jzhang jzhang 4096 8月 28 09:39 ../
-rw-rw-r-- 1 jzhang jzhang 11845 8月 28 21:30 Cisco-IOS-XE-cdp-oper.yang
-rw-rw-r-- 1 jzhang jzhang 4417 8月 28 16:17 Cisco-IOS-XE-features.yang
-rw-rw-r-- 1 jzhang jzhang 7407 8月 28 16:17 Cisco-IOS-XE-interface-common.yang
-rw-rw-r-- 1 jzhang jzhang 88739 8月 28 16:18 Cisco-IOS-XE-interfaces@2019-02-11.yang
-rw-r--r-- 1 root root 88739 8月 31 12:12 Cisco-IOS-XE-interfaces@2019-02-11.yang.bak
2 The models on that device are different from version 16.9.3 and might have conflicts with your cisco-ios-xe package
So conflict is in yang files between folder /home/jzhang/.ydk/ios-xe-mgmt-latest.cisco.com and /user/local/lib/python2.7/dist-packages/ydk/models/cisco_ios_xe/_yang/
I could get CSR1000v version by "show version". Can you give me some advice how I could know software version of
YDK package ??
3 you should generate your own package for new device version
May I know if I got your point ? May I know if I could use YDK-Gen to generate Yang package for IOS XE version 16.11.01a ??
Thanks a lot
Jacky
which is the same IOS version with CSR1000v ???
08-31-2020 10:24 AM
Hi Jacky
Here are my answers to your questions.
1. In order to operate on certain set of YANG models the YDK must specify location of the model repository (directory where YANG files are located). In case of Netconf service provider, the protocol allows to download models from device. This capability is used by YDK to create repository in runtime. The temporary repository location is $HOME/.ydk/your-device-name-ip. Other protocols like Restconf or gNMI do not have capability to download models, therefore the repository location is must be present parameter in corresponding service provider initialization. When YDK loads modules it looks for needed one in the repository and, if it is not present, attempts download it from device. That gives user unique opportunity manually change files in the repository, which I suggested you as a workaround for your original issue.
2. How to see the YDK version. If you use for installation precompiled core package, the deployment file name reflects full version notation: libydk-major.minor.patch-build.rpm. If you generate core package from source, look at the content of
file sdk/version. e.x:
ygorelik$ cat sdk/version.json
{
"core": "0.8.5",
"version": "0.8.5",
"ietf": "0.1.5-post2",
"openconfig": "0.1.8",
"cisco_ios_xr": "6.6.2",
"cisco_ios_xe": "16.9.3",
"cisco_nx_os": "9.3.1"
}
And the last one is for Python installation:
ygorelik$ pip list | grep ydk
ydk 0.8.5
ydk-models-cisco-ios-xe 16.9.3.post1
ydk-models-cisco-ios-xr 6.6.3
ydk-models-ietf 0.1.5.post2
ydk-models-openconfig 0.1.8
ydk-models-ydktest 0.1.0
ydk-models-ydktest-oc-nis 0.1.0
ydk-service-gnmi 0.4.0.post5
3. How to generate model package/bundle. Yes, you need clone ydk-gen from GitHub in order to generate packages. The whole process is documented here. As an example for package profile you can use this file ./ydk-gen/profiles/bundles/cisco-ios-xe_16_9_3.json. Note that for your specific application the package not necessarily should include all the modules, like in the example above. You can use any complete set of modules, for example the ones located in your temporary repository. The "complete" means that the command 'pyang *' issued in the repository directory does not give you error messages.
08-31-2020 09:24 PM
Hi Yan,
1 In case of Netconf service provider, the protocol allows to download models from device. This capability is used by YDK to create repository in runtime. location is $HOME/.ydk/your-device-name-ip. When YDK loads modules it looks for needed one in the repository and, if it is not present, attempts download it from device. That gives user unique opportunity manually change files in the repository, which I suggested you as a workaround for your original issue.'------------I understood now. Thanks a lot
When I followed the guide to install YDK, I also installed ydk-models-cisco-ios-xr(6.6.3) and ydk-models-cisco-ios-xe(16.9.3) from PYPI.org. And in /home/jzhang/.ydk/ios-xe-mgmt-latest.cisco.com which are from my device and version is 16.11.01a. So what's the relationship between them. From your statement, YDK loads modules from Devices. and you also mentioned conflict Yes, It looks
like there is one conflict between 16.11.01a (from real device) and 16.9.3 (from PYPI.org). I am sorry that I still not very clear about the logic background. So YDK will loads modules from $HOME/.ydk/your-device-name-ip first and compared with ydk-models-cisco-ios-xe ??????
Can you let me know a bit more about conflict logic background ? Thanks a lot.
pip install ydk-models-cisco-ios-xr
pip install ydk-models-cisco-ios-xe
08-31-2020 09:28 PM
Thanks a lot Yan for your reply for 2nd question.
I will try it later when I can access my DevNet computer.
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