File: health.py

package info (click to toggle)
python-hvac 2.3.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,800 kB
  • sloc: python: 29,360; makefile: 42; sh: 14
file content (83 lines) | stat: -rw-r--r-- 3,310 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env python
"""Support for "Health"-related System Backend Methods."""
from hvac import exceptions, utils
from hvac.api.system_backend.system_backend_mixin import SystemBackendMixin


class Health(SystemBackendMixin):
    """.

    Reference: https://www.vaultproject.io/api-docs/system/health
    """

    def read_health_status(
        self,
        standby_ok=None,
        active_code=None,
        standby_code=None,
        dr_secondary_code=None,
        performance_standby_code=None,
        sealed_code=None,
        uninit_code=None,
        method="HEAD",
    ):
        """Read the health status of Vault.

        This matches the semantics of a Consul HTTP health check and provides a simple way to monitor the health of a
        Vault instance.


        :param standby_ok: Specifies if being a standby should still return the active status code instead of the
            standby status code. This is useful when Vault is behind a non-configurable load balance that just wants a
            200-level response.
        :type standby_ok: bool
        :param active_code: The status code that should be returned for an active node.
        :type active_code: int
        :param standby_code: Specifies the status code that should be returned for a standby node.
        :type standby_code: int
        :param dr_secondary_code: Specifies the status code that should be returned for a DR secondary node.
        :type dr_secondary_code: int
        :param performance_standby_code: Specifies the status code that should be returned for a performance standby
            node.
        :type performance_standby_code: int
        :param sealed_code: Specifies the status code that should be returned for a sealed node.
        :type sealed_code: int
        :param uninit_code: Specifies the status code that should be returned for a uninitialized node.
        :type uninit_code: int
        :param method: Supported methods:
            HEAD: /sys/health. Produces: 000 (empty body)
            GET: /sys/health. Produces: 000 application/json
        :type method: str | unicode
        :return: The JSON response of the request.
        :rtype: requests.Response
        """
        params = utils.remove_nones(
            {
                "standbyok": standby_ok,
                "activecode": active_code,
                "standbycode": standby_code,
                "drsecondarycode": dr_secondary_code,
                "performancestandbycode": performance_standby_code,
                "sealedcode": sealed_code,
                "uninitcode": uninit_code,
            }
        )

        if method == "HEAD":
            api_path = utils.format_url("/v1/sys/health")
            return self._adapter.head(
                url=api_path,
                raise_exception=False,
            )
        elif method == "GET":
            api_path = utils.format_url("/v1/sys/health")
            return self._adapter.get(
                url=api_path,
                params=params,
                raise_exception=False,
            )
        else:
            error_message = '"method" parameter provided invalid value; HEAD or GET allowed, "{method}" provided'.format(
                method=method
            )
            raise exceptions.ParamValidationError(error_message)