Re: beginner questions
Tavis Rudd <[email protected]> Thu, 18 Mar 2010 13:16:54 -0700 (PDT)
| Newsgroups | gmane.comp.python.cheetah |
|---|---|
| Message-ID | <alpine.LNX.2.00.1003181308400.4878@o3> |
On Thu, 18 Mar 2010, Jonathan Sabo wrote:
> I'm using cheetah templates in Cobbler and I'm just getting started
> with cheetah itself so please forgive my lame and hopefully not to
> annoying questions. Cobbler comes with a dhcpd.conf template and I've
> customized it a bit but I'm not sure there isn't a cleaner way to
> write this code. I want to allow non programmer types to add
> netblocks to this file so it can configure the dhcpd.conf file. I'm
> curious if there are cleaner ways to write this or if this just looks
> retarded?
>
> #set $netblocks = {
> 'NYC' : {
> 'NYC_MANAGEMENT' : { 'NETWORK' : '10.37.40.0',
> 'NETMASK' : '255.255.248.0', 'GATEWAY' : '10.37.40.1' },
> 'NYC_DMZ_MANAGEMENT' : { 'NETWORK' : '10.37.54.0', 'NETMASK' :
> '255.255.255.0', 'GATEWAY' : '10.37.54.1' },
> 'NYC_EXT_MANAGEMENT' : { 'NETWORK' : '10.37.72.0', 'NETMASK' :
> '255.255.248.0', 'GATEWAY' : '10.37.72.1' },
> 'TRUSTED_MANAGEMENT' : { 'NETWORK' : '10.37.86.0', 'NETMASK' :
> '255.255.255.0', 'GATEWAY' : '10.37.86.1' },
> 'UNTRUSTED_MANAGEMENT' : { 'NETWORK' : '10.37.200.0', 'NETMASK' :
> '255.255.248.0', 'GATEWAY' : '10.37.200.1' },
> 'DMZ_MANAGEMENT' : { 'NETWORK' : '10.37.214.0', 'NETMASK' :
> '255.255.255.0', 'GATEWAY' : '10.37.214.1' },
> }
> }
It's probably easier to read if you iterate like this:
#for skey, blockgroup in netblocks.iteritems()
#for nkey, block in blockgroup.iteritems()
# $skey $nkey
subnet $block['NETWORK'] netmask
...
#end for
#end for
The dollar signs are only required in the places I've used them and you
can skip them elsewhere if you wish.
Nice domain name!
Tavis
> #for $skey in $netblocks.keys()
> #for $nkey in $netblocks[skey].keys()
> # $skey $nkey
> subnet $netblocks[skey][nkey]['NETWORK'] netmask
> $netblocks[skey][nkey]['NETMASK'] {
> option routers $netblocks[skey][nkey]['GATEWAY'];
> option subnet-mask $netblocks[skey][nkey]['NETMASK'];
> filename "/pxelinux.0";
> default-lease-time 21600;
> max-lease-time 43200;
> next-server $nextserver;
> }
>
> #end for
> #end for
>
> Thanks,
>
> Jonathan
>
> ------------------------------------------------------------------------------
> Download Intel® Parallel Studio Eval
> Try the new software tools for yourself. Speed compiling, find bugs
> proactively, and fine-tune applications for parallel performance.
> See why Intel Parallel Studio got high marks during beta.
> http://p.sf.net/sfu/intel-sw-dev
> _______________________________________________
> Cheetahtemplate-discuss mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
>
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev