I am working with Cisco Prime Infrastructure and need to create a CLI template for mass deployment to some switches. Prime uses Apache Velocity for its CLI content to script. I have run into a problem where I am running some code that loops through the VLANS on a switch and performs action per VLAN. The code works fine if the switch has multiple VLANS, but fails if it only has one. Example:
Switch1 consists of Vlan 1, so the array looks like this [Vlan1]
Switch2 consists of Vlan 1, Vlan 2, Vlan 3, array looks like [Vlan1, Vlan2, Vlan3]
The code:
#foreach($vlan in $VlanName)
interface $vlan
no ip helper-address
#end
$VlanName is defined in the Prime Database and returns the array of vlans on each switch. The above will work on Switch2 but will fail on Switch1. Is there a way in Apache Velocity to do a check to see if the array holds more than a single value? I would like to do an IF statement that changes the code to something like this:
#if ($VlanName.count = 1)
interface $VlanName
no ip helper-address
#else
#foreach($vlan in $VlanName)
interface $vlan
no ip helper-address
#end
Is this possible in Velocity?