consul.api.operator module

class consul.api.operator.AutopilotConfiguration[source]

Bases: TypedDict

CleanupDeadServers: bool
LastContactThreshold: str
MaxTrailingLogs: int
MinQuorum: int
ServerStabilizationTime: str
RedundancyZoneTag: str
DisableUpgradeMigration: bool
UpgradeVersionTag: str
CreateIndex: int
ModifyIndex: int
class consul.api.operator.AutopilotServerHealth[source]

Bases: TypedDict

ID: str
Name: str
Address: str
SerfStatus: str
Version: str
Leader: bool
LastContact: str
LastTerm: int
LastIndex: int
Healthy: bool
Voter: bool
StableSince: str
class consul.api.operator.AutopilotHealth[source]

Bases: TypedDict

Healthy: bool
FailureTolerance: int
Servers: builtins.list[AutopilotServerHealth]
class consul.api.operator.KeyringResponse[source]

Bases: TypedDict

WAN: bool
Datacenter: str
Segment: str
Keys: dict[str, int]
PrimaryKeys: dict[str, int]
NumNodes: int
class consul.api.operator.UsageDatacenter[source]

Bases: TypedDict

Services: int
ServiceInstances: int
ConnectServiceInstances: dict[str, int]
BillableServiceInstances: int
Nodes: int
class consul.api.operator.UsageResponse[source]

Bases: TypedDict

Usage: dict[str, UsageDatacenter]
Index: int
LastContact: int
KnownLeader: bool
ConsistencyLevel: str
NotModified: bool
Backend: int
ResultsFilteredByACLs: bool
class consul.api.operator.Operator(agent)[source]

Bases: object

raft_config()[source]

Returns raft configuration.

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

Parameters:
  • address (str | None)

  • peer_id (str | None)

  • token (str | None)

Return type:

bool

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.

Parameters:
  • token (str | None) – token with operator:write capability

  • peer_id (str | None)

Returns:

True if the request succeeded

Return type:

bool

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:
  • token (str | None)

  • dc (str | None)

Return type:

AutopilotConfiguration

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:

bool

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:
  • token (str | None)

  • dc (str | None)

Return type:

AutopilotHealth

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:
  • local_only (bool | None) – Optional, if True, restricts the response to queries against the local datacenter’s LAN ring only.

  • token (str | None) – token with keyring:read capability

  • relay_factor (int | None)

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.

Parameters:
  • token (str | None) – token with keyring:write capability

  • key (str)

  • relay_factor (int | None)

Returns:

True if the request succeeded

Return type:

bool

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.

Parameters:
  • token (str | None) – token with keyring:write capability

  • key (str)

  • relay_factor (int | None)

Returns:

True if the request succeeded

Return type:

bool

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.

Parameters:
  • token (str | None) – token with keyring:write capability

  • key (str)

  • relay_factor (int | None)

Returns:

True if the request succeeded

Return type:

bool

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:
  • stale (bool | None) – Optional, if True, allows reading the data from any server, not just the leader.

  • token (str | None) – token with operator:read capability

  • global_ (bool | None)

Returns:

cluster usage statistics

Return type:

UsageResponse