remove duration from lock delay as seconds are the only granularity supported. (#2877)
add utf header to file so that it loads correctly
This commit is contained in:
parent
6d37aa4260
commit
2b6f3419b6
1 changed files with 10 additions and 20 deletions
|
@ -1,4 +1,5 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
#
|
#
|
||||||
# (c) 2015, Steve Gargan <steve.gargan@gmail.com>
|
# (c) 2015, Steve Gargan <steve.gargan@gmail.com>
|
||||||
#
|
#
|
||||||
|
@ -30,7 +31,7 @@ requirements:
|
||||||
- python-consul
|
- python-consul
|
||||||
- requests
|
- requests
|
||||||
version_added: "2.0"
|
version_added: "2.0"
|
||||||
author: "Steve Gargan (@sgargan)"
|
author: "Steve Gargan @sgargan"
|
||||||
options:
|
options:
|
||||||
state:
|
state:
|
||||||
description:
|
description:
|
||||||
|
@ -54,9 +55,8 @@ options:
|
||||||
description:
|
description:
|
||||||
- the optional lock delay that can be attached to the session when it
|
- the optional lock delay that can be attached to the session when it
|
||||||
is created. Locks for invalidated sessions ar blocked from being
|
is created. Locks for invalidated sessions ar blocked from being
|
||||||
acquired until this delay has expired. Valid units for delays
|
acquired until this delay has expired. Durations are in seconds
|
||||||
include 'ns', 'us', 'ms', 's', 'm', 'h'
|
default: 15
|
||||||
default: 15s
|
|
||||||
required: false
|
required: false
|
||||||
node:
|
node:
|
||||||
description:
|
description:
|
||||||
|
@ -114,7 +114,7 @@ EXAMPLES = '''
|
||||||
- name: register basic session with consul
|
- name: register basic session with consul
|
||||||
consul_session:
|
consul_session:
|
||||||
name: session1
|
name: session1
|
||||||
|
|
||||||
- name: register a session with an existing check
|
- name: register a session with an existing check
|
||||||
consul_session:
|
consul_session:
|
||||||
name: session_with_check
|
name: session_with_check
|
||||||
|
@ -201,12 +201,11 @@ def update_session(module):
|
||||||
consul_client = get_consul_api(module)
|
consul_client = get_consul_api(module)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
||||||
session = consul_client.session.create(
|
session = consul_client.session.create(
|
||||||
name=name,
|
name=name,
|
||||||
behavior=behavior,
|
behavior=behavior,
|
||||||
node=node,
|
node=node,
|
||||||
lock_delay=validate_duration('delay', delay),
|
lock_delay=delay,
|
||||||
dc=datacenter,
|
dc=datacenter,
|
||||||
checks=checks
|
checks=checks
|
||||||
)
|
)
|
||||||
|
@ -223,7 +222,6 @@ def update_session(module):
|
||||||
|
|
||||||
def remove_session(module):
|
def remove_session(module):
|
||||||
session_id = module.params.get('id')
|
session_id = module.params.get('id')
|
||||||
|
|
||||||
if not session_id:
|
if not session_id:
|
||||||
module.fail_json(msg="""A session id must be supplied in order to
|
module.fail_json(msg="""A session id must be supplied in order to
|
||||||
remove a session.""")
|
remove a session.""")
|
||||||
|
@ -239,18 +237,10 @@ def remove_session(module):
|
||||||
module.fail_json(msg="Could not remove session with id '%s' %s" % (
|
module.fail_json(msg="Could not remove session with id '%s' %s" % (
|
||||||
session_id, e))
|
session_id, e))
|
||||||
|
|
||||||
def validate_duration(name, duration):
|
|
||||||
if duration:
|
|
||||||
duration_units = ['ns', 'us', 'ms', 's', 'm', 'h']
|
|
||||||
if not any((duration.endswith(suffix) for suffix in duration_units)):
|
|
||||||
raise Exception('Invalid %s %s you must specify units (%s)' %
|
|
||||||
(name, duration, ', '.join(duration_units)))
|
|
||||||
return duration
|
|
||||||
|
|
||||||
def get_consul_api(module):
|
def get_consul_api(module):
|
||||||
return consul.Consul(host=module.params.get('host'),
|
return consul.Consul(host=module.params.get('host'),
|
||||||
port=module.params.get('port'))
|
port=module.params.get('port'))
|
||||||
|
|
||||||
def test_dependencies(module):
|
def test_dependencies(module):
|
||||||
if not python_consul_installed:
|
if not python_consul_installed:
|
||||||
module.fail_json(msg="python-consul required for this module. "\
|
module.fail_json(msg="python-consul required for this module. "\
|
||||||
|
@ -259,7 +249,7 @@ def test_dependencies(module):
|
||||||
def main():
|
def main():
|
||||||
argument_spec = dict(
|
argument_spec = dict(
|
||||||
checks=dict(default=None, required=False, type='list'),
|
checks=dict(default=None, required=False, type='list'),
|
||||||
delay=dict(required=False,type='str', default='15s'),
|
delay=dict(required=False,type='int', default='15'),
|
||||||
behavior=dict(required=False,type='str', default='release',
|
behavior=dict(required=False,type='str', default='release',
|
||||||
choices=['release', 'delete']),
|
choices=['release', 'delete']),
|
||||||
host=dict(default='localhost'),
|
host=dict(default='localhost'),
|
||||||
|
@ -275,9 +265,9 @@ def main():
|
||||||
)
|
)
|
||||||
|
|
||||||
module = AnsibleModule(argument_spec, supports_check_mode=False)
|
module = AnsibleModule(argument_spec, supports_check_mode=False)
|
||||||
|
|
||||||
test_dependencies(module)
|
test_dependencies(module)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
execute(module)
|
execute(module)
|
||||||
except ConnectionError, e:
|
except ConnectionError, e:
|
||||||
|
|
Loading…
Reference in a new issue