コード例 #1
0
def get_clone_envdir():
    from spilo_commons import get_patroni_config

    config = get_patroni_config()
    restore_command = shlex.split(config['bootstrap']['clone_with_wale']
                                  ['recovery_conf']['restore_command'])
    if len(restore_command) > 4 and restore_command[0] == 'envdir':
        return restore_command[1]
    raise Exception('Failed to find clone envdir')
コード例 #2
0
def update_configs(new_version):
    from spilo_commons import append_extensions, get_bin_dir, get_patroni_config, write_file, write_patroni_config

    config = get_patroni_config()

    config['postgresql']['bin_dir'] = get_bin_dir(new_version)

    version = float(new_version)
    shared_preload_libraries = config['postgresql'].get(
        'parameters', {}).get('shared_preload_libraries')
    if shared_preload_libraries is not None:
        config['postgresql']['parameters']['shared_preload_libraries'] =\
                append_extensions(shared_preload_libraries, version)

    extwlist_extensions = config['postgresql'].get(
        'parameters', {}).get('extwlist.extensions')
    if extwlist_extensions is not None:
        config['postgresql']['parameters']['extwlist.extensions'] =\
                append_extensions(extwlist_extensions, version, True)

    write_patroni_config(config, True)

    # update wal-e/wal-g envdir files
    restore_command = shlex.split(config['postgresql'].get(
        'recovery_conf', {}).get('restore_command', ''))
    if len(restore_command) > 6 and restore_command[0] == 'envdir':
        envdir = restore_command[1]

        try:
            for name in os.listdir(envdir):
                # len('WALE__PREFIX') = 12
                if len(name) > 12 and name.endswith(
                        '_PREFIX') and name[:5] in ('WALE_', 'WALG_'):
                    name = os.path.join(envdir, name)
                    try:
                        with open(name) as f:
                            value = f.read().strip()
                        new_value = patch_wale_prefix(value, new_version)
                        if new_value != value:
                            write_file(new_value, name, True)
                    except Exception as e:
                        logger.error('Failed to process %s: %r', name, e)
        except Exception:
            pass
        else:
            return envdir
コード例 #3
0
def get_possible_versions():
    from spilo_commons import LIB_DIR, get_binary_version, get_bin_dir, get_patroni_config

    config = get_patroni_config()

    max_version = float(
        get_binary_version(config.get('postgresql', {}).get('bin_dir')))

    versions = {}

    for d in os.listdir(LIB_DIR):
        try:
            ver = get_binary_version(get_bin_dir(d))
            fver = float(ver)
            if fver <= max_version:
                versions[fver] = ver
        except Exception:
            pass

    # return possible versions in reversed order, i.e. 12, 11, 10, 9.6, and so on
    return [ver for _, ver in sorted(versions.items(), reverse=True)]