wiki:Usage/TemplatingDocumentation

Version 11 (modified by ramonb, 12 years ago) (diff)

--

Templating

CMT utilizes DJango's Templating engine to process templates.

load

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 %}

stringfilters

Stringfilters are functions that can pipe or translate a value into a different one.

base_net

    """
        Converts a IP (range) to it's first 3 octects

        Usage:
            {{{ <variable>|base_net }}}

        I.e.:
            {% assign broadcast = '192.168.1.0' %}
            {{{ broastcast|base_net }}}
        Results in output:
            192.168.1
    """

ip_last_digit

    """
        Converts a IP (range) to it's last octect

        Usage:
            {{{ <variable>|ip_last_digit }}}

        I.e.:
            {% assign myip = '192.168.1.123' %}
            {{{ myip|ip_last_digit }}}
        Results in output:
            123
    """

arpanize

    """
        Converts a IP (range) to reversed DNS style arpa notation

        Usage:
            {{{ <variable>|arpanize }}}

        I.e.:
            {% assign broadcast = '192.168.1.0' %}
            {{{ broastcast|arpanize }}}
        Results in output:
            1.168.192.in-addr.arpa
    """

functions

getracks

    """
        Get list of racks in a cluster

        Usage: {% getracks <cluster> as <listname> %}
    """

assign

    """
        Variable assignment within template

        Usage: {% assign newvar = <space seperated list of strings/vars> %}
         i.e.: {% assign file_name = '/var/tmp/rack-' rack.label '.txt' %}
    """

getbasenets

    """
        Get list of basenets in a network (name)

        Usage: {% getbasenets <network name> as <listname> %}
    """

use

    """
        Compilation function to definine Querysets for later use.

        Usage: {% use <entity> with <attribute>=<value> as <list/var> <key> %}
    """

sections

epilogue

Command's to be executed after (epi) the template processing is completed.

This can be useful to restart a daemon, for example.

noblanklines

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

store

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 %}