Renderer Plugins

Renderers responsible for combining data with templates and producing text output.

Jinja2 Renderer Plugin

Prerequisites:

Warning

data keys or table headers must be valid Python variable names for Jinja2 engine to work correctly, e.g. a variable name must start with a letter or the underscore character.

This renderer uses Jinja2 templates to render data and produce text results.

For example, if this is a data to render expressed in YAML format:

- interface: Gi1/1
  description: Customer A
  dot1q: 100
  ip: 10.0.0.1
  mask: 255.255.255.0
  vrf: cust_a
  template: ttr://interfaces.cisco_ios
  device: rt-1
- interface: Gi1/2
  description: Customer B
  dot1q: 200
  ip: 10.0.2.1
  mask: 255.255.255.0
  vrf: cust_b
  template: ttr://interfaces.cisco_ios
  device: rt-2

template_name_key corresponds to template key in above data, result_name_key corresponds to device key in above data.

And this is the content of ttr://interfaces.cisco_ios template:

interface {{ interface }}
 description {{ description }}
 encapsulation dot1q {{ vid }}
 vrf forwarding  {{ vrf }}
 ip address {{ ip }} {{ mask }}
 ipv6 address {{ ipv6 }}/{{ maskv6 }}
!

This renderer will combine each item in above data with ttr://interfaces.cisco_ios template and return results for further processing.

ttr.plugins.renderers.jinja2_renderer.render(data, template_name_key, templates, templates_dict, result_name_key, **renderer_kwargs)

Render function takes data, templates and produces text output.

Parameters
  • data – (list), list of dictionaries render

  • templates_dict – (dict), dictionary keyed by template name with template content as a value

  • template_name_key – (str), name of template key to use for data rendering, default - template

  • result_name_key – (str), name of result key to use to combine rendering results, default - device

  • renderer_kwargs – (dict), kwargs to pass on to jinja2.Template(.., **kwargs) object instantiation

By default renderer_kwargs will include:

{"trim_blocks": True, "lstrip_blocks": True}