I am new to Juju and trying to write a charm. I need ip address of all units deployed in a service. I am currently using juju 1.25 And deploying services in openstack

The scenario is:

I have 3 units of wordpress(it has required relation hook files) with

juju deploy -n 3 cs:wordpress

I deployed my charm from local repo

juju deploy local:trusty/myCharm

I add relation between the two

juju add-relation myCharm wordpress

Now, I need list of all 3 ip addresses of wordpress service in one of the hook in myCharm

I set relation-keys in wordpress and tried using relation-ids -> relation-list -> relation-get hook tools in myCharm. But it gives me just one ip and not all three.

relation-ids {relationName}  --gives one id. 
relation-list -r {id} --gives just one unit(wordpress/18). 
relation-get -r {id} {relation-key} {unit} --gives corresponding ip.

What should I do to get expected result?

share|improve this question
    
Is this a subordinate service? – Marco Ceppi Sep 1 '16 at 22:13

The relation-list -r {id} should return all units in the relation. Perhaps you're only parsing the first (or last) value?

This is what my relation-* output looks like when I have multiple units of one application related to another (in this case, i'm looking at the monitors relation data between nagios and 3 units of nrpe; you probably want to substitute those with myCharm and your 3 units of wordpress):

$ juju run --unit nagios/0 'relation-ids monitors'
monitors:1

$ juju run --unit nagios/0 'relation-list -r monitors:1'  
nrpe/0
nrpe/1
nrpe/2

$ juju run --unit nagios/0 'relation-get -r monitors:1 private-address nrpe/0'
172.31.13.216

I can put that all together in a loop that outputs the private-address for all units related to nagios like this:

$ juju run --unit nagios/0 'for i in `relation-ids monitors`; do for j in `relation-list -r $i`; do relation-get -r $i private-address $j; done; done'
172.31.13.216
172.31.30.157
172.31.49.121
share|improve this answer
    
Thanks a lot. But this is exactly what I am doing. I also checked it in debug mode. But the relation-list command is giving me just one unit instead of 3. Is it anything to do with the JUJU version? – mayuri Aug 9 '16 at 17:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.