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

XML loop over YAML variables

romain.guilloux
Level 1
Level 1

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

Michael Maddern
Cisco Employee
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

Michael Maddern
Cisco Employee
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.

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 NSO Developer community: