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(*values)
Bases:
IntEnumPossible exit codes of this script.
- Variables:
CONFIG_SWITCH_DONE – config switch was successfully performed.
CONFIG_SWITCH_SKIPPED – if the execution was skipped because of not matching user expectations.
CONFIG_SWITCH_FAILED – config switch faced an issue.
HTTP_ERROR – an error has occurred while communicating with
pg-backup-apiINVALID_ARGS – an invalid set of arguments has been given to the operation.
- 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: Namespace) bool
Check if we should skip the config switch operation.
- Parameters:
args – arguments received from the command-line of
patroni_barman config-switchcommand.- Returns:
if the operation should be skipped.
- patroni.scripts.barman.config_switch._switch_config(api: PgBackupApi, barman_server: str, barman_model: str | None, reset: bool | None) int
Switch configuration of Barman server through
pg-backup-api.Note
If requests to
pg-backup-apifail recurrently or we face HTTP errors, then exit withExitCode.HTTP_ERROR.- Parameters:
api – a
PgBackupApiinstance 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.
reset –
Trueif 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_barmanapplication. Refer toExitCode.
- patroni.scripts.barman.config_switch.run_barman_config_switch(api: PgBackupApi, args: Namespace) int
Run a remote
barman config-switchthrough thepg-backup-api.- Parameters:
api – a
PgBackupApiinstance to handle communication with the API.args – arguments received from the command-line of
patroni_barman config-switchcommand.
- Returns:
the return code to be used when exiting the
patroni_barmanapplication. Refer toExitCode.