patroni.scripts.barman.config_switch module

Implements patroni_barman config-switch sub-command.

Apply a Barman configuration model through pg-backup-api.

This sub-command is specially useful as a on_role_change callback to change Barman configuration in response to failovers and switchovers. Check the output of --help to understand the parameters supported by the sub-command.

It requires that you have previously configured a Barman server and Barman config models, and that you have pg-backup-api configured and running in the same host as Barman.

Refer to ExitCode for possible exit codes of this sub-command.

class patroni.scripts.barman.config_switch.ExitCode

Bases: enum.IntEnum

Possible exit codes of this script.

Variables:
CONFIG_SWITCH_DONE = 0
CONFIG_SWITCH_FAILED = 2
CONFIG_SWITCH_SKIPPED = 1
HTTP_ERROR = 3
INVALID_ARGS = 4
patroni.scripts.barman.config_switch._should_skip_switch(args: argparse.Namespace) → bool

Check if we should skip the config switch operation.

Parameters:args – arguments received from the command-line of patroni_barman config-switch command.
Returns:if the operation should be skipped.
patroni.scripts.barman.config_switch._switch_config(api: PgBackupApi, barman_server: str, barman_model: Optional[str], reset: Optional[bool]) → int

Switch configuration of Barman server through pg-backup-api.

Note

If requests to pg-backup-api fail recurrently or we face HTTP errors, then exit with ExitCode.HTTP_ERROR.

Parameters:
  • api – a PgBackupApi instance to handle communication with the API.
  • barman_server – name of the Barman server which config is to be switched.
  • barman_model – name of the Barman model to be applied to the server, if any.
  • resetTrue if you would like to unapply the currently active model for the server, if any.
Returns:

the return code to be used when exiting the patroni_barman application. Refer to ExitCode.

patroni.scripts.barman.config_switch.run_barman_config_switch(api: PgBackupApi, args: argparse.Namespace) → int

Run a remote barman config-switch through the pg-backup-api.

Parameters:
  • api – a PgBackupApi instance to handle communication with the API.
  • args – arguments received from the command-line of patroni_barman config-switch command.
Returns:

the return code to be used when exiting the patroni_barman application. Refer to ExitCode.