Changes between Version 32 and Version 33 of Usage/TemplatingDocumentation
- Timestamp:
- 07/10/12 17:44:53 (12 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Usage/TemplatingDocumentation
v32 v33 1 1 [[PageOutline]] 2 2 3 3 4 = The Django Templating Language = 4 5 5 6 CMT utilizes Django's Templating engine to process templates. 6 7 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] 8 For 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 9 10 10 11 = CMT extra templatetags = 11 12 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 %} }}} 13 For Cluster Management purposes, a few extra tags have been added. 14 These extra tags can be used and loaded for your template with the tag: 15 {{{ 16 {% load cmt_client %} 17 }}} 14 18 15 19 Without loading this, you cannot use any of the tags below. 16 20 21 17 22 = Stringfilters = 18 23 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: 24 Stringfilters are functions that can pipe or translate a value into a different one. 25 It's syntax is always through the use of a pipe: 20 26 * {{{ 'string'|<stringfilter> }}} 21 27 * {{{ <variable>|<stringfilter> }}} 22 28 29 23 30 == arpanize == 24 31 25 32 Converts an IP (range) to reversed DNS style ARPA notation 26 33 27 '''Usage''': 28 * {{{ {{ <variable>|arpanize }} }}} 29 30 '''Example's''': 31 * 34 '''Usage''' 35 {{{ 36 {{ <variable>|arpanize }} 37 }}} 38 39 '''Examples''' 32 40 {{{ 33 41 {% assign broadcast = '192.168.1.0' %} … … 35 43 }}} 36 44 37 '''Example output''': 38 * {{{ 1.168.192.in-addr.arpa }}} 45 '''Example output''' 46 {{{ 47 1.168.192.in-addr.arpa 48 }}} 49 39 50 40 51 == base_net == … … 42 53 Converts an IP (range) to it's first 3 octets 43 54 44 '''Usage''': 45 * {{{ {{ <variable>|base_net }} }}} 46 47 '''Example's''': 48 * 55 '''Usage''' 56 {{{ 57 {{ <variable>|base_net }} 58 }}} 59 60 '''Examples''' 49 61 {{{ 50 62 {% assign broadcast = '192.168.1.0' %} … … 52 64 }}} 53 65 54 '''Example output''': 55 * {{{ 192.168.1 }}} 66 '''Example output''' 67 {{{ 68 192.168.1 69 }}} 70 56 71 57 72 == ip_last_digit == 58 73 59 Converts an IP (range) to it's last octet 60 61 '''Usage''': 62 * {{{ {{ <variable>|ip_last_digit }} }}} 63 64 '''Example's''': 65 * 74 Converts an IP (range) to its last octet. 75 76 '''Usage''' 77 {{{ 78 {{ <variable>|ip_last_digit }} 79 }}} 80 81 '''Examples''' 66 82 {{{ 67 83 {% assign myip = '192.168.1.123' %} … … 69 85 }}} 70 86 71 '''Example output''': 72 * {{{ 123 }}} 87 '''Example output''' 88 {{{ 89 123 90 }}} 91 92 73 93 74 94 = Functions = 75 95 76 96 Functions are called with the following syntax: 77 * {{{ {% <function> <arguments> %} }}} 97 {{{ 98 {% <function> <arguments> %} 99 }}} 100 78 101 79 102 == assign == 80 103 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' %} }}} 104 Concatenates 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 91 128 92 129 == getbasenets == … … 94 131 Get list of basenets in a network (name). 95 132 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''' 100 140 101 141 Let's assume "MY ADMIN" network is: 192.168.10.0/23 102 142 103 *104 143 {{{ 105 144 {% getbasenets 'MY ADMIN' as network_basenets %} … … 110 149 }}} 111 150 112 '''Example output''' :113 * 151 '''Example output''' 152 114 153 {{{ 115 154 192.168.10 … … 117 156 }}} 118 157 158 119 159 == getracks == 120 160 121 161 Get list of all racks in a cluster. 122 162 123 '''Usage''': 124 * {{{ {% getracks <cluster> as <listname> %} }}} 125 126 '''Example's''': 163 '''Usage''' 164 165 {{{ 166 {% getracks <cluster> as <listname> %} 167 }}} 168 169 '''Examples''' 127 170 128 171 Let's assume the cluster with name "TINA" consists of 3 racks with the labels: !r1, !r5, !r6 129 172 130 *131 173 {{{ 132 174 {% getracks 'TINA' as tina_racks %} … … 137 179 }}} 138 180 139 '''Example output''' :140 * 181 '''Example output''' 182 141 183 {{{ 142 184 r1 … … 145 187 }}} 146 188 189 147 190 == use == 148 191 149 192 Compilation function to define Querysets for later use. 150 193 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 }}} 159 215 160 216 = Sections = 161 217 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 * 218 Sections are used to indicate the tag will only affect the section contained therein. 219 Sections always have a opening and closing tag and can contain arguments: 220 164 221 {{{ 165 222 {% <section> [arguments] %} … … 169 226 == epilogue == 170 227 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 * 228 Commands to be executed after (epi) the template processing is completed. 229 This 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 184 243 {{{ 185 244 {% epilogue %} … … 194 253 Prevents any blanklines occurring in the resulting output (file). 195 254 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''' 205 266 {{{ 206 267 {% noblanklines %} … … 210 271 {% endnoblanklines %} 211 272 }}} 273 274 212 275 == store == 213 276 214 277 Specifies where to store the resulting output (after template processing). 215 278 216 '''Section start''': 217 * {{{ {% store <filename> %} }}} 218 219 * {{{ <filename> }}} can be: 279 '''Section start''' 280 {{{ 281 {% store <filename> %} 282 }}} 283 284 Where {{{ <filename> }}} can be: 220 285 * variable 221 286 * 'Quoted string' 222 287 223 '''Section end''': 224 225 * {{{ {% endstore %} }}} 226 227 '''Example's''': 228 229 * 288 '''Section end''' 289 290 {{{ 291 {% endstore %} 292 }}} 293 294 '''Examples''' 295 230 296 {{{ 231 297 {% store '/path/to/file' %} … … 233 299 {% endstore %} 234 300 }}} 235 * 301 236 302 {{{ 237 303 {% store variable %}