# 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(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)

  Bases: `IntEnum`

  Possible 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-api`

    - INVALID_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-switch` command.

  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-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.

    - reset – `True` 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: 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`.