This Bridge is the Root

View Original

Introduction to Cisco DNA Center Templates

One of the many powerful features of Cisco's DNA Center is its templating engine. You can configure nearly your entire network from here. From the default installation, Cisco includes a couple of templates that can help you with DMVPN configuration but these are mainly meant as an introduction to the templating engine.

Cisco built their templating engine to use the Velocity Template Language which has plenty of documentation on its markup.

In this quick introduction, I'm going to walk you through creating your first template with a simple 'foreach' loop as well as some of the hotkeys that Cisco has built in that can make editing your template go a little faster.

Creating a Template

We first have to go into the Template Editor within DNAC by clicking to Tools icon in the upper right hand corner and selecting the Template Editor page.

Once in the Template Editor page, you'll notice that Cisco has included two sample projects and multiple sample templates. Take a second to look through these to get a feel for the Velocity language.

Once you've done that, it's time to create a new template for our usage by selecting the plus icon and selecting Create Template.

This opens up a page on the right hand side where we can specify a couple of things like the name of the template and the project it's going to be in. Importantly here is what we specify are going to be the target devices and software type. These will impact what devices we can apply the policy to later in the process. In this simple template, I'm just going to create a template that enables LLDP on my switches.



Editing Your Configuration

Once the template has been created, we're presented with the editor where we can type the commands that will be applied to our devices.

The Velocity Template Language is pretty powerful and I'm only scratching the surface here but below you can see a screenshot of a simple foreach loop for configuring multiple ranges of interfaces. Variables are created simply by defining them with a dollar sign. If you run into a situation where you want to append text directly after a variable, you have to surround the variable name with curly brackets.

The foreach loop is created simply by starting the block with #foreach ( $variable in $listOfVariables ) and it's closed with #end. If you would like to iterate through to a number like I have, incase your integer in brackets and your starting digit. For example [1..$number] where $number is 5 will produce a loop that iterates 1,2,3,4,5. In this case, I've create a variable that is the number of switches that will be in a stack and created a range command to configure them all to vlan 100.

We have to save this code before moving on to the next step. You can save by using crtl+s (Windows), command+s (Mac), or by selecting Save from the Actions menu. You'll also notice that there is a commit option under the Actions menu. Commit is used when you're done editing your template, you've tested it by running a simulation and you're ready to apply it to production devices.

While here, you can also try out some of the useful hotkeys and shortcuts that Cisco has included in the code editor. These shortcuts are copied from available IDEs and text editors like Sublime and Atom. [Ctrl/Command]+D will duplicate the current line. Useful for when you're creating multiple interfaces at the same time.

You can also use column select to edit multiple lines at the same time. Simply hold Option while dragging your mouse cursor. Here, I'm editing multiple interfaces to be in the same port-channel.

I'm sure Cisco has baked in more features that I haven't found yet. If you know of any I’ve missed, let me know in the comments below.


Configuring the Forms

The next step is to define your variables and create a form. Select the form editor in the upper right hand corner. Here we can give the variable a more human friendly name, provide tool tips, or change what type of input it is. An input can have a data type of String, Integer, IP Address, or MAC Address. The input box can also be displayed as a Text Field, Single Select, or Multiple Select depending on your needs.

For our switch stack, I've chosen an integer with a text field. I've also provided upper and lower bounds to the integer that the user can input. You'll notice that you can chose to bind to source. This is for using data that exists elsewhere in DNAC to use as a variable in the template.

Once you're happy on the Form Editor page, click save under the Actions menu and Navigate to the Simulation Editor in the upper right hand corner.


Simulating a Profile

Here, we can provide our template with sample inputs and see the output from the script. I've simply put 2 as the input for the switch stack variable and my template has produced a config for both switches.

After you're happy with your template, you can commit it under the Actions menu, go back to the DNAC page and attach it to a Network Profile under the Design tab.

Cisco documentation for DNA Center templates can be found here.