patroni.config_generator module

patroni --generate-config machinery.

class _patroni.config_generator.AbstractConfigGenerator(_output_file: str | None) View on GitHub

Bases: ABC + Object representing the generated Patroni config. +

Variables:

+

HOSTNAME = 'build-23994964-project-35122-patroni'_

+

IP = '172.17.0.2'_

+

__init\\__(output_file: str | None) → None View on GitHub

Set up the output file (if passed), helper vars and the minimal config structure. +

Parameters

output_file – full path to the output file to be used. +

abc_impl = <_abc._abc_data object>_

+

static \\__format_block(_block: Any, line_prefix: str = '') → str View on GitHub

Format a single YAML block. + Note

  Optionally the formatted block could be indented with the _line_prefix_
  +
  Parameters:::
  Returns:::
    a formatted and indented _block_.
+
_format_config() → Iterator[ str] View on GitHub

Format current config and enrich it with some comments. +

Yields

formatted lines or blocks that represent a text output of the YAML document. +

format_config_section(_section_name: str) → Iterator[ str] View on GitHub

Format and yield as single section of the current config. + Note

  If the section is a  https://docs.python.org/3/library/stdtypes.html#dict[`+dict+`] object we put an empty line before it.
  +
  Parameters:::
    *section_name* – a section name in the `+config+`.
  Yields:::
    a formatted section in case if it exists in the `+config+`.
+
write_config_to_fd(_fd: TextIO) → None View on GitHub

Format and write current config to provided file descriptor. +

Parameters

fd – where to write the config file. Could be sys.stdout or the real file. +

_abstract _generate() → None View on GitHub

Generate config and store in config. +

_classmethod _get_template_config() → Dict[ str, Any] View on GitHub

Generate a template config for further extension (e.g. in the inherited classes). +

Returns

dictionary with the values gathered from Patroni env, hopefully defined hostname and ip address (otherwise set to NO_VALUE_MSG), and some sane defaults. +

write_config() → None View on GitHub

Write current config to the output file if provided, to stdout otherwise.

class _patroni.config_generator.RunningClusterConfigGenerator(_output_file: str | None = None, dsn: str | None = None) View on GitHub

Bases: AbstractConfigGenerator + Object representing the Patroni config generated using information gathered from the running instance. +

Variables:

+

__init\\__(output_file: str | None = None, dsn: str | None = None) → None View on GitHub

Additionally store the passed dsn (if any) in both original and parsed version and run config generation. +

Parameters
Raises

PatroniException: if DSN parsing failed. +

abc_impl = <_abc._abc_data object>_

+

_enrich_config_from_running_instance() → None View on GitHub

Extend config with the values gathered from the running instance. + Retrieve the following information from the running PostgreSQL instance: + And redefine scope with the cluster_name GUC value if set. +

Raises

PatroniException: if the provided user doesn’t have superuser privileges. +

_get_bin_dir_from_running_instance() → str View on GitHub

Define the directory postgres binaries reside using postmaster’s pid executable. +

Returns

path to the PostgreSQL binaries directory.

Raises

PatroniException: if:
__\\__ __\\__ +

_get_connection_cursor() → Iterator[cursor | Cursor[Any]] View on GitHub

Get cursor for the PG connection established based on the stored information. +

Raises

PatroniException: if psycopg.Error occured. +

property \\__get_hba_conn_types: Tuple[ str, …​]_

Return the connection types allowed. + If pg_major is defined, adds additional parameters for PostgreSQL version >=16. +

Returns

tuple of the connection methods allowed. +

property \\__required_pg_params: List[ str]_

PG configuration prameters that have to be always present in the generated config. +

Returns

list of the parameter names. +

_set_conf_files() → None View on GitHub

Extend config with pg_hba.conf and pg_ident.conf content. + Note

  This function only defines `+postgresql.pg_hba+` and `+postgresql.pg_ident+` when `+hba_file+` and `+ident_file+` are set to the defaults. It may happen these files are located outside of `+PGDATA+` and Patroni doesn’t have write permissions for them.
  +
  Raises:::
    link:patroni.exceptions.html#patroni.exceptions.PatroniException[`+PatroniException+`]: if  https://docs.python.org/3/library/exceptions.html#OSError[`+OSError+`] occured during the conf files handling.
+
set_pg_params(_cur: cursor | Cursor[Any]) → None View on GitHub

Extend config with the actual PG GUCs values. + THe following GUC values are set: + __\\__ __\\__ +

Parameters

cur – connection cursor to use. +

_set_su_params() → None View on GitHub

Extend config with the superuser auth information.
Information set is based on the options used for connection. +

generate() → None View on GitHub

Generate config using the info gathered from the specified running PG instance. + Result is written to config.

class _patroni.config_generator.SampleConfigGenerator(_output_file: str | None) View on GitHub

Bases: AbstractConfigGenerator + Object representing the generated sample Patroni config. + Sane defults are used based on the gathered PG version. +

abc_impl = <_abc._abc_data object>_

+

_get_int_major_version() → int View on GitHub

Get major PostgreSQL version from the binary as an integer. +

Returns

an integer PostgreSQL major version representation gathered from the PostgreSQL binary. See postgres_major_version_to_int() and get_major_version(). +

generate() → None View on GitHub

Generate sample config using some sane defaults and update config. +

property _get_auth_method: str_

Return the preferred authentication method for a specific PG version if provided or the default md5. +

Returns

str value for the preferred authentication method.

patroni.config_generator.generate_config(output_file: str, sample: bool, dsn: str | None) → None View on GitHub

Generate Patroni configuration file. +

Parameters:
patroni.config_generator.get_address() → Tuple[ str, str] View on GitHub

Try to get hostname and the ip address for it returned by gethostname(). + Note

Can also return local ip.
+
Returns:;;
  tuple consisting of the hostname returned by  https://docs.python.org/3/library/socket.html#socket.gethostname[`+gethostname()+`] and the first element in the sorted list of the addresses returned by  https://docs.python.org/3/library/socket.html#socket.getaddrinfo[`+getaddrinfo()+`]. Sorting guarantees it will prefer IPv4. If an exception occured, hostname and ip values are equal to `+NO_VALUE_MSG+`.

© Copyright 2015 Compose, Zalando SE. Revision 9d231aee.

Built with Sphinx using a theme provided by Read the Docs.

Read the Docs v: latest

+ Builds