03-03-2022 12:25 PM
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!
Solved! Go to Solution.
03-03-2022 03:57 PM
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
03-03-2022 03:18 PM - edited 03-03-2022 03:57 PM
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.
03-03-2022 03:57 PM
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
03-04-2022 12:59 PM
Thanks Preston that worked. Just needed to add "int" before $int.portName
03-04-2022 05:05 AM
@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!
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide