Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Apr 15, 2024. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 56 additions & 6 deletions 62 consul/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 <https://consul.io/docs/internals/sessions.html>`_.
Expand Down Expand Up @@ -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:
abarbare marked this conversation as resolved.
Show resolved Hide resolved
params.append(('token', token))
data = {}
if name:
data['name'] = name
Expand Down Expand Up @@ -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:
abarbare marked this conversation as resolved.
Show resolved Hide resolved
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
Expand All @@ -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, [
Expand All @@ -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:
abarbare marked this conversation as resolved.
Show resolved Hide resolved
params.append(('token', token))
if index:
params.append(('index', index))
if wait:
Expand All @@ -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*.
Expand All @@ -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:
abarbare marked this conversation as resolved.
Show resolved Hide resolved
params.append(('token', token))
if index:
params.append(('index', index))
if wait:
Expand All @@ -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
Expand All @@ -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:
abarbare marked this conversation as resolved.
Show resolved Hide resolved
params.append(('token', token))
if index:
params.append(('index', index))
if wait:
Expand All @@ -1910,20 +1954,25 @@ 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.

*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:
abarbare marked this conversation as resolved.
Show resolved Hide resolved
params.append(('token', token))
return self.agent.http.put(
CB.json(one=True, allow_404=False),
'/v1/session/renew/%s' % session_id,
Expand Down Expand Up @@ -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

Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.