summaryrefslogtreecommitdiff
path: root/clustering/consul_session.py
diff options
context:
space:
mode:
authorRené Moser <mail@renemoser.net>2016-03-15 23:19:07 +0100
committerRené Moser <mail@renemoser.net>2016-03-15 23:19:07 +0100
commit1c79efb64d2b78c27fccd388d5015f05bf5b87ad (patch)
treef467a110fbc8cc6c503e1a9c107cf293b63b7a49 /clustering/consul_session.py
parent6c32e235f13af4fcbfd664d170cee8c0bec1569f (diff)
parent250494eaefcd475c69cc339654951683512a0e3f (diff)
downloadansible-modules-extras-1c79efb64d2b78c27fccd388d5015f05bf5b87ad.tar.gz
Merge pull request #1725 from mscherer/clean_consul
Clean consul
Diffstat (limited to 'clustering/consul_session.py')
-rw-r--r--clustering/consul_session.py21
1 files changed, 8 insertions, 13 deletions
diff --git a/clustering/consul_session.py b/clustering/consul_session.py
index 423a6ece..663456da 100644
--- a/clustering/consul_session.py
+++ b/clustering/consul_session.py
@@ -113,8 +113,6 @@ EXAMPLES = '''
consul_session: state=list
'''
-import sys
-
try:
import consul
from requests.exceptions import ConnectionError
@@ -138,10 +136,10 @@ def lookup_sessions(module):
datacenter = module.params.get('datacenter')
state = module.params.get('state')
- consul = get_consul_api(module)
+ consul_client = get_consul_api(module)
try:
if state == 'list':
- sessions_list = consul.session.list(dc=datacenter)
+ sessions_list = consul_client.session.list(dc=datacenter)
#ditch the index, this can be grabbed from the results
if sessions_list and sessions_list[1]:
sessions_list = sessions_list[1]
@@ -152,7 +150,7 @@ def lookup_sessions(module):
if not node:
module.fail_json(
msg="node name is required to retrieve sessions for node")
- sessions = consul.session.node(node, dc=datacenter)
+ sessions = consul_client.session.node(node, dc=datacenter)
module.exit_json(changed=True,
node=node,
sessions=sessions)
@@ -162,7 +160,7 @@ def lookup_sessions(module):
module.fail_json(
msg="session_id is required to retrieve indvidual session info")
- session_by_id = consul.session.info(session_id, dc=datacenter)
+ session_by_id = consul_client.session.info(session_id, dc=datacenter)
module.exit_json(changed=True,
session_id=session_id,
sessions=session_by_id)
@@ -174,18 +172,16 @@ def lookup_sessions(module):
def update_session(module):
name = module.params.get('name')
- session_id = module.params.get('id')
delay = module.params.get('delay')
checks = module.params.get('checks')
datacenter = module.params.get('datacenter')
node = module.params.get('node')
- consul = get_consul_api(module)
- changed = True
+ consul_client = get_consul_api(module)
try:
- session = consul.session.create(
+ session = consul_client.session.create(
name=name,
node=node,
lock_delay=validate_duration('delay', delay),
@@ -209,11 +205,10 @@ def remove_session(module):
module.fail_json(msg="""A session id must be supplied in order to
remove a session.""")
- consul = get_consul_api(module)
- changed = False
+ consul_client = get_consul_api(module)
try:
- session = consul.session.destroy(session_id)
+ consul_client.session.destroy(session_id)
module.exit_json(changed=True,
session_id=session_id)