From b57b74e40b0f2a838d2826fc1ce978f5ef2a17e0 Mon Sep 17 00:00:00 2001 From: Steve Gargan Date: Wed, 14 Sep 2016 11:39:41 +0200 Subject: [PATCH] remove duration from lock delay as seconds are the only granularity supported. (#2877) add utf header to file so that it loads correctly --- .../extras/clustering/consul_session.py | 30 +++++++------------ 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/lib/ansible/modules/extras/clustering/consul_session.py b/lib/ansible/modules/extras/clustering/consul_session.py index d2c24e12a3b..4d733561391 100644 --- a/lib/ansible/modules/extras/clustering/consul_session.py +++ b/lib/ansible/modules/extras/clustering/consul_session.py @@ -1,4 +1,5 @@ #!/usr/bin/python +# -*- coding: utf-8 -*- # # (c) 2015, Steve Gargan # @@ -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: @@ -114,7 +114,7 @@ EXAMPLES = ''' - name: register basic session with consul consul_session: name: session1 - + - name: register a session with an existing check consul_session: name: session_with_check @@ -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,18 +237,10 @@ 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')) - + def test_dependencies(module): if not python_consul_installed: module.fail_json(msg="python-consul required for this module. "\ @@ -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'), @@ -275,9 +265,9 @@ def main(): ) module = AnsibleModule(argument_spec, supports_check_mode=False) - + test_dependencies(module) - + try: execute(module) except ConnectionError, e: