Defining a charm that supports multiple interfaces for the same relationship
Bruno Girin
brunogirin at gmail.com
Tue Nov 6 00:15:49 UTC 2012
On 05/11/12 18:26, Clint Byrum wrote:
> Excerpts from Bruno Girin's message of 2012-11-05 08:23:46 -0800:
>> Hi all,
>>
>> I had a chat with Marco on Thursday about supporting multiple interfaces
>> on the same relationship and we couldn't come to a sensible conclusion
>> (beer may not have helped) so we concluded that we should put the
>> question to the wisdom of the mailing list. Here goes.
>>
>> Use case: say you have a web app that needs to connect to a database and
>> supports either MySQL or PostgreSQL. How should I define that in
>> metadata.yaml and how do I handle it in the relation-changed hook?
>>
>> If I specify this:
>>
>> requires:
>> db1:
>> interface: mysql
>> db2:
>> interface: postgresql
>>
>> it's a bit verbose and does not enforce the fact that I want either db1
>> or db2 but not both. Can I use the same name for both relationships? As in:
>>
>> requires:
>> db:
>> interface: mysql
>> db:
>> interface: postgresql
>>
>> Or even specify several interfaces for the same relationship:
>>
>> requires:
>> db:
>> interface: mysql
>> interface: postgresql
>>
>> Or even better:
>>
>> requires:
>> db:
>> interface: [ mysql, postgresql ]
>>
> None of the solutions presented make it easy for the hook author to
> know which database driver to use. The appropriate solution is like your
> first solution, but with names that make more sense:
>
> requires:
> db-mysql:
> interface: mysql
> db-postgres
> interface: postgresql
>
> This allows you to know, by the name of the hook executable, which
> interface to expect, since you will be in
>
> db-mysql-relation-joined
>
> or
>
> db-postgres-relation-joined
>
> You can even make these symlinks to the same script if you want, because
> argv[0] will still be the name that was executed.
Thanks, I'll have a go at doing it that way.
Bruno
More information about the Juju
mailing list