07-04-2019 06:11 AM - edited 07-04-2019 06:15 AM
Hello,
Is it possible to loop over a Python variable in a XML service template ?
For example in a Python I have imported a yaml file :
system:
dns:
truc.fr:
ip:
1.1.1.1
1.2.3.1
And in the template I want to loop over DNS ip
<configuration xmlns="http://xml.juniper.net/xnm/1.1/xnm">
<system tags="replace">
<domain-name>DNS HERE FROM YAML</domain-name>
<default-address-selection/>
<?foreach {DNS IP LIST HERE FROM YAML}?>
<name-server>
<name>DNS IP HERE FROM YAML</name>
</name-server>
<?end?>
</system>
</configuration>
Thanks
Solved! Go to Solution.
07-04-2019 07:51 AM
No it is not possible. You either need to do the loop in your python code and apply the template on each interation (this can be slow), or you need to create a YANG structure in the CDB that you can loop over in the template.
There's some good information about this in the Development Guide. Look at "Passing deep structures from an API" in the Templates section.
If your template is really simple (like just setting one leaf), you could do this in the python code instead and not use the template.
07-04-2019 07:51 AM
No it is not possible. You either need to do the loop in your python code and apply the template on each interation (this can be slow), or you need to create a YANG structure in the CDB that you can loop over in the template.
There's some good information about this in the Development Guide. Look at "Passing deep structures from an API" in the Templates section.
If your template is really simple (like just setting one leaf), you could do this in the python code instead and not use the template.
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