context.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:charm-helpers 作者: juju 项目源码 文件源码
def __init__(self, relid):
        remote_units = hookenv.related_units(relid)
        remote_units.sort(key=lambda u: int(u.split('/', 1)[-1]))
        super(Relation, self).__init__((unit, RelationInfo(relid, unit))
                                       for unit in remote_units)

        self.relname = relid.split(':', 1)[0]
        self.relid = relid
        self.local = RelationInfo(relid, hookenv.local_unit())

        for relinfo in self.values():
            self.service = relinfo.service
            break

        # If we have peers, and they have joined both the provided peer
        # relation and this relation, we can peek at their data too.
        # This is useful for creating consensus without leadership.
        peer_relid = hookenv.peer_relation_id()
        if peer_relid and peer_relid != relid:
            peers = hookenv.related_units(peer_relid)
            if peers:
                peers.sort(key=lambda u: int(u.split('/', 1)[-1]))
                self.peers = OrderedDict((peer, RelationInfo(relid, peer))
                                         for peer in peers)
            else:
                self.peers = OrderedDict()
        else:
            self.peers = None
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号