From 3290c2fc3c30964852fcfaa76193a698870600d7 Mon Sep 17 00:00:00 2001 From: ossark Date: Tue, 1 Aug 2017 16:15:54 +0200 Subject: [PATCH] Added priority attribute for pool members (bigip_pool_member module) (#23128) * Added priority attribute for pool members (bigip_pool_member module) * Line break missing * Change from 'priority' to 'priority_group' * Update bigip_pool_member.py * Update bigip_pool_member.py --- .../modules/network/f5/bigip_pool_member.py | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/lib/ansible/modules/network/f5/bigip_pool_member.py b/lib/ansible/modules/network/f5/bigip_pool_member.py index bc272b43c8..da212f72ee 100644 --- a/lib/ansible/modules/network/f5/bigip_pool_member.py +++ b/lib/ansible/modules/network/f5/bigip_pool_member.py @@ -121,6 +121,12 @@ options: - yes - no version_added: 2.1 + priority_group: + description: + - Sets priority group for a pool member. + required: false + default: null + version_added: 2.4 extends_documentation_fragment: f5 ''' @@ -331,6 +337,24 @@ def set_ratio(api, pool, address, port, ratio): ) +def get_priority_group(api, pool, address, port): + members = [{'address': address, 'port': port}] + result = api.LocalLB.Pool.get_member_priority( + pool_names=[pool], + members=[members] + )[0][0] + return result + + +def set_priority_group(api, pool, address, port, priority_group): + members = [{'address': address, 'port': port}] + api.LocalLB.Pool.set_member_priority( + pool_names=[pool], + members=[members], + priorities=[[priority_group]] + ) + + def set_member_session_enabled_state(api, pool, address, port, session_state): members = [{'address': address, 'port': port}] session_state = ["STATE_%s" % session_state.strip().upper()] @@ -384,7 +408,8 @@ def main(): description=dict(type='str'), rate_limit=dict(type='int'), ratio=dict(type='int'), - preserve_node=dict(type='bool', default=False) + preserve_node=dict(type='bool', default=False), + priority_group=dict(type='int') ) argument_spec.update(meta_args) @@ -415,6 +440,7 @@ def main(): description = module.params['description'] rate_limit = module.params['rate_limit'] ratio = module.params['ratio'] + priority_group = module.params['priority_group'] host = module.params['host'] address = fq_name(partition, host) port = module.params['port'] @@ -460,6 +486,8 @@ def main(): set_member_session_enabled_state(api, pool, address, port, session_state) if monitor_state is not None: set_member_monitor_state(api, pool, address, port, monitor_state) + if priority_group is not None: + set_priority_group(api, pool, address, port, priority_group) result = {'changed': True} else: # pool member exists -- potentially modify attributes @@ -499,6 +527,10 @@ def main(): if not module.check_mode: set_member_monitor_state(api, pool, address, port, monitor_state) result = {'changed': True} + if priority_group is not None and priority_group != get_priority_group(api, pool, address, port): + if not module.check_mode: + set_priority_group(api, pool, address, port, priority_group) + result = {'changed': True} except Exception as e: module.fail_json(msg="received exception: %s" % e)