Changeset 14130
- Timestamp:
- 03/15/12 15:54:39 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sara_cmt/sara_cmt/cluster/templatetags/cmts_extras.py
r12020 r14130 1 import os 2 import re 1 import os, re, string 3 2 4 3 # Inspired by Django tips on: … … 35 34 return NoBlankLinesNode(nodelist) 36 35 36 @stringfilter 37 def arpanize(value): 38 """ 39 Converts a IP (range) to reversed DNS style arpa notation 40 41 Usage: 42 {{{ <variable>|arpanize }}} 43 44 I.e.: 45 {% assign broadcast = '192.168.1.0' %} 46 {{{ broastcast|arpanize }}} 47 Results in output: 48 1.168.192.in-addr.arpa 49 """ 50 ip_blocks = value.split('.') 51 52 reverse_block = [ ip_blocks[2], ip_blocks[1], ip_blocks[0], 'in-addr.arpa' ] 53 54 return string.join( reverse_block, '.' ) 55 56 register.filter( 'arpanize', arpanize ) 57 58 @stringfilter 59 def base_net(value): 60 """ 61 Converts a IP (range) to it's first 3 octects 62 63 Usage: 64 {{{ <variable>|base_net }}} 65 66 I.e.: 67 {% assign broadcast = '192.168.1.0' %} 68 {{{ broastcast|base_net }}} 69 Results in output: 70 192.168.1 71 """ 72 ip_blocks = value.split('.') 73 74 return string.join( ip_blocks[:3], '.' ) 75 76 register.filter( 'base_net', base_net ) 77 78 @stringfilter 79 def ip_last_digit(value): 80 """ 81 Converts a IP (range) to it's last octect 82 83 Usage: 84 {{{ <variable>|ip_last_digit }}} 85 86 I.e.: 87 {% assign myip = '192.168.1.123' %} 88 {{{ myip|ip_last_digit }}} 89 Results in output: 90 123 91 """ 92 ip_blocks = value.split('.') 93 94 return ip_blocks[3] 95 96 register.filter( 'ip_last_digit', ip_last_digit ) 37 97 38 98 class MetaNode(template.Node):
Note: See TracChangeset
for help on using the changeset viewer.