cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1915
Views
85
Helpful
4
Replies

Automate shutdown ports based on description

david.moore.83
Level 1
Level 1

Just started a new job in a DNA Center environment. We are replacing our HP Aruba AP's. I need to shut down every port with the description of "Aruba AP", then no shut them after installation. There's about 100 AP's at this site. Do I need to learn python and rest api's? Does anyone have a script already made that I can tweak? Or point me in the right direction to learn how to do it.

 

Any help is appreciated!

 

1 Accepted Solution

Accepted Solutions

Here's a better way, pointed out by my colleague:

 

#foreach( $int in $__interface )
$int.portName
#if ($int.description.contains("Aruba AP"))
shut
#else
!nothing to do here
#end
#end

View solution in original post

4 Replies 4

Preston Chilcote
Cisco Employee
Cisco Employee

First, a few things to keep in mind about DNA templates. The template editor works to produce a text file config before it logs into the device.  That means, it (in general) is not interactive, so doing things like looking for existing config and acting against it is often not possible.  BUT, there are some builtin variables that DNA does store as part of inventory, including all the things you see if you click on a device name in inventory (mtu, interface speed, interface name, and description!!).  So, you can actually do what you need since DNA has collected the interface descriptions during the last resync.

 

Combine that with a little VTL scripting logic (I think this link is a great intro: https://github.com/kebaldwi/DNAC-TEMPLATES/blob/master/Velocity.md )

 

and you can do something like:

#foreach ( $index in [0..70])
$__interface[$index].portName
#if ($__interface[$index].description.contains("Aruba AP"))
shut
#else
!nothing to do here
#end
#end

 

The hard part is figuring out what the max index number is.  The template will not succeed if you pick a number too high.  How similarly configured are all your switches?  If they are all identical, then doing the work to find the number once and using it for every template isn't too big a deal, but it's not going to be very practical to find it on a per device basis.

 

I think we definitely need an easier solution to loop through interfaces to do things like what you're asking.

Here's a better way, pointed out by my colleague:

 

#foreach( $int in $__interface )
$int.portName
#if ($int.description.contains("Aruba AP"))
shut
#else
!nothing to do here
#end
#end

Thanks Preston that worked. Just needed to add "int" before $int.portName

Mike.Cifelli
VIP Alumni
VIP Alumni

@Preston Chilcote shared info is great.  Here are some additional items that may help:

-Getting started with DNAC APIs: Cisco DNA Center Platform APIs and Integrations Overview - Cisco DevNet

--The DNAC Developer API toolkit is good for testing APIs

-Look into linux curl tool.  Quick way to test consuming APIs to understand proper payload and formatting, etc. 

-Understanding REST can go a long way in regard to CRUD operations; there are a ton of resources on youtube/internet.

-IMO there is no cut and dry answer.  Trial and error practice helps and goes a long way.  You will start to see that required payloads for certain APIs have different requirements.  In your scenario mentioned one that may become tricky with relying on API consumption is 'interfaceName'.  You will see that this varies per platform.  

-Lastly, check out all the devnet resources available as that is another great repository of information.

HTH!