patroni.scripts.barman.utils module

Utilitary stuff to be used by Barman related scripts.

_exception _patroni.scripts.barman.utils.ApiNotOk View on GitHub

Bases: Exception + The pg-backup-api is not currently up and running.

class _patroni.scripts.barman.utils.OperationStatus(_value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None) View on GitHub

Bases: IntEnum + Possible status of pg-backup-api operations. +

Variables:

+

DONE_ = 2_

+

FAILED_ = 1_

+

IN_PROGRESS_ = 0_
class _patroni.scripts.barman.utils.PgBackupApi(_api_url: str, cert_file: str | None, key_file: str | None, retry_wait: int, max_retries: int) View on GitHub

Bases: object + Facilities for communicating with the pg-backup-api. +

Variables:

+

__init\\__(api_url: str, cert_file: str | None, key_file: str | None, retry_wait: int, max_retries: int) → None View on GitHub

Create a new instance of BarmanRecover. + Make sure the pg-backup-api is reachable and running fine. + Note

When using any method which send requests to the API, be aware that they might raise link:#patroni.scripts.barman.utils.RetriesExceeded[`+RetriesExceeded+`] upon HTTP request errors.
  Similarly, when instantiating this class you may face an link:#patroni.scripts.barman.utils.ApiNotOk[`+ApiNotOk+`], if the API is down or returns a bogus status.
  +
  Parameters:::
+
build_full_url(_url_path: str) → str View on GitHub

Build the full URL by concatenating url_path with the base URL. +

Parameters

url_path – path to be accessed in the pg-backup-api.

Returns

the full URL after concatenating. +

static \\__deserialize_response(_response: HTTPResponse) → Any View on GitHub

Retrieve body from response as a deserialized JSON object. +

Parameters

response – response from which JSON body will be deserialized.

Returns

the deserialized JSON body. +

_ensure_api_ok() → None View on GitHub

Ensure pg-backup-api is reachable and OK. +

Raises

ApiNotOk: if pg-backup-api status is not OK. +

get_request(_url_path: str) → Any View on GitHub

Perform a GET request to url_path. +

Parameters

url_path – URL to perform the GET request against.

Returns

the deserialized response body.

Raises
RetriesExceeded: raised from the corresponding urllib3

exception. +

post_request(_url_path: str, body: Any) → Any View on GitHub

Perform a POST request to url_path serializing body as JSON. +

Parameters
Returns

the deserialized response body.

Raises
RetriesExceeded: raised from the corresponding urllib3

exception. +

static \\__serialize_request(_body: Any) → Any View on GitHub

Serialize a request body. +

Parameters

body – content of the request body to be serialized.

Returns

the serialized request body. +

create_config_switch_operation(*args: Any, **kwargs: Any) → Any View on GitHub

+

create_recovery_operation(*args: Any, **kwargs: Any) → Any View on GitHub

+

get_operation_status(*args: Any, **kwargs: Any) → Any View on GitHub
_exception _patroni.scripts.barman.utils.RetriesExceeded View on GitHub

Bases: Exception + Maximum number of retries exceeded.

patroni.scripts.barman.utils.retry(exceptions: Type[ Exception] | Tuple[ Type[ Exception], …​]) → Any View on GitHub

Retry an operation n times if expected exceptions are faced. + Note

Should be used as a decorator of a class’ method as it expects the first argument to be a class instance.
The class which method is going to be decorated should contain a couple attributes:
+
Parameters:;;
  *exceptions* – exceptions that could trigger a retry attempt.
Raises:;;
RetriesExceeded: if the maximum number of attempts has been

exhausted.

patroni.scripts.barman.utils.set_up_logging(log_file: str | None = None) → None View on GitHub

Set up logging to file, if log_file is given, otherwise to console. +

Parameters:

log_file – file where to log messages, if any.


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

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

Read the Docs v: latest

+ Builds