1
Development and Code Review / [SOLVED] Accessing the UUID of a config item in (Jinja2) templates
« on: August 22, 2018, 02:52:03 am »
I'm having a challenge in figuring out out to obtain the UUID of an item when rendering templates - by way of example I have this configuration structure:-
I note the template helper functions `getUUID()` and `getUUIDtag()` in `template_helpers.py` that take a UUID as an input parameter and return data associated with that UUID - this is not what I want despite the `getUUID()` function having a correct sounding name.
What (I think) I want to write is something like the following:-
In a maybe-perfect world it might be nice if you could obtain a list of UUIDs for a tag-name using a helper function that I imagine might be called "getUUIDs()"
Before I set about trying to write and introduce such a new helper function is there another way of achieving what I'm setting out to do here?
Code: [Select]
<VerbNetworks>
<autossh version="0.1.0">
<tunnels>
<tunnel uuid="490829b9-f1b0-42ad-8dad-182de0c06afb">
<user>myuser</name>
<host>panic.verbnetworks.com</type>
</tunnel>
</tunnels>
</autossh>
</VerbNetworks>
I note the template helper functions `getUUID()` and `getUUIDtag()` in `template_helpers.py` that take a UUID as an input parameter and return data associated with that UUID - this is not what I want despite the `getUUID()` function having a correct sounding name.
What (I think) I want to write is something like the following:-
Code: [Select]
{% for tunnel_uuid, tunnel_item in 'VerbNetworks.autossh.tunnels.tunnel'.iteritems() %}
[autossh_{{ tunnel_uuid }}]
{% endfor %}
It is not clear to me how to write or express the tag-name that gets passed to `.iteritems()` and thus the above code fails.In a maybe-perfect world it might be nice if you could obtain a list of UUIDs for a tag-name using a helper function that I imagine might be called "getUUIDs()"
Code: [Select]
{% for tunnel_uuid in helpers.getUUIDs('VerbNetworks.autossh.tunnels.tunnel') %}
{% set tunnel = helpers.getUUID(tunnel_uuid) %}
Host {{ tunnel_uuid }}
User {{ tunnel.user }}
HostName {{ tunnel.host }}
{% endfor %}
Before I set about trying to write and introduce such a new helper function is there another way of achieving what I'm setting out to do here?