diff --git a/consul/base.py b/consul/base.py index ee6ab254..11a21d5d 100755 --- a/consul/base.py +++ b/consul/base.py @@ -358,6 +358,7 @@ class Event(object): practice, this means you cannot rely on the order of message delivery. An advantage however is that events can still be used even in the absence of server nodes or during an outage.""" + def __init__(self, agent): self.agent = agent @@ -465,6 +466,7 @@ class KV(object): used to store service configurations or other meta data in a simple way. """ + def __init__(self, agent): self.agent = agent @@ -662,6 +664,7 @@ class Txn(object): The Transactions endpoints manage updates or fetches of multiple keys inside a single, atomic transaction. """ + def __init__(self, agent): self.agent = agent @@ -697,6 +700,7 @@ class Agent(object): takes on the burden of registering with the Catalog and performing anti-entropy to recover from outages. """ + def __init__(self, agent): self.agent = agent self.service = Consul.Agent.Service(agent) @@ -1716,7 +1720,8 @@ def create( lock_delay=15, behavior='release', ttl=None, - dc=None): + dc=None, + token=None): """ Creates a new session. There is more documentation for sessions `here `_. @@ -1747,12 +1752,17 @@ def create( By default the session will be created in the current datacenter but an optional *dc* can be provided. + *token* is an optional `ACL token`_ to apply to this request. + Returns the string *session_id* for the session. """ params = [] dc = dc or self.agent.dc if dc: params.append(('dc', dc)) + token = token or self.agent.token + if token: + params.append(('token', token)) data = {} if name: data['name'] = name @@ -1780,22 +1790,33 @@ def create( params=params, data=data) - def destroy(self, session_id, dc=None): + def destroy(self, session_id, dc=None, token=None): """ Destroys the session *session_id* + *token* is an optional `ACL token`_ to apply to this request. + Returns *True* on success. """ params = [] dc = dc or self.agent.dc if dc: params.append(('dc', dc)) + token = token or self.agent.token + if token: + params.append(('token', token)) return self.agent.http.put( CB.bool(), '/v1/session/destroy/%s' % session_id, params=params) - def list(self, index=None, wait=None, consistency=None, dc=None): + def list( + self, + index=None, + wait=None, + consistency=None, + dc=None, + token=None): """ Returns a tuple of (*index*, *sessions*) of all active sessions in the *dc* datacenter. *dc* defaults to the current datacenter of @@ -1812,6 +1833,8 @@ def list(self, index=None, wait=None, consistency=None, dc=None): not specified *consistency* will the consistency level this client was configured with. + *token* is an optional `ACL token`_ to apply to this request. + The response looks like this:: (index, [ @@ -1831,6 +1854,9 @@ def list(self, index=None, wait=None, consistency=None, dc=None): dc = dc or self.agent.dc if dc: params.append(('dc', dc)) + token = token or self.agent.token + if token: + params.append(('token', token)) if index: params.append(('index', index)) if wait: @@ -1841,7 +1867,14 @@ def list(self, index=None, wait=None, consistency=None, dc=None): return self.agent.http.get( CB.json(index=True), '/v1/session/list', params=params) - def node(self, node, index=None, wait=None, consistency=None, dc=None): + def node( + self, + node, + index=None, + wait=None, + consistency=None, + dc=None, + token=None): """ Returns a tuple of (*index*, *sessions*) as per *session.list*, but filters the sessions returned to only those active for *node*. @@ -1856,11 +1889,16 @@ def node(self, node, index=None, wait=None, consistency=None, dc=None): *consistency* can be either 'default', 'consistent' or 'stale'. if not specified *consistency* will the consistency level this client was configured with. + + *token* is an optional `ACL token`_ to apply to this request. """ params = [] dc = dc or self.agent.dc if dc: params.append(('dc', dc)) + token = token or self.agent.token + if token: + params.append(('token', token)) if index: params.append(('index', index)) if wait: @@ -1877,7 +1915,8 @@ def info(self, index=None, wait=None, consistency=None, - dc=None): + dc=None, + token=None): """ Returns a tuple of (*index*, *session*) for the session *session_id* in the *dc* datacenter. *dc* defaults to the current @@ -1893,11 +1932,16 @@ def info(self, *consistency* can be either 'default', 'consistent' or 'stale'. if not specified *consistency* will the consistency level this client was configured with. + + *token* is an optional `ACL token`_ to apply to this request. """ params = [] dc = dc or self.agent.dc if dc: params.append(('dc', dc)) + token = token or self.agent.token + if token: + params.append(('token', token)) if index: params.append(('index', index)) if wait: @@ -1910,7 +1954,7 @@ def info(self, '/v1/session/info/%s' % session_id, params=params) - def renew(self, session_id, dc=None): + def renew(self, session_id, dc=None, token=None): """ This is used with sessions that have a TTL, and it extends the expiration by the TTL. @@ -1918,12 +1962,17 @@ def renew(self, session_id, dc=None): *dc* is the optional datacenter that you wish to communicate with. If None is provided, defaults to the agent's datacenter. + *token* is an optional `ACL token`_ to apply to this request. + Returns the session. """ params = [] dc = dc or self.agent.dc if dc: params.append(('dc', dc)) + token = token or self.agent.token + if token: + params.append(('token', token)) return self.agent.http.put( CB.json(one=True, allow_404=False), '/v1/session/renew/%s' % session_id, @@ -2111,6 +2160,7 @@ class Status(object): The Status endpoints are used to get information about the status of the Consul cluster. """ + def __init__(self, agent): self.agent = agent