wiki:Usage/TemplatingDocumentation

The Django Templating Language

CMT utilizes Django's Templating engine to process templates.

For a complete description of the Django templating engine, please read the documentation about the Django template language at the Django website.

CMT extra templatetags

For Cluster Management purposes, a few extra tags have been added. These extra tags can be used and loaded for your template with the tag:

{% load cmt_client %}

Without loading this, you cannot use any of the tags below.

Stringfilters

Stringfilters are functions that can pipe or translate a value into a different one. It's syntax is always through the use of a pipe:

  • 'string'|<stringfilter>
  • <variable>|<stringfilter>

arpanize

Converts an IPv4 (range) to reversed DNS style ARPA notation

DEPRECATED: use reverse_name or reverse_names in stead

Usage

{{ <variable>|arpanize }}

Examples

{% assign broadcast = '192.168.1.0' %}
{{ broastcast|arpanize }}

Example output

1.168.192.in-addr.arpa

base_net

Converts an IPv4 (range) to it's first 3 octets

Usage

{{ <variable>|base_net }}

Examples

{% assign broadcast = '192.168.1.0' %}
{{ broastcast|base_net }}

Example output

192.168.1

ip_last_digit

Converts an IP (range) to its last octet.

Usage

{{ <variable>|ip_last_digit }}

Examples

{% assign myip = '192.168.1.123' %}
{{ myip|ip_last_digit }}

Example output

123

reverse_name

Return's a IP or CIDR reverse (arpa) name

Usage

{{ <variable>|reverse_name }}

Examples

{% assign ip4cidr24 = '192.168.1.0/24' %}
ip4cidr/24 = {{{ ip4cidr24 }}}
ip4cidr/24 reverse name = {{{ ip4cidr24|reverse_name }}}

{% assign ip4cidr30 = '192.168.1.0/28' %}
ip4cidr/30 = {{{ ip4cidr30 }}}
ip4cidr/30 reverse name = {{{ ip4cidr30|reverse_name }}}

{% assign ip4 = '192.168.1.123' %}
ip4 = {{{ ip4 }}}
ip4 reverse name = {{{ ip4|reverse_name }}}

{% assign ip6cidr64 = 'fd93:59ef:8ce1:aac8::/64' %}
ip6cidr/64 = {{{ ip6cidr64 }}}
ip6cidr/64 reverse name  = {{{ ip6cidr64|reverse_name }}}

{% assign ip6cidr76 = 'fd93:59ef:8ce1:aac8::/76' %}
ip6cidr/76 = {{{ ip6cidr76 }}}
ip6cidr/76 reverse name  = {{{ ip6cidr76|reverse_name }}}

{% assign ip6 = 'fd93:59ef:8ce1:aac8::123' %}
ip6 = {{{ ip6 }}}
ip6 reverse name  = {{{ ip6|reverse_name }}}

Example output

ip4cidr/24 = 192.168.1.0/24
ip4cidr/24 reverse name = 1.168.192.in-addr.arpa.

ip4cidr/30 = 192.168.1.0/30
ip4cidr/30 reverse name = 0-3.1.168.192.in-addr.arpa.

ip4 = 192.168.1.123
ip4 reverse name = 123.1.168.192.in-addr.arpa.

ip6cidr/64 = fd93:59ef:8ce1:aac8::/64
ip6cidr/64 reverse name = 8.c.a.a.1.e.c.8.f.e.9.5.3.9.d.f.ip6.arpa.

ip6cidr/76 = fd93:59ef:8ce1:aac8::/76
ip6cidr/76 reverse name = 0.0.0.8.c.a.a.1.e.c.8.f.e.9.5.3.9.d.f.ip6.arpa.

ip6 = fd93:59ef:8ce1:aac8::123
ip6 reverse name = 3.2.1.0.0.0.0.0.0.0.0.0.0.0.0.0.8.c.a.a.1.e.c.8.f.e.9.5.3.9.d.f.ip6.arpa.

reverse_names

Return's a CIDR reverse (arpa) name

Usage

{{ <variable>|reverse_names }}

Examples

