<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to use multiple models with ydk.services.CodecService in Tools</title>
    <link>https://community.cisco.com/t5/tools/how-to-use-multiple-models-with-ydk-services-codecservice/m-p/4597113#M1054</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;Apologies for what could be a trivial question; I looked at some examples and in the discussion forum without finding a clear answer.&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;from&lt;/SPAN&gt; &lt;SPAN class=""&gt;ydk.models.cisco_ios_xr&lt;/SPAN&gt; &lt;SPAN class=""&gt;import&lt;/SPAN&gt; &lt;SPAN class=""&gt;Cisco_IOS_XR_ifmgr_cfg&lt;/SPAN&gt; &lt;SPAN class=""&gt;as&lt;/SPAN&gt; &lt;SPAN class=""&gt;ifmgr&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;as described in the Example of JsonSubtreeCodec usage however I am unclear what is the logic behind using a specific model when running the &lt;EM&gt;class &lt;/EM&gt;ydk.services.CodecService encode and decode from XML to JSON and vice-versa.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;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&lt;/PRE&gt;&lt;P&gt;Any code example would be greatly appreciated and apologies if the question has been addressed somewhere already.&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;P&gt;Luca&lt;/P&gt;</description>
    <pubDate>Fri, 22 Apr 2022 02:34:18 GMT</pubDate>
    <dc:creator>ldacol</dc:creator>
    <dc:date>2022-04-22T02:34:18Z</dc:date>
    <item>
      <title>How to use multiple models with ydk.services.CodecService</title>
      <link>https://community.cisco.com/t5/tools/how-to-use-multiple-models-with-ydk-services-codecservice/m-p/4597113#M1054</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;Apologies for what could be a trivial question; I looked at some examples and in the discussion forum without finding a clear answer.&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;from&lt;/SPAN&gt; &lt;SPAN class=""&gt;ydk.models.cisco_ios_xr&lt;/SPAN&gt; &lt;SPAN class=""&gt;import&lt;/SPAN&gt; &lt;SPAN class=""&gt;Cisco_IOS_XR_ifmgr_cfg&lt;/SPAN&gt; &lt;SPAN class=""&gt;as&lt;/SPAN&gt; &lt;SPAN class=""&gt;ifmgr&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;as described in the Example of JsonSubtreeCodec usage however I am unclear what is the logic behind using a specific model when running the &lt;EM&gt;class &lt;/EM&gt;ydk.services.CodecService encode and decode from XML to JSON and vice-versa.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;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&lt;/PRE&gt;&lt;P&gt;Any code example would be greatly appreciated and apologies if the question has been addressed somewhere already.&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;P&gt;Luca&lt;/P&gt;</description>
      <pubDate>Fri, 22 Apr 2022 02:34:18 GMT</pubDate>
      <guid>https://community.cisco.com/t5/tools/how-to-use-multiple-models-with-ydk-services-codecservice/m-p/4597113#M1054</guid>
      <dc:creator>ldacol</dc:creator>
      <dc:date>2022-04-22T02:34:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to use multiple models with ydk.services.CodecService</title>
      <link>https://community.cisco.com/t5/tools/how-to-use-multiple-models-with-ydk-services-codecservice/m-p/4598132#M1055</link>
      <description>&lt;P&gt;Hi Luca&lt;/P&gt;&lt;P&gt;In order to work with CodecService with multiple model versions you have to create one instance of CodecProvider for each model version and initialize &lt;STRONG&gt;explicitly&lt;/STRONG&gt; root schema for each instance. For example:&lt;/P&gt;&lt;PRE&gt;from ydk.services import CodecService&lt;BR /&gt;from ydk.providers import CodecProvider&lt;BR /&gt;import ydk.models.junos_18_4_R3 as j18&lt;BR /&gt;import ydk.models.junos_20_4_R1 as j20&lt;BR /&gt;import ydk.models.junos_21_1_R1 as j21&lt;BR /&gt;&lt;BR /&gt;provider18 = CodecProvider(type=json)&lt;BR /&gt;provider20 = CodecProvider(type=json)&lt;BR /&gt;provider21 = CodecProvider(type=json)&lt;BR /&gt;codec = CodecService()&lt;BR /&gt;&lt;BR /&gt;provider18.initialize('junos-18',&lt;BR /&gt;    '&lt;SPAN&gt;/Users/Luca/venv3.7/lib/python3.7/site-packages/ydk/models/junos_18_4_R3/_yang&lt;/SPAN&gt;')&lt;BR /&gt;provider20.initialize('junos-20',&lt;BR /&gt;    '&lt;SPAN&gt;/Users/Luca/venv3.7/lib/python3.7/site-packages/ydk/models/junos_20_4_R1/_yang&lt;/SPAN&gt;')&lt;BR /&gt;provider21.initialize('junos-21',&lt;BR /&gt;    '&lt;SPAN&gt;/Users/Luca/venv3.7/lib/python3.7/site-packages/ydk/models/junos_21_4_R1/_yang&lt;/SPAN&gt;')&lt;/PRE&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Yan&lt;/P&gt;</description>
      <pubDate>Fri, 22 Apr 2022 21:49:54 GMT</pubDate>
      <guid>https://community.cisco.com/t5/tools/how-to-use-multiple-models-with-ydk-services-codecservice/m-p/4598132#M1055</guid>
      <dc:creator>ygorelik</dc:creator>
      <dc:date>2022-04-22T21:49:54Z</dc:date>
    </item>
  </channel>
</rss>

