def leader_elected():
    '''Set the leader nodes IP'''
    if is_leader():
        leader_set(**{'leader-ip': get_relation_ip('cluster')})
    else:
        log('leader-elected hook executed, but this unit is not the leader',
            level=INFO)
    # NOTE(tkurek): re-set 'master' relation data
    if relation_ids('master'):
        master_joined()
    # NOTE(tkurek): configure new leader
    if relation_ids('slave'):
        configure_slave()
def leader_elected():
    '''Set the leader nodes IP'''
    if is_leader():
        leader_set(**{'leader-ip': get_relation_ip('cluster')})
    else:
        log('leader-elected hook executed, but this unit is not the leader',
            level=INFO)
    # NOTE(tkurek): re-set 'master' relation data
    if relation_ids('master'):
        master_joined()
    # NOTE(tkurek): configure new leader
    if relation_ids('slave'):
        configure_slave()
def slave_joined(interface='slave'):
    relation_settings = {}
    cluster_id = get_cluster_id()
    if not is_clustered():
        log("Not clustered yet", level=DEBUG)
        return
    if is_leader():
        configure_slave()
    relation_settings = {'slave_address':
                         network_get_primary_address(interface)}
    relation_settings['cluster_id'] = cluster_id
    log("Setting slave relation: '{}'".format(relation_settings), level=INFO)
    for rid in relation_ids(interface):
        relation_set(relation_id=rid, relation_settings=relation_settings)
def slave_joined(interface='slave'):
    relation_settings = {}
    cluster_id = get_cluster_id()
    if not is_clustered():
        log("Not clustered yet", level=DEBUG)
        return
    if is_leader():
        configure_slave()
    relation_settings = {'slave_address':
                         network_get_primary_address(interface)}
    relation_settings['cluster_id'] = cluster_id
    log("Setting slave relation: '{}'".format(relation_settings), level=INFO)
    for rid in relation_ids(interface):
        relation_set(relation_id=rid, relation_settings=relation_settings)