{% assign ip4cidr24 = '192.168.1.0/24' %}
ip4cidr/24 = {{{ ip4cidr24 }}}
ip4cidr/24 reverse names = {{{ ip4cidr24|reverse_names }}}

{% assign ip4cidr30 = '192.168.1.0/30' %}
ip4cidr/30 = {{{ ip4cidr30 }}}
ip4cidr/30 reverse names = {{{ ip4cidr30|reverse_names }}}

{% assign ip6cidr64 = 'fd93:59ef:8ce1:aac8::/64' %}
ip6cidr/64 reverse names  = {{{ ip6cidr64|reverse_names }}}

Example output

ip4cidr/24 = 192.168.1.0/24
ip4cidr/24 reverse names = 1.168.192.in-addr.arpa.

ip4cidr/30 = 192.168.1.0/30
ip4cidr/30 reverse names = 0.1.168.192.in-addr.arpa.
ip4cidr/30 reverse names = 1.1.168.192.in-addr.arpa.
ip4cidr/30 reverse names = 2.1.168.192.in-addr.arpa.
ip4cidr/30 reverse names = 3.1.168.192.in-addr.arpa.

ip6cidr/64 = fd93:59ef:8ce1:aac8::/64
ip6cidr/64 reverse names = 8.c.a.a.1.e.c.8.f.e.9.5.3.9.d.f.ip6.arpa.

Functions

Functions are called with the following syntax:

{% <function> <arguments> %}

assign

Concatenates any combination of (space separated) variables and strings and assigns it to a new variable.

Usage

{% assign <varname> = <str|var> [[str|var] [str|var] [..]]

Examples

{% assign newvar = <space seperated list of strings/vars> %}
{% assign myabbreviation = 'bla' %}
{% assign file_name = '/var/tmp/rack-' rack.label '.txt' %}
{% assign elite = 'foo' host.label 'bar' %}

getbasenets

Get list of basenets in a network (name).

Usage

{% getbasenets <network name> as <listname> %}

Examples

Let's assume "MY ADMIN" network is: 192.168.10.0/23

{% getbasenets 'MY ADMIN' as network_basenets %}

{% for bnet in network_basenets %}
{{ bnet }}
{% endfor %}

Example output

192.168.10
192.168.11

getracks

Get list of all racks in a cluster.

Usage

{% getracks <cluster> as <listname> %}

Examples

Let's assume the cluster with name "TINA" consists of 3 racks with the labels: r1, r5, r6

{% getracks 'TINA' as tina_racks %}

{% for r in tina_racks %}
{{ r.label }}
{% endfor %}

Example output

r1
r5
r6

use

Compilation function to define Querysets for later use.

Usage

{% use <entity> with <attribute>=<value> as <variable> %}

Examples

{% use hardwareunit with 'cluster__name=Gina' as gina_hosts %}
{% use network with 'name__contains=gina' as gina_networks %}
{% use network with 'name=gina admin' as net_gina_admin %}
{% use interface with 'network__name=gina admin' as ifaces_gina_admin %}

Sections

Sections are used to indicate the tag will only affect the section contained therein. Sections always have a opening and closing tag and can contain arguments:

{% <section> [arguments] %}
{% <endsection> %}

epilogue

Commands to be executed after (epi) the template processing is completed. This can be useful to restart a daemon for example, with a new configuration made by processing the template:

Section start

{% epilogue %}

Section end

{% endepilogue %}

Examples

{% epilogue %} 
/etc/init.d/named reload
touch /var/run/named.pid
{% endepilogue %}

noblanklines

Prevents any blanklines occurring in the resulting output (file).

Section start

{% noblanklines %}

Section end

{% endnoblanklines %}

Example's

{% noblanklines %} 
{{ host.label }}

{{ host.rack }}
{% endnoblanklines %}

store

Specifies where to store the resulting output (after template processing).

Section start

{% store <filename> %}

Where <filename> can be:

  • variable
  • 'Quoted string'

Section end

{% endstore %}

Examples

{% store '/path/to/file' %}
{{ host.label }}
{% endstore %}
{% store variable %} 
{{ host.label }}
{% endstore %}
Last modified 7 years ago Last modified on 08/29/13 11:17:49