Get number of units

Tom Barber tom at analytical-labs.com
Wed Mar 2 22:46:07 UTC 2016


Personally for command line stuff, I like the juju cheatsheet on github. It
would be good to have something similar for tips and tricks then its
relatively relaxed and easy to get new submissions in from outside.

--------------

Director Meteorite.bi - Saiku Analytics Founder
Tel: +44(0)5603641316

(Thanks to the Saiku community we reached our Kickstart
<http://kickstarter.com/projects/2117053714/saiku-reporting-interactive-report-designer/>
goal, but you can always help by sponsoring the project
<http://www.meteorite.bi/products/saiku/sponsorship>)

On 2 March 2016 at 17:56, Charles Butler <charles.butler at canonical.com>
wrote:

> Nice, I like this. +1 Marco
>
> If we have a "tips and tricks" page or charmer snippets, this should live
> there.
>
>
> Charles Butler <charles.butler at canonical.com> - Juju Charmer
> Come see the future of modeling your datacenter: http://jujucharms.com
>
> On Wed, Mar 2, 2016 at 6:45 AM, Marco Ceppi <marco.ceppi at canonical.com>
> wrote:
>
>> To answer your question anyways, you can do this with the peers relation:
>>
>> ``` metadata.yaml
>> peers:
>>     cluster:
>>         interface: my-service-cluster
>> ```
>>
>> So, at anytime, in any hook you can do the following:
>>
>> ``` bash
>> rid=$(relation-ids cluster)
>> for unit in $(relation-list -r $rid); do
>>     echo "It's a  peer and confidant $unit"
>> done
>> ```
>>
>> However, since Juju gives unique numbers for each unit, you could use a
>> units number to enumerate a port. You wouldn't need the peer relationship
>> for this directly. As an example
>>
>> ``` bash
>> port_start=4000
>> port=$(expr $port_start + ${JUJU_UNIT_NAME##*/})
>> ```
>>
>> So if it's unit/0 you'll get 4000, if it's unit/10 you'll get 4010, etc.
>> Since unit numbers are unique in Juju you'll never get a conflict.
>>
>> Marco Ceppi
>>
>> On Wed, Mar 2, 2016 at 6:29 AM Tom Barber <tom at analytical-labs.com>
>> wrote:
>>
>>> Scrap that, I have an alternative solution!
>>>
>>> --------------
>>>
>>> Director Meteorite.bi - Saiku Analytics Founder
>>> Tel: +44(0)5603641316
>>>
>>> (Thanks to the Saiku community we reached our Kickstart
>>> <http://kickstarter.com/projects/2117053714/saiku-reporting-interactive-report-designer/>
>>> goal, but you can always help by sponsoring the project
>>> <http://www.meteorite.bi/products/saiku/sponsorship>)
>>>
>>> On 2 March 2016 at 11:22, Tom Barber <tom at analytical-labs.com> wrote:
>>>
>>>> Morning
>>>>
>>>> I need to open an extra port for each unit in my charm, can I ask juju
>>>> for a count of running units in a service?
>>>>
>>>> Thanks
>>>>
>>>> Tom
>>>>
>>>
>>> --
>>> Juju mailing list
>>> Juju at lists.ubuntu.com
>>> Modify settings or unsubscribe at:
>>> https://lists.ubuntu.com/mailman/listinfo/juju
>>>
>>
>> --
>> Juju mailing list
>> Juju at lists.ubuntu.com
>> Modify settings or unsubscribe at:
>> https://lists.ubuntu.com/mailman/listinfo/juju
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/juju/attachments/20160302/6d91a47f/attachment.html>


More information about the Juju mailing list