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
# -*- coding: utf-8 -*-
#
# (c) 2015, Steve Gargan <steve.gargan@gmail.com>
#
@ -30,7 +31,7 @@ requirements:
- python-consul
- requests
version_added: "2.0"
author: "Steve Gargan (@sgargan)"
author: "Steve Gargan @sgargan"
options:
state:
description:
@ -54,9 +55,8 @@ options:
description:
- the optional lock delay that can be attached to the session when it
is created. Locks for invalidated sessions ar blocked from being
acquired until this delay has expired. Valid units for delays
include 'ns', 'us', 'ms', 's', 'm', 'h'
default: 15s
acquired until this delay has expired. Durations are in seconds
default: 15
required: false
node:
description:
@ -201,12 +201,11 @@ def update_session(module):
consul_client = get_consul_api(module)
try:
session = consul_client.session.create(
name=name,
behavior=behavior,
node=node,
lock_delay=validate_duration('delay', delay),
lock_delay=delay,
dc=datacenter,
checks=checks
)
@ -223,7 +222,6 @@ def update_session(module):
def remove_session(module):
session_id = module.params.get('id')
if not session_id:
module.fail_json(msg="""A session id must be supplied in order to
remove a session.""")
@ -239,14 +237,6 @@ def remove_session(module):
module.fail_json(msg="Could not remove session with id '%s' %s" % (
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):
return consul.Consul(host=module.params.get('host'),
port=module.params.get('port'))
@ -259,7 +249,7 @@ def test_dependencies(module):
def main():
argument_spec = dict(
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',
choices=['release', 'delete']),
host=dict(default='localhost'),