Version 27 (modified by ramonb, 12 years ago) (diff) |
---|
The Django Templating Language
CMT utilizes Django's Templating engine to process templates.
For a complete description of the DJango templating engine, please visit the DJango website here:
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.
arpanize
Converts a IP (range) to reversed DNS style arpa notation
Usage:
- {{ <variable>|arpanize }}
Example's:
-
{% assign broadcast = '192.168.1.0' %} {{ broastcast|arpanize }}
Example output:
- 1.168.192.in-addr.arpa
base_net
Converts a IP (range) to it's first 3 octects
Usage:
- {{ <variable>|base_net }}
Example's:
-
{% assign broadcast = '192.168.1.0' %} {{ broastcast|base_net }}
Example output:
- 192.168.1
ip_last_digit
Converts a IP (range) to it's last octect
Usage:
- {{ <variable>|ip_last_digit }}
Example's:
-
{% assign myip = '192.168.1.123' %} {{ myip|ip_last_digit }}
Example output:
- 123
functions
Functions are called with the following syntax:
- {% <function> <arguments> %}
assign
Variable assignment within template
Usage:
- {% assign <varname> = <str|var> [[str|var] [str|var] [..]]
Example's:
- {% 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> %}
Example's:
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> %}
Example's:
-
{% use HardwareUnit with 'cluster__name=Gina' as gina_hosts %} {% getracks 'Gina' as gina_racks %} {% for r in gina_racks %} {% assign filename = '/var/tmp/hosts.' r.label '.in' %} {% store filename %} {% noblanklines %} # Hosts file containing all hosts from rack: {{ r.label }} {% for h in gina_hosts %} {% if h.rack.label == r.label %} {{ h.label }} {% endif %} {% endfor %} {% endnoblanklines %} {% endstore %} {% endfor %}
use
Compilation function to definine Querysets for later use.
Usage:
- {% use <entity> with <attribute>=<value> as <list/var> <key> %}
Example's:
- {% 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
epilogue
Command's to be executed after (epi) the template processing is completed.
This can be useful to restart a daemon, for example.
Section start:
- {% epilogue %}
Section end:
- {% endepilogue %}
Example's:
-
{% epilogue %} /etc/init.d/named reload touch /var/run/named.pid {% endepilogue %}
noblanklines
Prevents any blanklines occuring 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> %}
- <filename> can be:
- variable
- 'Quoted string'
Section end:
- {% endstore %}
Example's:
-
{% store '/path/to/file' %} {{{ host.label }}} {% endstore %}
-
{% store variable %} {{{ host.label }}} {% endstore %}