cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
218
Views
0
Helpful
2
Replies

How can use forloop in nso rfs template?

alessiagreco
Level 1
Level 1

 Example1 : Supposed your input payload is given below  { "l3-device-list" :{ "interface-list":{ "s-existing-trunk-vlan":[444, 454,222], } } }  Step1: Add variable in java inputParams.putQuotedEmptyIfNull( "s-existing-trunk-vlan", interfaceObj.leaf(l3VpnRfs._s_existing_trunk_vlan_).valueAsString() );  Step2: Add variable in  yang leaf-list s-existing-trunk-vlan { type uint32 { range "1..4096"; } } #3: Add loop in config template <dot1q> <?foreach {l3-device-list/interface-list/s-existing-trunk-vlan}?> <id>{.}</id> <?end?> <id>{$vlan-id}</id> </dot1q>  Example2 : Supposed your input payload is given below { "alc-last-mile-ag2-rfs": { "interface-name1":["0/0/1/7", "0/0/1/8", "0/0/1/9"], } }  Step1: Add variable in  yang leaf-list interface-name1 { type string; }  Step2:  Add loop in config template  <?foreach{interface-name1}?> <TenGigE> <id>{.}</id> <load-interval>30</load-interval> <bundle> <id> <id-value>{$B-ID}</id-value> <mode>active</mode> </id> </bundle> </TenGigE> <?end?> 

2 Replies 2

Example one, use <?loop?> as it is easier to read, then you can remove the <id>{$vlan-id}</id element, as it's not part of the loop.

<dot1q>
  <?loop var="vlan" in="l3-device-list/interface-list/s-existing-trunk-vlan"?>
  <id>${vlan}</id>
  <?end?>
</dot1q>

 Example two, same for the update of <?foreach?>, and then in both example the code becomes more readable, maintainable, and efficient.

<?loop var="interface" in="interface-name1"?>
<TenGigE>
  <id>${interface}</id>
  <load-interval>30</load-interval>
  <bundle>
    <id>
      <id-value>${B-ID}</id-value>
      <mode>active</mode>
    </id>
  </bundle>
</TenGigE>
<?end?>

 

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

Ruben Cocheno
Spotlight
Spotlight

@alessiagreco 

Can you provide more details?

Tag me to follow up.
Please mark it as Helpful and/or Solution Accepted if that is the case. Thanks for making Engineering easy again.
Connect with me for more on Linkedin https://www.linkedin.com/in/rubencocheno/