Exemplo n.º 1
0
def build_connect_parameters(conn_url, connect_parameters):
    params = get_conn_kwargs(conn_url, connect_parameters)
    params.update({
        'fallback_application_name': 'Patroni ctl',
        'connect_timeout': '5'
    })
    if 'database' in connect_parameters:
        params['database'] = connect_parameters['database']
    else:
        params.pop('database')
    return params
Exemplo n.º 2
0
def dsn(cluster_name, config_file, dcs, role, member):
    if role is not None and member is not None:
        raise PatroniCtlException(
            '--role and --member are mutually exclusive options')
    if member is None and role is None:
        role = 'master'

    _, dcs, cluster = ctl_load_config(cluster_name, config_file, dcs)
    m = get_any_member(cluster, role=role, member=member)
    if m is None:
        raise PatroniCtlException('Can not find a suitable member')

    params = get_conn_kwargs(m.conn_url)
    click.echo('host={host} port={port}'.format(**params))
Exemplo n.º 3
0
def output_members(cluster, name, fmt='pretty'):
    rows = []
    logging.debug(cluster)
    leader_name = None
    if cluster.leader:
        leader_name = cluster.leader.member.name

    xlog_location_cluster = cluster.last_leader_operation or 0

    # Mainly for consistent pretty printing and watching we sort the output
    cluster.members.sort(key=lambda x: x.name)
    for m in cluster.members:
        logging.debug(m)

        leader = ''
        if m.name == leader_name:
            leader = '*'

        host = get_conn_kwargs(m.conn_url)['host']

        xlog_location = m.data.get('xlog_location') or 0
        lag = ''
        if (xlog_location_cluster >= xlog_location):
            lag = round((xlog_location_cluster - xlog_location) / 1024 / 1024)

        rows.append([name, m.name, host, leader, m.data.get('state', ''), lag])

    columns = [
        'Cluster',
        'Member',
        'Host',
        'Leader',
        'State',
        'Lag in MB',
    ]
    alignment = {'Cluster': 'l', 'Member': 'l', 'Host': 'l', 'Lag in MB': 'r'}

    print_output(columns, rows, alignment, fmt)