main.py 文件源码

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

项目:charm-glusterfs 作者: openstack 项目源码 文件源码
def server_connected(peer) -> None:
    """
    The peer.available state is set when there are one or more peer units
    that have joined.
    :return:
    """
    update_status()
    bricks = check_for_new_devices()
    if bricks.is_ok():
        log('Reporting my bricks {} to the leader'.format(bricks.value))
        peer.set_bricks(bricks=bricks.value)
    if not is_leader():
        log('Reporting my public address {} to the leader'.format(
            unit_public_ip()))
        peer.set_address(address_type='public', address=unit_public_ip())
        return

    # I am the leader
    log('Leader probing peers')
    probed_units = []
    try:
        p = hookenv.leader_get('probed-units')
        if p:
            probed_units = json.loads(p)
    except json.decoder.JSONDecodeError as e:
        log("json decoder failed for {}: {}".format(e.doc, e.msg))

    log("probed_units: {}".format(probed_units))
    peer_info = peer.get_peer_info()
    for unit in peer_info:
        if unit in probed_units:
            continue
        address = peer_info[unit]['address']
        log('probing host {} at {}'.format(unit, address))
        status_set('maintenance', 'Probing peer {}'.format(unit))
        try:
            peer_probe(address)
            probed_units.append(unit)
        except (GlusterCmdException, GlusterCmdOutputParseError):
            log('Error probing host {}: {}'.format(unit, address), ERROR)
            continue
        log('successfully probed {}: {}'.format(unit, address), DEBUG)
    settings = {'probed-units': json.dumps(probed_units)}
    hookenv.leader_set(settings)
    status_set('maintenance', '')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号