cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1458
Views
0
Helpful
4
Replies

DNAC Velocity IF Else statement forloop

Khanminator
Level 1
Level 1

I want to create a DNAC velocity template where I can go through the ports of each switch in the stack and IF the interface contains the command "switchport access vlan 1" or "switchport access vlan 1" or "switchport access vlan 3", issue the statement "no spanning-tree portfast", else dont do anything.

 

I have created a draft as below where I go through the stack by entering how many stacks there are and the range I want. If under that stack I find that switchport access command, I want to execute the no spanning-tree portfast. Not sure how the syntax would go for velocity over here.

#foreach($switch in [1..${stack_member_count}])
interface range GigabitEthernet${switch}/0/1-$Ports
#if ($var == "switchport access vlan 1")
no spanning-tree portfast
#end
#end

4 Replies 4

Preston Chilcote
Cisco Employee
Cisco Employee

This sounds like a change you are planning to make only once.  The Day-N automation tools aren't designed that way.  With just a few exceptions, the automation process can't read the existing config on the switch to make a decision.

 Instead, consider how you would create a template to reconfigure the entire switch, in a repeatable way, including having the admin tell the switch which interfaces are in vlan 1,2,3, etc rather the admin asking the switch for that information.

Yes its a change I'll do once, I have used many templates to get the change done once if its a repetitive change. I have sseen IF Else statement where it actually does read existing configs and makes a decision, is there any documentation to your claim ? that would be useful, thanks.
So far I can use a forloop to enter the commands on a particular interface I enter, but cant seem to use the IF command successfully. since I dont have an IF statement, I used the code 3 times or can use it more to enter the desired interface or interface range to get the job done. IF statement would have been usefull, thats what I'm after


#set ($port1 = $port_number_format1)

#foreach($switch in [${port1}])
interface range GigabitEthernet${switch}
no spanning-tree portfast
#end


#set ($port2 = $port_number_format2)

#foreach($switch in [${port2}])
interface range GigabitEthernet${switch}
no spanning-tree portfast
#end


#set ($port3 = $port_number_format3)

#foreach($switch in [${port3}])
interface range GigabitEthernet${switch}
no spanning-tree portfast
#end



I didn't say it was impossible, just that it helps to understand how the system is designed.  It does not read the config as it provisions. But it does have a copy of the config from the last time it synced and it extracts some interface information that you can access with built in system variables.  interface.description is a common one, and for your purposes you can use interface.vlanid.  Try this in your simulator to see what I mean:

 

#foreach($i in $__interface)
interface  $i.portName
portMode is $i.portMode
portType is $i.portType
description is $i.description
vlanID is $i.vlanId
voiceVlan is $i.voiceVlan
#end

MartinKajan
Level 1
Level 1

As stated by @Preston Chilcote , you should be able to use the System Template Variables to do this, although it might take a bit of bending..

For every interface in a list of interfaces (list of interfaces can be taken from said variables)..
##..Bear in mind, this will take a list of all physical/virtual interfaces, so you need to make subsequent conditionals to check for the correct interfaces
if this vlanId for this port is in [1,2,3]..

Review Cisco Networking for a $25 gift card