How to access model information from juju actions or hooks

I’m trying to implement a juju action that will send a mail to the “admins” of a juju model.

I’m not sure how to query for model information in Juju actions. Any helpers here?

Also, a hint as how to access unit information from actions would be nice to know.

I’m using simple bash since this should work also on centos.

@timClicks do you have any suggestions here? I think this ability to pull out model metadata would be useful for charm writing in general really. For example, fetching proxy settings, default series, users, etc. I’ve been missing this capability for a while really since the hook-tools are very bare bone…

@jamesbeedy suggested looking at libjuju using agent.conf to be able to interact. However, that wouldnt work with script languages like bash I take it or am I wrong?

@wallyworld and @jameinel might jump in and correct me here, but my first thought when reading this is “that’s useful!” and my second thought is that the charm probably shouldn’t know or care about juju details like who is the model admin.

I think the “right” thing to do here is set a juju status, and then have the model’s admin watch for that status. (Or, alternately, deploy a charmed LMA stack, and handle the alerting there.)

I don’t believe that there is currently a way to get at the data that you want to get at from within an action.

In the past, there’s been discussions about constructing a curated view of the model and having that available on request when executing a hook. A charm already has access to charm config, relation data, network information. But maybe if a charm is responsible for managing an application stack it might need to see what’s happening with other applications also, for example. This is not something for this current cycle though.

For the question about model admins, that sounds like it could be done as simply charm config. Right now, there’s quite limited options available other than to manually set a scalar value. There’s been requests to implement a richer config schema, including things like secrets, collections etc; we’re sort of waiting to see what happens in the snap world first so we can pick up what’s done there. It might be worth considering the idea of a “derived” config attribute based on a script or formula, eg @model.users(acl=admin).email. But there’s no immediate plans in this area.

To get unit information from an action, are you talking about being able to run hook commands like config-get or relation-get? Juju creates a “/usr/bin/juju-run” on the host machine which allows an script to execute inside a hook context, and thus call any hook command just as a hook would.

eg from a ssh session on a machine

juju-run mariadb/0 config-get

2 Likes

Thanks for informing me about the current situation. It’s very valuable.

I’m ber much after a means to achieve something like this:

@jamesbeedy suggested using libjuju, which would seem like me only option except having config in the charm which is not what I want. Models might change or add users outside of the charm at which point a config value will be invalid if it’s mapped to the model let’s say ‘admin@external’