cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
356
Views
5
Helpful
1
Replies

How to use multiple models with ydk.services.CodecService

ldacol
Level 1
Level 1

Hello,

Apologies for what could be a trivial question; I looked at some examples and in the discussion forum without finding a clear answer.

I have multiple bundles generated and specific to a release version. The idea is to use bundles accordingly to the specific version of the code I am running on a device I need to program. I know this can be done by specifying the model ie.

from ydk.models.cisco_ios_xr import Cisco_IOS_XR_ifmgr_cfg as ifmgr

as described in the Example of JsonSubtreeCodec usage however I am unclear what is the logic behind using a specific model when running the class ydk.services.CodecService encode and decode from XML to JSON and vice-versa.

 

The idea is to be able to select any of those models when calling the encode and decode functions based on the version running on a device.

 

pip freeze | grep ydk
ydk==0.8.6.3
ydk-models-junos-18-4-R3==18.4.post3
ydk-models-junos-20-4-R1==20.4.post1
ydk-models-junos-21-1-R1==21.1.post1

Any code example would be greatly appreciated and apologies if the question has been addressed somewhere already.

Thank you

Luca

1 Reply 1

ygorelik
Cisco Employee
Cisco Employee

Hi Luca

In order to work with CodecService with multiple model versions you have to create one instance of CodecProvider for each model version and initialize explicitly root schema for each instance. For example:

from ydk.services import CodecService
from ydk.providers import CodecProvider
import ydk.models.junos_18_4_R3 as j18
import ydk.models.junos_20_4_R1 as j20
import ydk.models.junos_21_1_R1 as j21

provider18 = CodecProvider(type=json)
provider20 = CodecProvider(type=json)
provider21 = CodecProvider(type=json)
codec = CodecService()

provider18.initialize('junos-18',
'/Users/Luca/venv3.7/lib/python3.7/site-packages/ydk/models/junos_18_4_R3/_yang')
provider20.initialize('junos-20',
'/Users/Luca/venv3.7/lib/python3.7/site-packages/ydk/models/junos_20_4_R1/_yang')
provider21.initialize('junos-21',
'/Users/Luca/venv3.7/lib/python3.7/site-packages/ydk/models/junos_21_4_R1/_yang')

Needless to add that model objects must be created for according model packages. The intermix of entities and model packages can cause the YDK to crash.

Regards,

Yan

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: