Add "Default Persistence profile" support

This commit is contained in:
Etienne CARRIERE 2015-07-02 08:20:29 +02:00
parent 757fc291c1
commit fc9078229c

View file

@ -93,7 +93,11 @@ options:
- "Source network address policy"
required: false
default: None
default_persistence_profile:
description:
- "Default Profile which manages the session persistence"
required: false
default: None
description:
description:
- "Virtual server description."
@ -291,6 +295,28 @@ def set_description(api,name,description):
except bigsuds.OperationFailed, e:
raise Exception('Error on setting description : %s ' % e)
def get_persistence_profiles(api,name):
return api.LocalLB.VirtualServer.get_persistence_profile(virtual_servers = [name])[0]
def set_default_persistence_profiles(api,name,persistence_profile):
updated=False
if persistence_profile is None:
return updated
try:
current_persistence_profiles = get_persistence_profiles(api,name)
default=None
for profile in current_persistence_profiles:
if profile['default_profile']:
default=profile['profile_name']
break
if default is not None and default != persistence_profile:
api.LocalLB.VirtualServer.remove_persistence_profile(virtual_servers=[name],profiles=[[{'profile_name':default,'default_profile' : True}]])
if default != persistence_profile:
api.LocalLB.VirtualServer.add_persistence_profile(virtual_servers=[name],profiles=[[{'profile_name':persistence_profile,'default_profile' : True}]])
updated=True
return updated
except bigsuds.OperationFailed, e:
raise Exception('Error on setting default persistence profile : %s' % e)
def main():
argument_spec = f5_argument_spec()
@ -303,7 +329,8 @@ def main():
all_profiles = dict(type='list'),
pool=dict(type='str'),
description = dict(type='str'),
snat=dict(type='str')
snat=dict(type='str'),
default_persistence_profile=dict(type='str')
)
)
@ -320,6 +347,7 @@ def main():
pool=fq_name(partition,module.params['pool'])
description = module.params['description']
snat = module.params['snat']
default_persistence_profile=fq_name(partition,module.params['default_persistence_profile'])
if 1 > port > 65535:
module.fail_json(msg="valid ports must be in range 1 - 65535")
@ -361,6 +389,7 @@ def main():
set_profiles(api,name,all_profiles)
set_snat(api,name,snat)
set_description(api,name,description)
set_default_persistence_profiles(api,name,default_persistence_profile)
result = {'changed': True}
except bigsuds.OperationFailed, e:
raise Exception('Error on creating Virtual Server : %s' % e)
@ -380,6 +409,7 @@ def main():
result['changed']|=set_description(api,name,description)
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)
api.System.Session.submit_transaction()
except Exception,e:
raise Exception("Error on updating Virtual Server : %s" % e)