From aaf16fe3376773ab50e9c7b98363e294d38eedc4 Mon Sep 17 00:00:00 2001 From: Etienne CARRIERE Date: Wed, 18 Nov 2015 06:52:03 +0100 Subject: [PATCH] Developpement of enabled/disabled state --- network/f5/bigip_virtual_server.py | 35 ++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/network/f5/bigip_virtual_server.py b/network/f5/bigip_virtual_server.py index 043a44c6ca8..f7e243c5d6e 100644 --- a/network/f5/bigip_virtual_server.py +++ b/network/f5/bigip_virtual_server.py @@ -54,9 +54,13 @@ options: choices: ['yes', 'no'] state: description: - - Pool member state + - Virtual Server state required: false default: present + description: + - Absent : delete the VS if present + - present (and its synonym enabled) : create if needed the VS and set state to enabled + - absent : create if needed the VS and set state to disabled choices: ['present', 'absent', 'enabled', 'disabled'] aliases: [] partition: @@ -292,7 +296,22 @@ def set_port(api,name,port): except bigsuds.OperationFailed, e: raise Exception('Error on setting port : %s'% e ) +def get_state(api,name): + return api.LocalLB.VirtualServer.get_enabled_state(virtual_servers = [name])[0] +def set_state(api,name,state): + updated=False + try: + current_state=get_state(api,name) + # We consider that being present is equivalent to enabled + if state == 'present': + state='enabled' + if STATES[state] != current_state: + api.LocalLB.VirtualServer.set_enabled_state(virtual_servers=[name],states=[STATES[state]]) + updated=True + return updated + except bigsuds.OperationFailed, e: + raise Exception('Error on setting state : %s'% e ) def get_description(api,name): return api.LocalLB.VirtualServer.get_description(virtual_servers = [name])[0] @@ -386,7 +405,7 @@ def main(): # check-mode return value result = {'changed': True} - elif state == 'present': + else: update = False if not vs_exists(api, name): if (not destination) or (not port): @@ -403,6 +422,7 @@ def main(): set_snat(api,name,snat) set_description(api,name,description) set_default_persistence_profiles(api,name,default_persistence_profile) + set_state(api,name,state) result = {'changed': True} except bigsuds.OperationFailed, e: raise Exception('Error on creating Virtual Server : %s' % e) @@ -424,6 +444,7 @@ def main(): result['changed']|=set_snat(api,name,snat) result['changed']|=set_profiles(api,name,all_profiles) result['changed']|=set_default_persistence_profiles(api,name,default_persistence_profile) + result['changed']|=set_state(api,name,state) api.System.Session.submit_transaction() except Exception,e: raise Exception("Error on updating Virtual Server : %s" % e) @@ -431,16 +452,6 @@ def main(): # check-mode return value result = {'changed': True} - elif state in ('disabled', 'enabled'): - if name is None: - module.fail_json(msg="name parameter required when " \ - "state=enabled/disabled") - if not module.check_mode: - pass - else: - # check-mode return value - result = {'changed': True} - except Exception, e: module.fail_json(msg="received exception: %s" % e)