Changes between Version 32 and Version 33 of Usage/TemplatingDocumentation


Ignore:
Timestamp:
07/10/12 17:44:53 (12 years ago)
Author:
sil
Comment:

merged some other docs into this page, and did some refactoring/corrections

Legend:

Unmodified
Added
Removed
Modified
  • Usage/TemplatingDocumentation

    v32 v33  
    11[[PageOutline]]
    22
     3
    34= The Django Templating Language =
    45
    56CMT utilizes Django's Templating engine to process templates.
    67
    7 For a complete description of the Django templating engine, please visit the DJango website here:
    8  * [https://docs.djangoproject.com/en/dev/topics/templates/ The Django template language]
     8For a complete description of the Django templating engine, please read the documentation about [https://docs.djangoproject.com/en/dev/topics/templates/ the Django template language] at the Django website.
     9
    910
    1011= CMT extra templatetags =
    1112
    12 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:
    13  * {{{ {% load cmt_client %} }}}
     13For Cluster Management purposes, a few extra tags have been added.
     14These extra tags can be used and loaded for your template with the tag:
     15{{{
     16{% load cmt_client %}
     17}}}
    1418
    1519Without loading this, you cannot use any of the tags below.
    1620
     21
    1722= Stringfilters =
    1823
    19 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:
     24Stringfilters are functions that can pipe or translate a value into a different one.
     25It's syntax is always through the use of a pipe:
    2026 * {{{ 'string'|<stringfilter> }}}
    2127 * {{{ <variable>|<stringfilter> }}}
    2228
     29
    2330== arpanize ==
    2431
    2532Converts an IP (range) to reversed DNS style ARPA notation
    2633
    27 '''Usage''':
    28  * {{{ {{ <variable>|arpanize }} }}}
    29 
    30 '''Example's''':
    31  *
     34'''Usage'''
     35{{{
     36{{ <variable>|arpanize }}
     37}}}
     38
     39'''Examples'''
    3240{{{
    3341{% assign broadcast = '192.168.1.0' %}
     
    3543}}}
    3644
    37 '''Example output''':
    38  * {{{ 1.168.192.in-addr.arpa }}}
     45'''Example output'''
     46{{{
     471.168.192.in-addr.arpa
     48}}}
     49
    3950
    4051== base_net ==
     
    4253Converts an IP (range) to it's first 3 octets
    4354
    44 '''Usage''':
    45  * {{{ {{ <variable>|base_net }} }}}
    46 
    47 '''Example's''':
    48  *
     55'''Usage'''
     56{{{
     57{{ <variable>|base_net }}
     58}}}
     59
     60'''Examples'''
    4961{{{
    5062{% assign broadcast = '192.168.1.0' %}
     
    5264}}}
    5365
    54 '''Example output''':
    55  * {{{ 192.168.1 }}}
     66'''Example output'''
     67{{{
     68192.168.1
     69}}}
     70
    5671
    5772== ip_last_digit ==
    5873
    59 Converts an IP (range) to it's last octet
    60 
    61 '''Usage''':
    62  * {{{ {{ <variable>|ip_last_digit }} }}}
    63 
    64 '''Example's''':
    65  *
     74Converts an IP (range) to its last octet.
     75
     76'''Usage'''
     77{{{
     78{{ <variable>|ip_last_digit }}
     79}}}
     80
     81'''Examples'''
    6682{{{
    6783{% assign myip = '192.168.1.123' %}
     
    6985}}}
    7086
    71 '''Example output''':
    72  * {{{ 123 }}}
     87'''Example output'''
     88{{{
     89123
     90}}}
     91
     92
    7393
    7494= Functions =
    7595
    7696Functions are called with the following syntax:
    77  * {{{ {% <function> <arguments> %} }}}
     97{{{
     98{% <function> <arguments> %}
     99}}}
     100
    78101
    79102== assign ==
    80103
    81 Concatenates any combination of (space separated) variable's and strings and assigns it to a new variable.
    82 
    83 '''Usage''':
    84  * {{{ {% assign <varname> = <str|var> [[str|var] [str|var] [..]] }}}
    85 
    86 '''Example's''':
    87  * {{{ {% assign newvar = <space seperated list of strings/vars> %} }}}
    88  * {{{ {% assign myabbreviation = 'bla' %} }}}
    89  * {{{ {% assign file_name = '/var/tmp/rack-' rack.label '.txt' %} }}}
    90  * {{{ {% assign elite = 'foo' host.label 'bar' %} }}}
     104Concatenates any combination of (space separated) variables and strings and assigns it to a new variable.
     105
     106'''Usage'''
     107{{{
     108{% assign <varname> = <str|var> [[str|var] [str|var] [..]]
     109}}}
     110
     111'''Examples'''
     112{{{
     113{% assign newvar = <space seperated list of strings/vars> %}
     114}}}
     115
     116{{{
     117{% assign myabbreviation = 'bla' %}
     118}}}
     119
     120{{{
     121{% assign file_name = '/var/tmp/rack-' rack.label '.txt' %}
     122}}}
     123
     124{{{
     125{% assign elite = 'foo' host.label 'bar' %}
     126}}}
     127
    91128
    92129== getbasenets ==
     
    94131Get list of basenets in a network (name).
    95132
    96 '''Usage''':
    97  * {{{ {% getbasenets <network name> as <listname> %} }}}
    98 
    99 '''Example's''':
     133'''Usage'''
     134
     135{{{
     136{% getbasenets <network name> as <listname> %}
     137}}}
     138
     139'''Examples'''
    100140
    101141Let's assume "MY ADMIN" network is: 192.168.10.0/23
    102142
    103  *
    104143{{{
    105144{% getbasenets 'MY ADMIN' as network_basenets %}
     
    110149}}}
    111150
    112 '''Example output''':
    113  *
     151'''Example output'''
     152
    114153{{{
    115154192.168.10
     
    117156}}}
    118157
     158
    119159== getracks ==
    120160
    121161Get list of all racks in a cluster.
    122162
    123 '''Usage''':
    124  * {{{ {% getracks <cluster> as <listname> %} }}}
    125 
    126 '''Example's''':
     163'''Usage'''
     164
     165{{{
     166{% getracks <cluster> as <listname> %}
     167}}}
     168
     169'''Examples'''
    127170
    128171Let's assume the cluster with name "TINA" consists of 3 racks with the labels: !r1, !r5, !r6
    129172
    130  *
    131173{{{
    132174{% getracks 'TINA' as tina_racks %}
     
    137179}}}
    138180
    139 '''Example output''':
    140  *
     181'''Example output'''
     182
    141183{{{
    142184r1
     
    145187}}}
    146188
     189
    147190== use ==
    148191
    149192Compilation function to define Querysets for later use.
    150193
    151 '''Usage''':
    152  * {{{ {% use <entity> with <attribute>=<value> as <variable> %} }}}
    153 
    154 '''Example's''':
    155  * {{{ {% use hardwareunit with 'cluster__name=Gina' as gina_hosts %} }}}
    156  * {{{ {% use network with 'name__contains=gina' as gina_networks %} }}}
    157  * {{{ {% use network with 'name=gina admin' as net_gina_admin %} }}}
    158  * {{{ {% use interface with 'network__name=gina admin' as ifaces_gina_admin %} }}}
     194'''Usage'''
     195{{{
     196{% use <entity> with <attribute>=<value> as <variable> %}
     197}}}
     198
     199'''Examples'''
     200{{{
     201{% use hardwareunit with 'cluster__name=Gina' as gina_hosts %}
     202}}}
     203
     204{{{
     205{% use network with 'name__contains=gina' as gina_networks %}
     206}}}
     207
     208{{{
     209{% use network with 'name=gina admin' as net_gina_admin %}
     210}}}
     211
     212{{{
     213{% use interface with 'network__name=gina admin' as ifaces_gina_admin %}
     214}}}
    159215
    160216= Sections =
    161217
    162 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:
    163  *
     218Sections are used to indicate the tag will only affect the section contained therein.
     219Sections always have a opening and closing tag and can contain arguments:
     220
    164221{{{
    165222{% <section> [arguments] %}
     
    169226== epilogue ==
    170227
    171 Command's to be executed after (epi) the template processing is completed.
    172 
    173 This can be useful to restart a daemon, for example.
    174 
    175 '''Section start''':
    176  * {{{ {% epilogue %} }}}
    177 
    178 '''Section end''':
    179  * {{{ {% endepilogue %} }}}
    180 
    181 '''Example's''':
    182 
    183  *
     228Commands to be executed after (epi) the template processing is completed.
     229This can be useful to restart a daemon for example, with a new configuration made by processing the template:
     230
     231'''Section start'''
     232{{{
     233{% epilogue %}
     234}}}
     235
     236'''Section end'''
     237{{{
     238{% endepilogue %}
     239}}}
     240
     241'''Examples'''
     242
    184243{{{
    185244{% epilogue %}
     
    194253Prevents any blanklines occurring in the resulting output (file).
    195254
    196 '''Section start''':
    197  * {{{ {% noblanklines %} }}}
    198 
    199 '''Section end''':
    200  * {{{ {% endnoblanklines %} }}}
    201 
    202 '''Example's''':
    203 
    204  *
     255'''Section start'''
     256{{{
     257{% noblanklines %}
     258}}}
     259
     260'''Section end'''
     261{{{
     262{% endnoblanklines %}
     263}}}
     264
     265'''Example's'''
    205266{{{
    206267{% noblanklines %}
     
    210271{% endnoblanklines %}
    211272}}}
     273
     274
    212275== store ==
    213276
    214277Specifies where to store the resulting output (after template processing).
    215278
    216 '''Section start''':
    217  * {{{ {% store <filename> %} }}}
    218 
    219   * {{{ <filename> }}} can be:
     279'''Section start'''
     280{{{
     281{% store <filename> %}
     282}}}
     283
     284Where {{{ <filename> }}} can be:
    220285    * variable
    221286    * 'Quoted string'
    222287
    223 '''Section end''':
    224 
    225  * {{{ {% endstore %} }}}
    226 
    227 '''Example's''':
    228 
    229  *
     288'''Section end'''
     289
     290{{{
     291{% endstore %}
     292}}}
     293
     294'''Examples'''
     295
    230296{{{
    231297{% store '/path/to/file' %}
     
    233299{% endstore %}
    234300}}}
    235  *
     301
    236302{{{
    237303{% store variable %}