How to check/render output of Mako templates?


Userlevel 2
Now that I'm getting my learnin' on with C.L. I want to step it up a notch by experimenting with Mako templates. Using C.L. 3.1... how do I verify and/or "render" the template to make sure it really did what I wanted it do?

6 replies

Hi Troy:

mako-render is the command.

David
Userlevel 2
so I dropped in a simple mako template (taken from these forums):
<%!from ipaddr import IPAddress
ip = IPAddress('10.1.1.0')
%>

<%def name="incr_ip(ip, count, incr)">
<% newip = ip + (count * incr) %>
address ${newip}/31


% for i in range(1,10):
auto swp${i}
iface swp${i}
${incr_ip(ip, i, 2)}
% endfor

it works, because "ip link show" shows the results. However whenever I try:
cumulus@cumulus$ mako-render
or:
cumulus@cumulus$ sudo mako-render

the cursor moves to the next line and nothing happens...how long is this rendering supposed to take? Seems like it should be nearly instantaneous, right?

You want to run: mako-render

For example, to see how an interfaces file renders: mako-render /etc/network/interfaces

Userlevel 2
Okay, so that worked, thank you! I'm still feeling my way around this environment and ecosystem. So no, I really need some help on syntax. I would like to turn this long hand:
auto downlink1 iface downlink1
bond-slaves swp1 swp2
clag-id 1

auto downlink2
iface downlink2
bond-slaves swp3 swp4
clag-id 2

.
.
.
auto downlink24
iface downlink24
bond-slaves swp47 swp48
clag-id 24

into as short a mako template as possible. I've tried some combos, but either get errors when rendering, or the increments for the switch port numbering does quite come out right.
Here's one way to do it:

%for i in range(1,25):
auto downlink${i}
iface downlink${i}
bond-slaves swp${(i - 1)*2 + 1} swp${(i - 1)*2 + 2}
clag-id ${i}

%endfor
Userlevel 2
Once again, thank you! guess I don't math so well...lol

Reply