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:
Steve Gargan 2016-09-14 11:39:41 +02:00 committed by Matt Clay
parent c203283889
commit b57b74e40b

View file

@ -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:
@ -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,14 +237,6 @@ 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'))
@ -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'),