Example
import consul
c = consul.Consul()
# poll a key for updates
index = None
while True:
index, data = c.kv.get('foo', index=index)
print data['Value']
# in another process
c.kv.put('foo', 'bar')
Installation
pip install python-consul
Status
There’s a few API endpoints still to go to expose all features available inConsul v0.6.0. If you need an endpoint that’s not in the documentation, justopen an issue and I’ll try and add it straight away.
Releases
# release the current version, eg: 0.6.1-dev -> 0.6.1
bumpversion release
# prepare the next patch (z-stream) version, eg: 0.6.1 -> 0.6.2-dev
bumpversion --no-tag patch
# else, prepare the next minor (y-stream) version, eg: 0.6.1 -> 0.7.0-dev
bumpversion --no-tag minor
Clients
This library is designed to be easily adapted for a number of clients.Particularly asynchronous clients. The following clients are currentlysupported.
Standard
This is a standard blocking python client. It isn’t particularly useful forcreating server components - but it does serve as a base. It makes use of therequests library for http requests.
>>> import consul
>>> c = consul.Consul()
>>> c.kv.put('foo', 'bar')
True
>>> index, data = c.kv.get('foo')
>>> data['Value']
'bar'
# this will block until there's an update or a timeout
>>> index, data = c.kv.get('foo', index=index)
Vanilla
An asynchronous Vanilla plugin based on this library is available at:https://github.com/cablehead/vanilla.consul
gevent
The terribly awful thing about gevent is that anything that uses the socketlibrary from the python standard lib, including the requests library can bemade non-blocking via monkey patching. This means the standard python-consulclient will just work asynchronously with gevent.
Tornado
There is a Tornado client which makes use of gen.coroutine. The API forthis client is identical to the standard python-consul client except that youneed to yield the result of each API call. This client is available inconsul.tornado.
import consul.tornado
class Config(object):
def __init__(self):
self.foo = None
loop.add_callback(self.watch)
@tornado.gen.coroutine
def watch(self):
c = consul.tornado.Consul()
# asynchronously poll for updates
index = None
while True:
index, data = yield c.kv.get('foo', index=index)
self.foo = data['Value']
asyncio
There is a asyncio (using aiohttp) client which works with Python3.4 andmakes use of asyncio.coroutine. The API for this client is identical tothe standard python-consul client except that you need to yield from
theresult of each API call. This client is available in consul.aio.
import asyncio
import consul.aio
loop = asyncio.get_event_loop()
@asyncio.coroutine
def go():
# always better to pass ``loop`` explicitly, but this
# is not mandatory, you can relay on global event loop
c = consul.aio.Consul(port=consul_port, loop=loop)
# set value, same as default api but with ``yield from``
response = yield from c.kv.put(b'foo', b'bar')
assert response is True
# get value
index, data = yield from c.kv.get(b'foo')
assert data['Value'] == b'bar'
# delete value
response = yield from c.kv.delete(b'foo2')
assert response is True
loop.run_until_complete(go())
Wanted
Adaptors for Twisted and a thread pool based adaptor.
Tools
Handy tools built on python-consul.
Example Uses
ACLs
import consul
# master_token is a *management* token, for example the *acl_master_token*
# you started the Consul server with
master = consul.Consul(token=master_token)
master.kv.put('foo', 'bar')
master.kv.put('private/foo', 'bar')
rules = """
key "" {
policy = "read"
}
key "private/" {
policy = "deny"
}
"""
token = master.acl.create(rules=rules)
client = consul.Consul(token=token)
client.kv.get('foo') # OK
client.kv.put('foo', 'bar2') # raises ACLPermissionDenied
client.kv.get('private/foo') # returns None, as though the key doesn't
# exist - slightly unintuitive
client.kv.put('private/foo', 'bar2') # raises ACLPermissionDenied
API Documentation
Check
-
class
-
There are three different kinds of checks: script, http and ttl
consul.
Check
Check.docker
-
classmethod
-
Invoke script packaged within a running docker container withcontainer_id at a specified specified interval on the configuredshell using the Docker Exec API
Check.
docker
(
container_id,
shell,
script,
interval
)
Check.script
-
classmethod
-
Run script every interval (e.g. “10s”) to peform health check
Check.
script
(
script,
interval
)
Check.http
-
classmethod
-
Peform a HTTP GET against url every interval (e.g. “10s”) to peformhealth check with an option timeout
Check.
http
(
url,
interval,
timeout=None
)
Check.tcp
-
classmethod
-
Attempt to establish a tcp connection to the specified host andport at a specified interval with optional timeout
Check.
tcp
(
host,
port,
interval,
timeout=None
)
Check.ttl
-
classmethod
-
Set check to be marked as critical after ttl (e.g. “10s”) unless thecheck is periodically marked as passing.
Check.
ttl
(
ttl
)
Consul
-
class
-
token is an optional ACL token. If supplied it will be used bydefault for all requests made with this client session. It’s stillpossible to override this token by passing a token explicitly for arequest.
consistency sets the consistency mode to use by default for all readsthat support the consistency option. It’s still possible to overridethis by passing explicitly for a given request. consistency can beeither ‘default’, ‘consistent’ or ‘stale’.
dc is the datacenter that this agent will communicate with.By default the datacenter of the host is used.
verify is whether to verify the SSL certificate for HTTPS requests
consul.
Consul
(
host='127.0.0.1',
port=8500,
token=None,
scheme='http',
consistency='default',
dc=None,
verify=True
)
Consul.kv
-
class
-
The KV endpoint is used to expose a simple key/value store. This can beused to store service configurations or other meta data in a simpleway.
-
Returns a tuple of (index, value[s])
index is the current Consul index, suitable for making subsequentcalls to wait for changes since this query was last run.
wait the maximum duration to wait (e.g. ‘10s’) to retrievea given index. this parameter is only applied if index is alsospecified. the wait time by default is 5 minutes.
token is an optional ACL token to apply to this request.
keys is a boolean which, if True, says to return a flat list ofkeys without values or other metadata. separator can be usedwith keys to list keys only up to a given separator character.
dc is the optional datacenter that you wish to communicate with.If None is provided, defaults to the agent’s datacenter.
The value returned is for the specified key, or if recurse isTrue a list of values for all keys with the given prefix isreturned.
Each value looks like this:
{ "CreateIndex": 100, "ModifyIndex": 200, "LockIndex": 200, "Key": "foo", "Flags": 0, "Value": "bar", "Session": "adf4238a-882b-9ddc-4a9d-5b6758e4159e" }
Note, if the requested key does not exists (index, None) isreturned. It’s then possible to long poll on the index for when thekey is created.
get
( key, index=None, recurse=False, wait=None, token=None, consistency=None, keys=False, separator=None, dc=None )-
Sets key to the given value.
value can either be None (useful for marking a key as adirectory) or any string type, including binary data (e.g. amsgpack’d data structure)
The optional cas parameter is used to turn the PUT into aCheck-And-Set operation. This is very useful as it allows clientsto build more complex syncronization primitives on top. If theindex is 0, then Consul will only put the key if it does notalready exist. If the index is non-zero, then the key is only setif the index matches the ModifyIndex of that key.
An optional flags can be set. This can be used to specify anunsigned value between 0 and 2^64-1.
acquire is an optional session_id. if supplied a lock acquisitionwill be attempted.
release is an optional session_id. if supplied a lock releasewill be attempted.
token is an optional ACL token to apply to this request. Ifthe token’s policy is not allowed to write to this key anACLPermissionDenied exception will be raised.
dc is the optional datacenter that you wish to communicate with.If None is provided, defaults to the agent’s datacenter.
The return value is simply either True or False. If False isreturned, then the update has not taken place.
put
( key, value, cas=None, flags=None, acquire=None, release=None, token=None, dc=None )-
Deletes a single key or if recurse is True, all keys sharing aprefix.
cas is an optional flag is used to turn the DELETE into aCheck-And-Set operation. This is very useful as a building blockfor more complex synchronization primitives. Unlike PUT, the indexmust be greater than 0 for Consul to take any action: a 0 indexwill not delete the key. If the index is non-zero, the key is onlydeleted if the index matches the ModifyIndex of that key.
token is an optional ACL token to apply to this request. Ifthe token’s policy is not allowed to delete to this key anACLPermissionDenied exception will be raised.
dc is the optional datacenter that you wish to communicate with.If None is provided, defaults to the agent’s datacenter.
delete
( key, recurse=None, cas=None, token=None, dc=None ) -
Consul.
KV
Consul.agent
-
class
-
The Agent endpoints are used to interact with a local Consul agent.Usually, services and checks are registered with an agent, which thentakes on the burden of registering with the Catalog and performinganti-entropy to recover from outages.
-
Returns configuration of the local agent and member information.
self
( )-
Returns all the services that are registered with the local agent.These services were either provided through configuration files, oradded dynamically using the HTTP API. It is important to note thatthe services known by the agent may be different than thosereported by the Catalog. This is usually due to changes being madewhile there is no leader elected. The agent performs activeanti-entropy, so in most situations everything will be in syncwithin a few seconds.
services
( )-
Returns all the checks that are registered with the local agent.These checks were either provided through configuration files, oradded dynamically using the HTTP API. Similar to services,the checks known by the agent may be different than thosereported by the Catalog. This is usually due to changes being madewhile there is no leader elected. The agent performs activeanti-entropy, so in most situations everything will be in syncwithin a few seconds.
checks
( )-
Returns all the members that this agent currently sees. This mayvary by agent, use the nodes api of Catalog to retrieve a clusterwide consistent view of members.
For agents running in server mode, setting wan to True returnsthe list of WAN members instead of the LAN members which isdefault.
members
( wan=False )-
The node maintenance endpoint can place the agent into“maintenance mode”.
enable is either ‘true’ or ‘false’. ‘true’ enables maintenancemode, ‘false’ disables maintenance mode.
reason is an optional string. This is simply to aid humanoperators.
maintenance
( enable, reason=None )-
This endpoint instructs the agent to attempt to connect to agiven address.
address is the ip to connect to.
wan is either ‘true’ or ‘false’. For agents running in servermode, ‘true’ causes the agent to attempt to join using the WANpool. Default is ‘false’.
join
( address, wan=False )-
This endpoint instructs the agent to force a node into the leftstate. If a node fails unexpectedly, then it will be in a failedstate. Once in the failed state, Consul will attempt to reconnect,and the services and checks belonging to that node will not becleaned up. Forcing a node into the left state allows its oldentries to be removed.
node is the node to change state for.
force_leave
( node ) -
Consul.
Agent
-
class
-
-
Add a new service to the local agent. There is moredocumentation on serviceshere.
name is the name of the service.
If the optional service_id is not provided it is set toname. You cannot have duplicate service_id entries peragent, so it may be necessary to provide one.
address will default to the address of the agent if notprovided.
An optional health check can be created for this service isone of Check.script, Check.http, Check.tcp,Check.ttl or Check.docker.
token is an optional ACL token to apply to this request.Note this call will return successful even if the token doesn’thave permissions to register this service.
script, interval, ttl, http, and timeout argumentsare deprecated. use check instead.
register
( name, service_id=None, address=None, port=None, tags=None, check=None, token=None, script=None, interval=None, ttl=None, http=None, timeout=None )-
Used to remove a service from the local agent. The agent willtake care of deregistering the service with the Catalog. Ifthere is an associated check, that is also deregistered.
deregister
( service_id )-
The service maintenance endpoint allows placing a given serviceinto “maintenance mode”.
service_id is the id of the service that is to be targetedfor maintenance.
enable is either ‘true’ or ‘false’. ‘true’ enablesmaintenance mode, ‘false’ disables maintenance mode.
reason is an optional string. This is simply to aid humanoperators.
maintenance
( service_id, enable, reason=None ) -
Consul.Agent.
Service
-
class
-
-
Register a new check with the local agent. More documentationon checks can be found here.
name is the name of the check.
check is one of Check.script, Check.http, Check.tcpCheck.ttl or Check.docker and is required.
If the optional check_id is not provided it is set to name.check_id must be unique for this agent.
notes is not used by Consul, and is meant to be humanreadable.
Optionally, a service_id can be specified to associate aregistered check with an existing service.
token is an optional ACL token to apply to this request.Note this call will return successful even if the token doesn’thave permissions to register this check.
script, interval, ttl, http, and timeout argumentsare deprecated. use check instead.
Returns True on success.
register
( name, check=None, check_id=None, notes=None, service_id=None, token=None, script=None, interval=None, ttl=None, http=None, timeout=None )-
Remove a check from the local agent.
deregister
( check_id )-
Mark a ttl based check as passing. Optional notes can beattached to describe the status of the check.
ttl_pass
( check_id, notes=None )-
Mark a ttl based check as failing. Optional notes can beattached to describe why check is failing. The status of thecheck will be set to critical and the ttl clock will be reset.
ttl_fail
( check_id, notes=None )-
Mark a ttl based check with warning. Optional notes can beattached to describe the warning. The status of thecheck will be set to warn and the ttl clock will be reset.
ttl_warn
( check_id, notes=None ) -
Consul.Agent.
Check
Consul.catalog
-
class
-
-
A low level mechanism for directly registering or updating entriesin the catalog. It is usually recommended to useagent.service.register and agent.check.register, as they aresimpler and perform anti-entropy.
node is the name of the node to register.
address is the ip of the node.
service is an optional service to register. if supplied this is adict:
{ "Service": "redis", "ID": "redis1", "Tags": [ "master", "v1" ], "Port": 8000 }
where
Service is required and is the name of the service
ID is optional, and will be set to Service if not provided.Note ID must be unique for the given node.
Tags and Port are optional.
check is an optional check to register. if supplied this is adict:
{ "Node": "foobar", "CheckID": "service:redis1", "Name": "Redis health check", "Notes": "Script based health check", "Status": "passing", "ServiceID": "redis1" }
dc is the datacenter of the node and defaults to this agentsdatacenter.
This manipulates the health check entry, but does not setup ascript or TTL to actually update the status. The full documentationis here.
Returns True on success.
register
( node, address, service=None, check=None, dc=None )-
A low level mechanism for directly removing entries in the catalog.It is usually recommended to use the agent APIs, as they aresimpler and perform anti-entropy.
node and dc specify which node on which datacenter to remove.If service_id and check_id are not provided, all associatedservices and checks are deleted. Otherwise only one of service_idand check_id should be provided and only that service or checkwill be removed.
Returns True on success.
deregister
( node, service_id=None, check_id=None, dc=None )-
Returns all the datacenters that are known by the Consul server.
datacenters
( )-
Returns a tuple of (index, nodes) of all nodes knownabout in the dc datacenter. dc defaults to the currentdatacenter of this agent.
index is the current Consul index, suitable for making subsequentcalls to wait for changes since this query was last run.
wait the maximum duration to wait (e.g. ‘10s’) to retrievea given index. this parameter is only applied if index is alsospecified. the wait time by default is 5 minutes.
consistency can be either ‘default’, ‘consistent’ or ‘stale’. ifnot specified consistency will the consistency level this clientwas configured with.
The response looks like this:
(index, [ { "Node": "baz", "Address": "10.1.10.11" }, { "Node": "foobar", "Address": "10.1.10.12" } ])
nodes
( index=None, wait=None, consistency=None, dc=None )-
Returns a tuple of (index, services) of all services knownabout in the dc datacenter. dc defaults to the currentdatacenter of this agent.
index is the current Consul index, suitable for making subsequentcalls to wait for changes since this query was last run.
wait the maximum duration to wait (e.g. ‘10s’) to retrievea given index. this parameter is only applied if index is alsospecified. the wait time by default is 5 minutes.
consistency can be either ‘default’, ‘consistent’ or ‘stale’. ifnot specified consistency will the consistency level this clientwas configured with.
The response looks like this:
(index, { "consul": [], "redis": [], "postgresql": [ "master", "slave" ] })
The main keys are the service names and the list provides all theknown tags for a given service.
services
( index=None, wait=None, consistency=None, dc=None )-
Returns a tuple of (index, services) of all services providedby node.
index is the current Consul index, suitable for making subsequentcalls to wait for changes since this query was last run.
wait the maximum duration to wait (e.g. ‘10s’) to retrievea given index. this parameter is only applied if index is alsospecified. the wait time by default is 5 minutes.
consistency can be either ‘default’, ‘consistent’ or ‘stale’. ifnot specified consistency will the consistency level this clientwas configured with.
dc is the datacenter of the node and defaults to this agentsdatacenter.
The response looks like this:
(index, { "Node": { "Node": "foobar", "Address": "10.1.10.12" }, "Services": { "consul": { "ID": "consul", "Service": "consul", "Tags": null, "Port": 8300 }, "redis": { "ID": "redis", "Service": "redis", "Tags": [ "v1" ], "Port": 8000 } } })
node
( node, index=None, wait=None, consistency=None, dc=None )-
Returns a tuple of (index, nodes) of the nodes providingservice in the dc datacenter. dc defaults to the currentdatacenter of this agent.
index is the current Consul index, suitable for making subsequentcalls to wait for changes since this query was last run.
wait the maximum duration to wait (e.g. ‘10s’) to retrievea given index. this parameter is only applied if index is alsospecified. the wait time by default is 5 minutes.
If tag is provided, the list of nodes returned will be filteredby that tag.
consistency can be either ‘default’, ‘consistent’ or ‘stale’. ifnot specified consistency will the consistency level this clientwas configured with.
The response looks like this:
(index, [ { "Node": "foobar", "Address": "10.1.10.12", "ServiceID": "redis", "ServiceName": "redis", "ServiceTags": null, "ServicePort": 8000 } ])
service
( service, index=None, wait=None, tag=None, consistency=None, dc=None ) -
Consul.
Catalog
Consul.health
-
class
-
-
Returns a tuple of (index, nodes)
index is the current Consul index, suitable for making subsequentcalls to wait for changes since this query was last run.
wait the maximum duration to wait (e.g. ‘10s’) to retrievea given index. this parameter is only applied if index is alsospecified. the wait time by default is 5 minutes.
nodes are the nodes providing the given service.
Calling with passing set to True will filter results to onlythose nodes whose checks are currently passing.
Calling with tag will filter the results by tag.
dc is the datacenter of the node and defaults to this agentsdatacenter.
token is an optional ACL token to apply to this request.
service
( service, index=None, wait=None, passing=None, tag=None, dc=None, token=None )-
Returns a tuple of (index, checks) with checks being thechecks associated with the service.
service is the name of the service being checked.
index is the current Consul index, suitable for making subsequentcalls to wait for changes since this query was last run.
wait the maximum duration to wait (e.g. ‘10s’) to retrievea given index. this parameter is only applied if index is alsospecified. the wait time by default is 5 minutes.
dc is the datacenter of the node and defaults to this agentsdatacenter.
token is an optional ACL token to apply to this request.
checks
( service, index=None, wait=None, dc=None, token=None )-
Returns a tuple of (index, nodes)
name is a supported state. From the Consul docs:
The supported states are any, unknown, passing, warning, orcritical. The any state is a wildcard that can be used toreturn all checks.index is the current Consul index, suitable for making subsequentcalls to wait for changes since this query was last run.
wait the maximum duration to wait (e.g. ‘10s’) to retrievea given index. this parameter is only applied if index is alsospecified. the wait time by default is 5 minutes.
dc is the datacenter of the node and defaults to this agentsdatacenter.
token is an optional ACL token to apply to this request.
nodes are the nodes providing the given service.
state
( name, index=None, wait=None, dc=None, token=None )-
Returns a tuple of (index, checks)
index is the current Consul index, suitable for making subsequentcalls to wait for changes since this query was last run.
wait the maximum duration to wait (e.g. ‘10s’) to retrievea given index. this parameter is only applied if index is alsospecified. the wait time by default is 5 minutes.
dc is the datacenter of the node and defaults to this agentsdatacenter.
token is an optional ACL token to apply to this request.
nodes are the nodes providing the given service.
node
( node, index=None, wait=None, dc=None, token=None ) -
Consul.
Health
Consul.session
-
class
-
-
Creates a new session. There is more documentation for sessionshere.
name is an optional human readable name for the session.
node is the node to create the session on. if not provided thecurrent agent’s node will be used.
checks is a list of checks to associate with the session. if notprovided it defaults to the serfHealth check. It is highlyrecommended that, if you override this list, you include thedefault serfHealth.
lock_delay is an integer of seconds.
behavior can be set to either ‘release’ or ‘delete’. Thiscontrols the behavior when a session is invalidated. By default,this is ‘release’, causing any locks that are held to be released.Changing this to ‘delete’ causes any locks that are held to bedeleted. ‘delete’ is useful for creating ephemeral key/valueentries.
when ttl is provided, the session is invalidated if it is notrenewed before the TTL expires. If specified, it is an integer ofseconds. Currently it must be between 10 and 3600 seconds.
By default the session will be created in the current datacenterbut an optional dc can be provided.
Returns the string session_id for the session.
create
( name=None, node=None, checks=None, lock_delay=15, behavior='release', ttl=None, dc=None )-
Destroys the session session_id
Returns True on success.
destroy
( session_id, dc=None )-
Returns a tuple of (index, sessions) of all active sessions inthe dc datacenter. dc defaults to the current datacenter ofthis agent.
index is the current Consul index, suitable for making subsequentcalls to wait for changes since this query was last run.
wait the maximum duration to wait (e.g. ‘10s’) to retrievea given index. this parameter is only applied if index is alsospecified. the wait time by default is 5 minutes.
consistency can be either ‘default’, ‘consistent’ or ‘stale’. ifnot specified consistency will the consistency level this clientwas configured with.
The response looks like this:
(index, [ { "LockDelay": 1.5e+10, "Checks": [ "serfHealth" ], "Node": "foobar", "ID": "adf4238a-882b-9ddc-4a9d-5b6758e4159e", "CreateIndex": 1086449 }, ... ])
list
( index=None, wait=None, consistency=None, dc=None )-
Returns a tuple of (index, sessions) as per session.list, butfilters the sessions returned to only those active for node.
index is the current Consul index, suitable for making subsequentcalls to wait for changes since this query was last run.
wait the maximum duration to wait (e.g. ‘10s’) to retrievea given index. this parameter is only applied if index is alsospecified. the wait time by default is 5 minutes.
consistency can be either ‘default’, ‘consistent’ or ‘stale’. ifnot specified consistency will the consistency level this clientwas configured with.
node
( node, index=None, wait=None, consistency=None, dc=None )-
Returns a tuple of (index, session) for the sessionsession_id in the dc datacenter. dc defaults to the currentdatacenter of this agent.
index is the current Consul index, suitable for making subsequentcalls to wait for changes since this query was last run.
wait the maximum duration to wait (e.g. ‘10s’) to retrievea given index. this parameter is only applied if index is alsospecified. the wait time by default is 5 minutes.
consistency can be either ‘default’, ‘consistent’ or ‘stale’. ifnot specified consistency will the consistency level this clientwas configured with.
info
( session_id, index=None, wait=None, consistency=None, dc=None )-
This is used with sessions that have a TTL, and it extends theexpiration by the TTL.
dc is the optional datacenter that you wish to communicate with.If None is provided, defaults to the agent’s datacenter.
Returns the session.
renew
( session_id, dc=None ) -
Consul.
Session
Consul.acl
-
class
-
-
Lists all the active ACL tokens. This is a privileged endpoint, andrequires a management token. token will override this client’sdefault token. An ACLPermissionDenied exception will be raisedif a management token is not used.
list
( token=None )-
Returns the token information for acl_id.
info
( acl_id, token=None )-
Creates a new ACL token. This is a privileged endpoint, andrequires a management token. token will override this client’sdefault token. An ACLPermissionDenied exception will be raisedif a management token is not used.
name is an optional name for this token.
type is either ‘management’ or ‘client’. A management token iseffectively like a root user, and has the ability to perform anyaction including creating, modifying, and deleting ACLs. A clienttoken can only perform actions as permitted by rules.
rules is an optional HCL string for this ACL Token RuleSpecification.
Rules look like this:
# Default all keys to read-only key "" { policy = "read" } key "foo/" { policy = "write" } key "foo/private/" { # Deny access to the private dir policy = "deny" }
Returns the string acl_id for the new token.
create
( name=None, type='client', rules=None, acl_id=None, token=None )-
Updates the ACL token acl_id. This is a privileged endpoint, andrequires a management token. token will override this client’sdefault token. An ACLPermissionDenied exception will be raised ifa management token is not used.
name is an optional name for this token.
type is either ‘management’ or ‘client’. A management token iseffectively like a root user, and has the ability to perform anyaction including creating, modifying, and deleting ACLs. A clienttoken can only perform actions as permitted by rules.
rules is an optional HCL string for this ACL Token RuleSpecification.
Returns the string acl_id of this token on success.
update
( acl_id, name=None, type=None, rules=None, token=None )-
Clones the ACL token acl_id. This is a privileged endpoint, andrequires a management token. token will override this client’sdefault token. An ACLPermissionDenied exception will be raised ifa management token is not used.
Returns the string of the newly created acl_id.
clone
( acl_id, token=None )-
Destroys the ACL token acl_id. This is a privileged endpoint, andrequires a management token. token will override this client’sdefault token. An ACLPermissionDenied exception will be raised ifa management token is not used.
Returns True on success.
destroy
( acl_id, token=None ) -
Consul.
ACL
Consul.event
-
class
-
The event command provides a mechanism to fire a custom user event toan entire datacenter. These events are opaque to Consul, but they canbe used to build scripting infrastructure to do automated deploys,restart services, or perform any other orchestration action.
Unlike most Consul data, which is replicated using consensus, eventdata is purely peer-to-peer over gossip.
This means it is not persisted and does not have a total ordering. Inpractice, this means you cannot rely on the order of message delivery.An advantage however is that events can still be used even in theabsence of server nodes or during an outage.
-
Sends an event to Consul’s gossip protocol.
name is the Consul-opaque name of the event. This can be filteredon in calls to list, below
-
body is the Consul-opaque body to be delivered with the event.
-
-
From the Consul documentation:
- The underlying gossip also sets limits on the size of a userevent message. It is hard to give an exact number, as itdepends on various parameters of the event, but the payloadshould be kept very small (< 100 bytes). Specifying too largeof an event will return an error.
node, service, and tag are regular expressions which remoteagents will filter against to determine if they should store theevent
-
fire
( name, body='', node=None, service=None, tag=None )-
-
Returns a tuple of (
index,
events)
- Note: Since Consul’s event protocol uses gossip, there is noordering, and instead index maps to the newest event thatmatches the query.
name is the type of events to list, if None, lists all available.
index is the current event Consul index, suitable for makingsubsequent calls to wait for changes since this query was last run.Check https://consul.io/docs/agent/http/event.html#event_list formore infos about indexes on events.
wait the maximum duration to wait (e.g. ‘10s’) to retrievea given index. This parameter is only applied if index is alsospecified. the wait time by default is 5 minutes.
Consul agents only buffer the most recent entries. The currentbuffer size is 256, but this value could change in the future.
Each event looks like this:
{ { "ID": "b54fe110-7af5-cafc-d1fb-afc8ba432b1c", "Name": "deploy", "Payload": "1609030", "NodeFilter": "", "ServiceFilter": "", "TagFilter": "", "Version": 1, "LTime": 19 }, }
list
( name=None, index=None, wait=None ) -
Consul.
Event
Consul.status
-
class
-
-
The Status endpoints are used to get information about the status
- of the Consul cluster.
-
This endpoint is used to get the Raft leader for the datacenterin which the agent is running.
leader
( )-
This endpoint retrieves the Raft peers for the datacenter in whichthe the agent is running.
peers
( )
Consul.
Status