Description

This article describes a deviceModel, where to find it, and how it is used in creating custom Configlets by using Jinja expressions in Juniper Apstra.

Solution

The Configlet in Juniper Apstra is a template with the exact set of CLI commands that customers wish to be deployed to the device. These commands or file contents are issued directly to the devices. The Configlet supports a static template as well as the use of Jinja2 delimiters, and it is up to customers to decide whether they want to use a static or a dynamic Jinja template.

  • For static template Configlets, refer to the Juniper Apstra documentation at Configlets .

  • In the dynamic Jinja-based templates, customers can make use of the ready-to-use deviceModel to render values at run time.

This article describes how a deviceModel is used in creating custom Configlets by using Jinja expressions. 
 

Using Jinja in Configlets

Note: deviceModel is a hidden feature prior to Apstra version 4.1.0 and exposed thereafter. It needs to be used with caution, even more so than regular Configlets.
 

Users can access the Juniper Apstra internal deviceModel, which essentially serves as built-in property sets for Configlets. This can be useful for some use cases where users must apply the Configlet to many switches or interfaces with parameterized values, or where they want the Configlet to include data (such as the switch’s own ASN or IP addresses) from the Blueprint.

For such use cases, this feature can potentially reduce the number of Configlets that need to be created, applied, and maintained.

​Users can find deviceModel in their environment at https://APSTRA_SERVER_IP/webcons/Main/aos/v0/device/deployment/config/DEVICE_SERIAL_NO/field/deviceModel  (replace  APSTRA_SERVER_IP  and  DEVICE_SERIAL_NO with your values in the link). To view the deviceModel, customers can use developer webcons via a browser.  
 

From Apstra version 4.1.0 onwards users can find the Device Model directly in a Blueprint under Staged--> Physical--> Topology--> Select a particular Device-->bottom right corner "Device Context". Users can view various Jinja variables only related to the rendered configuration of that specific device under that option and use adequately in a Jinja Template based Configlet.

Example DeviceModel in Apstra 4.1.0 Onwards

Each Jinja configuration file makes use of the "deviceModel," which is the internal dictionary that Juniper Apstra builds from the blueprint graph. Note that this deviceModel is passed as a Python dictionary to each of the Jinja files.

The Jinja configuration files can be modified, but this takes a steady hand and familiarity with the deviceModel and deployment strategies. A couple of examples are given here that demonstrate how Configlets can be created using Jinja.
 

Example of Configlets Using Jinja (Example 1)

In this example, the Configlet template dynamically generates the BGP ASN number and Router ID of the device by using {{ bgpService.asn }} , {{ bgpService.router_id }} , and {{ logical_vtep_ipv4_address }}.


All values for the respective keys will be fetched from the deviceModel dictionary during configuration rendering and put into the resulting rendered configuration.

alt

Example of Configlets Using Jinja (Example 2)

In this example, a complex use case of Jinja-based Configlets is shown with variable declaration and iteration used for loop.

Here, a dictionary "bgp_filters" is instantiated, and then looped through the dictionary to generate a prefix list configuration.

alt

Note: The above examples are for illustration purposes only. It is a customer's responsibility to ensure that correct syntax and commands are used in Configlet. Juniper Apstra always recommends that customers should test the configuration in a lab before the Configlet is deployed to devices in production because any incorrect template syntax could lead to deployment failure.

 

Modification History

2022-11-21: Added from Apstra 4.1.0 onwards Device Model is directly exposed in a Blueprint