本文整理汇总了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)