08-21-2017 07:08 AM - edited 03-01-2019 03:58 AM
I am testing the creation of 200 L2 VPNs on a ios cisco device.
I am using a 'tab-delimited' file to apply template variables.
I have been successful to apply the variables by using the tab-delimted file by commiting after each apply-template.
I have to run the entire ncs_cli > configure > cli commands > exit > exit for each time I apply the template variables.
Is there a way to apply the template variables by looping through all 200 variable sets prior to commiting?
Example TAB-DELIMITED file: l2-vpn_VARS.txt
---
200 200
201 201
202 202
300 300
301 301
302 302
---
Example BASH:
---
while read LR_ID VLAN_ID; do
echo "LR_ID_VAL=$LR_ID VLAN_ID_VAL=$VLAN_ID"
done < l2-vpn_VARS.txt
---
Example ncs_cli commands
---
while read LR_ID_VAL VLAN_ID_VAL; do
echo "LR_ID=$LR_ID_VAL VLAN_ID=$VLAN_ID_VAL"
ncs_cli -u admin << EOF1
configure
request devices device RTR-NAME apply-template template-name cisco-layer-2-vpn-example variable { name VLAN_ID value ${VLAN_ID_VAL} } variable { name LR_ID value ${LR_ID_VAL} }
commit
exit
exit
EOF1
done < DIRECTORY/l2-vpn_VARS.txt
---
Template creation
---
ncs_cli -u admin
configure
set devices template cisco-layer-2-vpn-example config ios:l2vpn-vfi l2vpn vfi context LR{$LR_ID}_VPLS vpn id {$LR_ID}
set devices template cisco-layer-2-vpn-example config ios:l2vpn-vfi l2vpn vfi context LR{$LR_ID}_VPLS autodiscovery bgp signaling ldp
tag add devices template cisco-layer-2-vpn-example config ios:l2vpn-vfi l2vpn vfi context LR{$LR_ID}_VPLS replace
set devices template cisco-layer-2-vpn-example config ios:bridge-domain bridge-domain-list {$VLAN_ID}
set devices template cisco-layer-2-vpn-example config ios:bridge-domain bridge-domain-list {$VLAN_ID} member vfi LR{$LR_ID}_VPLS
set devices template cisco-layer-2-vpn-example config ios:bridge-domain bridge-domain-list {$VLAN_ID} member interface-list Ethernet-Internal1/0/0 {$VLAN_ID}
tag add devices template cisco-layer-2-vpn-example config ios:bridge-domain bridge-domain-list {$VLAN_ID} replace
set devices template cisco-layer-2-vpn-example config ios:interface Ethernet-Internal 1/0/0 service instance {$VLAN_ID} ethernet encapsulation dot1q id {$VLAN_ID}
set devices template cisco-layer-2-vpn-example config ios:interface Ethernet-Internal 1/0/0 service instance {$VLAN_ID} ethernet rewrite ingress tag pop 1 mode symmetric
tag add devices template cisco-layer-2-vpn-example config ios:interface Ethernet-Internal 1/0/0 service instance {$VLAN_ID} replace
compare running brief
commit
show devices template cisco-layer-2-vpn-example
exit
exit
---
Solved! Go to Solution.
08-21-2017 10:01 PM
This question is about how to use bash basically.
There would be many ways, but here's an example I just created.
You can do more complicated things using pipes.
------
ncs_cli -u admin << EOF1
$(
echo "configure"
while read LR_ID_VAL VLAN_ID_VAL; do
echo "request devices device RTR-NAME apply-template template-name cisco-layer-2-vpn-example variable { name VLAN_ID value ${VLAN_ID_VAL}} variable { name LR_ID value ${LR_ID_VAL}}";
done < DIRECTORY/l2-vpn_VARS.txt
echo "commit"
echo "exit"
echo "exit"
)
EOF1
------
08-21-2017 10:01 PM
This question is about how to use bash basically.
There would be many ways, but here's an example I just created.
You can do more complicated things using pipes.
------
ncs_cli -u admin << EOF1
$(
echo "configure"
while read LR_ID_VAL VLAN_ID_VAL; do
echo "request devices device RTR-NAME apply-template template-name cisco-layer-2-vpn-example variable { name VLAN_ID value ${VLAN_ID_VAL}} variable { name LR_ID value ${LR_ID_VAL}}";
done < DIRECTORY/l2-vpn_VARS.txt
echo "commit"
echo "exit"
echo "exit"
)
EOF1
------
08-22-2017 08:52 AM
PERFECT
My bash script: Automate configuration of L2 VPN. 200 L2 VPNs configured per device (15 minutes per device).
Akira Iwamoto bash script: Automate configuration of L2 VPN. 200 L2 VPNs configured per device (3 min 24 sec per device).
Thank you a million times.
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: