2016-08-04 28 views
0

我是Juju的新手,想寫一些魅力。我需要在服務中部署的所有設備的IP地址。我使用如何獲得Juju魅力服務中所有單位的IP地址?

例如:I有3個單位的WordPress with-- 朱朱的部署-n 3 CS:WordPress的

我部署從本地回購我的魅力 - 朱朱部署本地:值得信賴/ X

我在two--朱朱附加關係X WordPress的

之間添加關係現在,我需要在我的魅力在鉤之一的WordPress服務的所有3個IP地址的列表(X)

我設置的關係,按鍵在wordpress和嘗試使用relati on-ids - >關係列表 - >關係獲取鉤子工具在我的魅力。 但它給我只有一個IP而不是全部三個。

關係 - 給一個id。 關係列表ID - 僅提供一個單元。 relation-get - 給出相應的ip。

我該怎麼做才能得到預期的結果?

回答

0

你可以使用

get_host_ip(unit_get('private-address')

其中get_host_ip可以從charmhelpers

from charmhelpers.contrib.openstack.utils import get_host_ip 

導入到獲得魅力的各單位的IP地址,必須添加對關係的單位地址。您可以從here

1

嘗試這樣的事情瞭解的關係:

from charmhelpers.contrib.openstack.utils import get_host_ip 
from charmhelpers.core.hookenv import (
    relation_ids, 
    related_units, 
    relation_get, 
) 
def _get_ips(rel_name): 
    return [get_host_ip(rdata['private-address']) 
      for rid in relation_ids(rel_name) 
      for rdata in 
      (relation_get(rid=rid, unit=unit) for unit in related_units(rid)) 
      if rdata] 

ips = _get_ips("wordpress") 

關係名,可能是你的情況不同。確認。