aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--web/templates/HOWTO.txt30
-rw-r--r--web/templates/switches.txt9
2 files changed, 33 insertions, 6 deletions
diff --git a/web/templates/HOWTO.txt b/web/templates/HOWTO.txt
index de98b6a..ed47926 100644
--- a/web/templates/HOWTO.txt
+++ b/web/templates/HOWTO.txt
@@ -83,6 +83,36 @@ Other worth-while api-endpoints:
- public/switches - All switches
- read/snmp - All SNMP data
+Filters
+=======
+
+Jinja2 uses a number of filters to transform variables. They can be used to
+do anything from upper-case all text to pretty-print JSON objects. They are
+used by piping a variable. For example: options|pprint . This will "pretty
+print" the options-object:
+
+{{ options|pprint }}
+
+See http://jinja.pocoo.org/docs/dev/templates/#builtin-filters for a list
+of available filters.
+
+Loops
+=====
+
+You can easily loop over objects, such as switches, using a for-loop.
+Combine this with the "dictsort" filter to get a sorted list.
+
+{% for switch in objects["public/switches"].switches|dictsort %}
+ Switch {{ loop.index }} is {{ switch[0] }} or {{ switch[1] }} or full version: {{ switch }}
+{% endfor %}
+
+To avoid having to worry about indices of tuples (e.g.: switch[0]), you can
+also use a simpler style:
+
+{% for key, value in objects["public/ping"].switches|dictsort %}
+ Switch {{ loop.index }} is {{ key}} with latency4 of {{ value.latency4 }}ms
+{% endfor %}
+
Work flow
=========
diff --git a/web/templates/switches.txt b/web/templates/switches.txt
index 0cc203b..b710066 100644
--- a/web/templates/switches.txt
+++ b/web/templates/switches.txt
@@ -1,7 +1,4 @@
-{% for switch in objects["public/switches"].switches %}
- {% set mg = objects["read/switches-management"].switches[switch] %}
- {% set s = objects["public/switches"].switches[switch] %}
- {% if mg.subnet4 -%}
- {{ switch }} {{mg.subnet4 }} {{ mg.subnet6 }} {{ mg.mgmt_v4_addr }} {{ mg.mgmt_v6_addr }} {{ mg.traffic_vlan }} {{ s.distro_name }}
- {% endif %}
+{% for (switch, s) in objects["public/switches"].switches|dictsort %}
+ {% set mg = objects["read/switches-management"].switches[switch] -%}
+ {{ switch }} {{mg.subnet4 }} {{ mg.subnet6 }} {{ mg.mgmt_v4_addr }} {{ mg.mgmt_v6_addr }} {{ mg.traffic_vlan }} {{ s.distro_name }}
{% endfor %}