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

XML loop over YAML variables

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

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Cisco Employee

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.

View solution in original post

1 REPLY 1
Highlighted
Cisco Employee

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.

View solution in original post