User Tools

Site Tools


guides:user:scenarios:scn_cond_loop
LDAP: couldn't connect to LDAP server

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

guides:user:scenarios:scn_cond_loop [2019/12/24 08:33] – created bdorlandtguides:user:scenarios:scn_cond_loop [2022/04/29 08:20] (current) pgels
Line 1: Line 1:
 +===== Scenario with conditionals and a loop =====
 +
 +<code>
 +# Comments that follow after a hash will be ignored
 +[parameters] 
 +# Assign a static value
 +ring_node = rng00cs01
 +version = "ipvpn 1.1"
 +
 +[scenario]
 +# assign a value, which could be changed later on
 +<cpe> := switch1
 +# create a list
 +<pe_nodes> := <hostname@local_pe_nodes>
 +<pe_nodes> += <cpe>
 +# create a list of nodes from a relation
 +<ring_nodes> += <hostname@local_ring_nodes>
 +
 +
 +Description <cpe> test scenario
 +
 +config_create -n <cpe> -t ring_interface -f <ring_node>.cfg
 +if <error>
 +  log -m "failed to create cpe <cpe> config"
 +  <fail> += <cpe>
 +else
 +  <done> += <cpe>
 +endif
 +
 +# foreach loop
 +log -m "creating config pe-nodes"
 +foreach <pe_node> in <pe_nodes>
 +    log -m "pe-node: <pe-node>"
 +    if "<pe_node> == <cpe>"
 +        log -m "skipping cpe <cpe> node as pe-node"
 +        next
 +    endif
 +    
 +    # or: if ! <pe_node>
 +    if "<pe_node> == ''"
 +        log -m "aborting on blank pe-node"
 +        last
 +    endif
 +    
 +    config_create -n <cpe> -t pe_template -f <pe_node>.cfg
 +    if <error>
 +        log -m "failed to gen cfg for pe-node <pe_node>"
 +        <fail> += <pe_node>
 +    else
 +        <done> += <pe_node>
 +    endif
 +    
 +    foreach <tmp> in <done>
 +      log -m "node <tmp> is on done list"
 +    endeach
 +    log -m "starting next loop"
 +endeach
 +
 +log -m "generated configs for: <done>"
 +
 +if <fail>
 +    log -m "failed configs for: <fail>"
 +    stop
 +endif
 +</code>