Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accessing the UUID of a config item in templates #2664

Closed
ndejong opened this issue Aug 22, 2018 · 3 comments
Closed

Accessing the UUID of a config item in templates #2664

ndejong opened this issue Aug 22, 2018 · 3 comments
Assignees

Comments

@ndejong
Copy link
Contributor

ndejong commented Aug 22, 2018

I started a discussion in the forum with the same subject but I think I need to move this one here to discuss the code in more detail.

My goal is to implement a template helper function called getUUIDs() to facilitate being able to write the following template style:-

{% 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 %}

Following the code, I observe that the special __uuid_tags__ attribute that is populated via this code

self.__uuid_tags[item.attrib['uuid']] = item.tag

... and this code provides data in the helper that looks like this

  "__uuid_tags__": {
    "8a777695-656c-497e-ba31-3e9301edb15f": "alert",
    "4a0bab44-cd2d-485a-8d07-75967c8e521f": "key",
    "c467f1c4-375b-4be1-987a-e52a07dd6de1": "tunnel",
...

The "thing" about this is that the tag-name value (ie, "alert", "key", "tunnel") only provide the last part of the item tag-path which means it is impossible to select all UUIDs that belong to a given full-tag without the risk of collecting tags from different plugins that happen to have the same name.

Is there actually any straight-forward way to resolve this? I imagine that the flow on effects of expanding the tag value to include the full tag-path would create a whole set of new issues elsewhere.

  "__uuid_tags__": {
    "8a777695-656c-497e-ba31-3e9301edb15f": "OPNsense.monit.general.alert",
    "4a0bab44-cd2d-485a-8d07-75967c8e521f": "VerbNetworks.autossh.keys.key",
    "c467f1c4-375b-4be1-987a-e52a07dd6de1": "VerbNetworks.autossh.tunnels.tunnel",
...

@AdSchellevis - I'm figuring this question is for you.

@AdSchellevis
Copy link
Member

@ndejong I think we should just add the attributes to the items, so you could point to something like {{tunnel.__uuid__}} I'll take a look at this when I can.

@AdSchellevis AdSchellevis self-assigned this Aug 22, 2018
@AdSchellevis
Copy link
Member

for reference, same content as in the pull request :

this 3add6c7 should do the trick.

To use a uuid, just use something similar to:

  {{item['@uuid']}}

@ndejong
Copy link
Contributor Author

ndejong commented Aug 26, 2018

Thanks @AdSchellevis

@ndejong ndejong closed this as completed Aug 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants