Changes between Version 7 and Version 8 of Usage/UserDocumentation


Ignore:
Timestamp:
06/04/12 17:18:59 (12 years ago)
Author:
sil
Comment:

adde documentation about CMT templates

Legend:

Unmodified
Added
Removed
Modified
  • Usage/UserDocumentation

    v7 v8  
    384384= CMT Templates =
    385385
    386 CMT offers a powerful feature, powered by templates based on the [https://docs.djangoproject.com/en/dev/topics/templates/ Django Template Language].
    387 With these template-files you're able to let CMT generate various kind of files, like configuration files or reports about your clusters.
     386CMT offers a powerful feature, powered by templates.
     387With these templates you're able to let CMT generate various kind of files, like configuration files or reports about your clusters.
     388
     389The syntax of the templates in CMT is based on Django templates, therefore the documentation of the [https://docs.djangoproject.com/en/dev/topics/templates/ Django template language] can be useful as a reference.
     390Django templates are usually meant for web pages, but since we use it for our configuration files some functionalities have been added for CMT-specific needs.
     391By extending the Django template language, it has been made possible to:
     392 * Define an epilogue script
     393 * Pre-load datasets from database
     394 * Set a path to write the output to
     395
     396To make use of these functionalities you have to start your template with
     397
     398{{{
     399{% load cmt_client %}
     400}}}
     401
     402and store the file in your template-directory as `<name>.cmt`
     403
     404
     405== Epilogue script ==
     406
     407Some configuration files need to be reloaded by the program when they are modified.
     408Or maybe some other things should be done to activate the new configuration.
     409This is where an epilogue script comes in.
     410You can write the epilogue script in the template itself, between the ''epilogue'' and ''endepilogue'' tag:
     411
     412{{{
     413{% epilogue %}
     414# this epilogue-script will restart the DHCP server
     415/etc/init.d/dhcp3-server restart
     416{% endepilogue %}
     417}}}
     418
     419
     420== Pre-load datasets from database ==
     421
     422You may define collections of objects to use in your templates.
     423These collections can be defined with a filter, and assigning it to a variable name to use.
     424
     425{{{
     426# syntax for the use-tag is:
     427#  use <entity> with <filter> as <variable name>
     428{% use network with 'name=lisa consoles' as net_consoles %}
     429{% use interface with 'network__name=lisa consoles' as ifaces_consoles %}
     430}}}
     431
     432In the example two collections are assigned to a variable:
     433 * `net_consoles` will contain the network with the name ''lisa consoles''
     434 * `ifaces_consoles` will contain all interfaces in that network
     435
     436Now these collections can be used in the template, to build a part of a DHCP config-file for example:
     437
     438{{{
     439group { # Start Console network
     440    option domain-name "{{net_consoles.domain}}";
     441
     442    {% for iface in ifaces_consoles %}
     443    {% if iface.hwaddress != None %}
     444    host {{iface.fqdn}} {
     445        hardware ethernet {{iface.hwaddress}};
     446        fixed-address {{iface.ip}};
     447        option host-name "{{iface.fqdn}}";
     448    }
     449    {% endif %}
     450    {% endfor %}
     451} # End Console network
     452}}}
     453
     454
     455== Set a path to write the output to ==
     456
     457To save the result of your template, you can store the output to a file.
     458This can be done by using the ''store''-tag, and give it a path:
     459{{{
     460# syntax for the store-tag is:
     461#  store <outputpath>  as output
     462{% store /etc/dhcp/dhcpd.conf as output %}
     463}}}
     464
     465In this example the result will be written to `/etc/dhcp/dhcp.conf`.