consul.api.operator module¶
- class consul.api.operator.AutopilotHealth[source]¶
Bases:
TypedDict- Servers: builtins.list[AutopilotServerHealth]¶
- class consul.api.operator.UsageResponse[source]¶
Bases:
TypedDict- Usage: dict[str, UsageDatacenter]¶
- class consul.api.operator.Operator(agent)[source]¶
Bases:
object- raft_remove_peer(address=None, peer_id=None, token=None)[source]¶
Removes the Consul server with given address or ID from the Raft configuration. Requires a token with operator:write capability.
Exactly one of address or peer_id should be supplied, per Consul’s raft/peer API. :param address: The address (host:port) of the peer to remove. :param peer_id: The ID of the peer to remove. :param token: token with operator:write capability :return: True if the request succeeded
- raft_transfer_leader(peer_id=None, token=None)[source]¶
Transfers Raft leadership away from the current leader to another peer. Requires a token with operator:write capability. :param peer_id: Optional node ID of the peer to transfer leadership
to. If not specified, Consul selects a peer at random.
- autopilot_configuration(token=None, dc=None)[source]¶
Returns the current Autopilot configuration. Requires a token with operator:read capability. :param token: token with operator:read capability :param dc: Optional datacenter to target; defaults to the client’s own dc. :return: the Autopilot configuration
- Parameters:
- Return type:
- update_autopilot_configuration(cleanup_dead_servers=None, last_contact_threshold=None, max_trailing_logs=None, min_quorum=None, server_stabilization_time=None, redundancy_zone_tag=None, disable_upgrade_migration=None, upgrade_version_tag=None, cas=None, token=None, dc=None)[source]¶
Updates the Autopilot configuration. Requires a token with operator:write capability. :param cleanup_dead_servers: Optional, whether to remove dead servers
from the Raft peer list when a new server joins.
- Parameters:
last_contact_threshold (str | None) – Optional duration, e.g. “200ms”.
max_trailing_logs (int | None) – Optional maximum number of log entries a server can trail the leader by before being considered unhealthy.
min_quorum (int | None) – Optional minimum number of servers to maintain before autopilot allows a dead server to be removed.
server_stabilization_time (str | None) – Optional duration, e.g. “10s”.
redundancy_zone_tag (str | None) – Optional -autopilot-redundancy-zone-tag value.
disable_upgrade_migration (bool | None) – Optional, disables Autopilot’s upgrade migration strategy.
upgrade_version_tag (str | None) – Optional tag used to override the version used during a migration.
cas (int | None) – Optional Autopilot ModifyIndex to check-and-set against; the write only applies if it still matches the current configuration’s ModifyIndex. Consul always replies with HTTP 200 here, encoding the actual success/failure of the cas as a JSON boolean body, hence the CB.json() callback below rather than CB.boolean() (which only looks at the status code).
token (str | None) – token with operator:write capability
dc (str | None) – Optional datacenter to target; defaults to the client’s own dc.
cleanup_dead_servers (bool | None)
- Returns:
True if the update was applied. When cas is supplied and does not match the current ModifyIndex, False is returned instead of raising an error.
- Return type:
- autopilot_health(token=None, dc=None)[source]¶
Returns the current health of the servers, as tracked by Autopilot. Requires a token with operator:read capability.
Consul responds with HTTP 200 when the cluster is healthy and HTTP 429 when it is not; both responses carry the same JSON body shape, distinguished by the “Healthy” field, so neither raises an exception. :param token: token with operator:read capability :param dc: Optional datacenter to target; defaults to the client’s own dc. :return: the Autopilot health snapshot
- Parameters:
- Return type:
- keyring_list(relay_factor=None, local_only=None, token=None)[source]¶
Lists the gossip encryption keys installed on every member of the WAN and LAN rings. Requires a token with keyring:read capability. :param relay_factor: Optional number of extra nodes to relay the
response through, between 0 and 5.
- Parameters:
- Returns:
a list of key/ring status entries, one per WAN/LAN ring
- Return type:
builtins.list[KeyringResponse]
- keyring_install(key, relay_factor=None, token=None)[source]¶
Installs a new gossip encryption key onto every member of the WAN and LAN rings. Requires a token with keyring:write capability. :param key: The base64-encoded gossip encryption key to install. :param relay_factor: Optional number of extra nodes to relay the
request through, between 0 and 5.
- keyring_use(key, relay_factor=None, token=None)[source]¶
Changes the primary gossip encryption key used on every member of the WAN and LAN rings. The key must already be installed before it can be used as the primary key. Requires a token with keyring:write capability. :param key: The base64-encoded gossip encryption key to use as primary. :param relay_factor: Optional number of extra nodes to relay the
request through, between 0 and 5.
- keyring_remove(key, relay_factor=None, token=None)[source]¶
Removes a gossip encryption key from every member of the WAN and LAN rings. Requires a token with keyring:write capability. :param key: The base64-encoded gossip encryption key to remove. :param relay_factor: Optional number of extra nodes to relay the
request through, between 0 and 5.
- usage(global_=None, stale=None, token=None)[source]¶
Returns key metrics about the cluster, such as the number of services, service instances, and nodes. Requires a token with operator:read capability. :param global_: Optional, if True, returns usage information for
all known datacenters instead of just the client’s own dc.
- Parameters:
- Returns:
cluster usage statistics
- Return type: