Catalog¶
-
class
consulate.api.catalog.
Catalog
(uri, adapter, dc=None, token=None)¶ The Consul agent is the core process of Consul. The agent maintains membership information, registers services, runs checks, responds to queries and more. The agent must run on every node that is part of a Consul cluster.
-
deregister
(node, datacenter=None, check_id=None, service_id=None)¶ Directly remove entries in the catalog. It is usually recommended to use the agent local endpoints, as they are simpler and perform anti-entropy.
The behavior of the endpoint depends on what keys are provided. The endpoint requires
node
to be provided, whiledatacenter
will be defaulted to match that of the agent. If onlynode
is provided, then the node, and all associated services and checks are deleted. Ifcheck_id
is provided, only that check belonging to the node is removed. Ifservice_id
is provided, then the service along with it’s associated health check (if any) is removed.Parameters: Return type:
-
node
(node_id)¶ Return the node data for the specified node
Parameters: node_id (str) – The node ID Return type: dict
-
register
(node, address, datacenter=None, service=None, check=None)¶ A a low level mechanism for directly registering or updating entries in the catalog. It is usually recommended to use the agent local endpoints, as they are simpler and perform anti-entropy.
The behavior of the endpoint depends on what keys are provided. The endpoint requires Node and Address to be provided, while Datacenter will be defaulted to match that of the agent. If only those are provided, the endpoint will register the node with the catalog.
If the Service key is provided, then the service will also be registered. If ID is not provided, it will be defaulted to Service. It is mandated that the ID be node-unique. Both Tags and Port can be omitted.
If the Check key is provided, then a health check will also be registered. It is important to remember that this register API is very low level. This manipulates the health check entry, but does not setup a script or TTL to actually update the status. For that behavior, an agent local check should be setup.
The CheckID can be omitted, and will default to the Name. Like before, the CheckID must be node-unique. The Notes is an opaque field that is meant to hold human readable text. If a ServiceID is provided that matches the ID of a service on that node, then the check is treated as a service level health check, instead of a node level health check. Lastly, the status must be one of “unknown”, “passing”, “warning”, or “critical”. The “unknown” status is used to indicate that the initial check has not been performed yet.
It is important to note that Check does not have to be provided with Service and visa-versa. They can be provided or omitted at will.
Example service dict:
'Service': { 'ID': 'redis1', 'Service': 'redis', 'Tags': ['master', 'v1'], 'Port': 8000, }
Example check dict:
'Check': { 'Node': 'foobar', 'CheckID': 'service:redis1', 'Name': 'Redis health check', 'Notes': 'Script based health check', 'Status': 'passing', 'ServiceID': 'redis1' }
Parameters: Return type:
-