本文整理匯總了Python中charmhelpers.core.hookenv.relation_get方法的典型用法代碼示例。如果您正苦於以下問題:Python hookenv.relation_get方法的具體用法?Python hookenv.relation_get怎麽用?Python hookenv.relation_get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類charmhelpers.core.hookenv
的用法示例。
在下文中一共展示了hookenv.relation_get方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_relation_clear
# 需要導入模塊: from charmhelpers.core import hookenv [as 別名]
# 或者: from charmhelpers.core.hookenv import relation_get [as 別名]
def test_relation_clear(self, local_unit,
relation_get,
relation_set):
local_unit.return_value = 'local-unit'
relation_get.return_value = {
'private-address': '10.5.0.1',
'foo': 'bar',
'public-address': '146.192.45.6'
}
hookenv.relation_clear('relation:1')
relation_get.assert_called_with(rid='relation:1',
unit='local-unit')
relation_set.assert_called_with(
relation_id='relation:1',
**{'private-address': '10.5.0.1',
'foo': None,
'public-address': '146.192.45.6'})
示例2: test_ingress_address
# 需要導入模塊: from charmhelpers.core import hookenv [as 別名]
# 或者: from charmhelpers.core.hookenv import relation_get [as 別名]
def test_ingress_address(self, relation_get):
"""Ensure ingress_address returns the ingress-address when available
and returns the private-address when not.
"""
_with_ingress = {'egress-subnets': '10.5.0.23/32',
'ingress-address': '10.5.0.23',
'private-address': '172.16.5.10'}
_without_ingress = {'private-address': '172.16.5.10'}
# Return the ingress-address
relation_get.return_value = _with_ingress
self.assertEqual(hookenv.ingress_address(rid='test:1', unit='unit/1'),
'10.5.0.23')
relation_get.assert_called_with(rid='test:1', unit='unit/1')
# Return the private-address
relation_get.return_value = _without_ingress
self.assertEqual(hookenv.ingress_address(rid='test:1'),
'172.16.5.10')
示例3: get_data
# 需要導入模塊: from charmhelpers.core import hookenv [as 別名]
# 或者: from charmhelpers.core.hookenv import relation_get [as 別名]
def get_data(self):
"""
Retrieve the relation data for each unit involved in a relation and,
if complete, store it in a list under `self[self.name]`. This
is automatically called when the RelationContext is instantiated.
The units are sorted lexographically first by the service ID, then by
the unit ID. Thus, if an interface has two other services, 'db:1'
and 'db:2', with 'db:1' having two units, 'wordpress/0' and 'wordpress/1',
and 'db:2' having one unit, 'mediawiki/0', all of which have a complete
set of data, the relation data for the units will be stored in the
order: 'wordpress/0', 'wordpress/1', 'mediawiki/0'.
If you only care about a single unit on the relation, you can just
access it as `{{ interface[0]['key'] }}`. However, if you can at all
support multiple units on a relation, you should iterate over the list,
like::
{% for unit in interface -%}
{{ unit['key'] }}{% if not loop.last %},{% endif %}
{%- endfor %}
Note that since all sets of relation data from all related services and
units are in a single list, if you need to know which service or unit a
set of data came from, you'll need to extend this class to preserve
that information.
"""
if not hookenv.relation_ids(self.name):
return
ns = self.setdefault(self.name, [])
for rid in sorted(hookenv.relation_ids(self.name)):
for unit in sorted(hookenv.related_units(rid)):
reldata = hookenv.relation_get(rid=rid, unit=unit)
if self._is_ready(reldata):
ns.append(reldata)