Why is unit id mandatory in config-changed context?

Gustavo Niemeyer gustavo at niemeyer.net
Fri May 31 23:42:18 UTC 2013


On Fri, May 31, 2013 at 8:14 PM, Andreas Hasenack <andreas at canonical.com> wrote:
> On Fri, May 31, 2013 at 7:50 PM, Gustavo Niemeyer <gustavo at niemeyer.net>
> wrote:
>>
>> On Fri, May 31, 2013 at 6:46 PM, Andreas Hasenack <andreas at canonical.com>
>> wrote:
>> > while playing with hooks I reached this bit in a config-changed hook:
>> (...)
>> > Why do I need to specify the unit id when I have the relation id
>> > already?
>>
>> A single relation can have multiple units, and since you are in a
>> config-changed context, there's no implicit hint about which remote
>> unit you're talking about.
>>
>
> But aren't the key-value pairs that I set in the relation the same for all
> units?

Yes, because it is associated with the local unit. It's similar to the
following scheme:

relation R1:
    unit U1:
          setting S1=V1
          setting S2=V2
    unit U2:
          setting S1=V3
          setting S2=V4
          setting S3=V5
    unit U3:
          setting S1=V6

If U1 does relation-set S1=V1, it sets its own S1 setting to V1. If it
does relation-get S1, it obtains S1 for a specific remote unit. When
the hook is executed as a side-effect of a change in a remote unit
(for example, it joined), relation-get will default to obtaining
settings for the given unit. This means that in most case you don't
really have to know about all of this.. it just works.

But, if you're in a context where there's no known unit being
addressed, such as config-changed, you have to identify whose settings
you're talking about.


gustavo @ http://niemeyer.net



More information about the Juju mailing list