From a27de3adccfb330b3bf28b7c703713687a0b2764 Mon Sep 17 00:00:00 2001 From: Tim Rupp Date: Wed, 26 Oct 2016 09:06:34 -0700 Subject: [PATCH] Adds route advertisement state to the bigip_virtual_server module (#3273) --- .../extras/network/f5/bigip_virtual_server.py | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/lib/ansible/modules/extras/network/f5/bigip_virtual_server.py b/lib/ansible/modules/extras/network/f5/bigip_virtual_server.py index b1fb318ca59..f1c6905ca1d 100644 --- a/lib/ansible/modules/extras/network/f5/bigip_virtual_server.py +++ b/lib/ansible/modules/extras/network/f5/bigip_virtual_server.py @@ -112,6 +112,12 @@ options: - Default Profile which manages the session persistence required: false default: None + route_advertisement_state: + description: + - Enable route advertisement for destination + required: false + default: disabled + version_added: "2.3" description: description: - Virtual server description @@ -540,6 +546,27 @@ def set_default_persistence_profiles(api, name, persistence_profile): raise Exception('Error on setting default persistence profile : %s' % e) +def get_route_advertisement_status(api, address): + result = api.LocalLB.VirtualAddressV2.get_route_advertisement_state(virtual_addresses=[address]).pop(0) + result = result.split("STATE_")[-1].lower() + return result + + +def set_route_advertisement_state(api, destination, partition, route_advertisement_state): + updated = False + + try: + state = "STATE_%s" % route_advertisement_state.strip().upper() + address = fq_name(partition, destination,) + current_route_advertisement_state=get_route_advertisement_status(api,address) + if current_route_advertisement_state != route_advertisement_state: + api.LocalLB.VirtualAddressV2.set_route_advertisement_state(virtual_addresses=[address], states=[state]) + updated = True + return updated + except bigsuds.OperationFailed as e: + raise Exception('Error on setting profiles : %s' % e) + + def main(): argument_spec = f5_argument_spec() argument_spec.update(dict( @@ -554,6 +581,7 @@ def main(): pool=dict(type='str'), description=dict(type='str'), snat=dict(type='str'), + route_advertisement_state=dict(type='str', default='disabled', choices=['enabled', 'disabled']), default_persistence_profile=dict(type='str') )) @@ -593,6 +621,7 @@ def main(): pool = fq_name(partition, module.params['pool']) description = module.params['description'] snat = module.params['snat'] + route_advertisement_state = module.params['route_advertisement_state'] default_persistence_profile = fq_name(partition, module.params['default_persistence_profile']) if 1 > port > 65535: @@ -639,6 +668,7 @@ def main(): set_description(api, name, description) set_default_persistence_profiles(api, name, default_persistence_profile) set_state(api, name, state) + set_route_advertisement_state(api, destination, partition, route_advertisement_state) result = {'changed': True} except bigsuds.OperationFailed as e: raise Exception('Error on creating Virtual Server : %s' % e) @@ -663,6 +693,7 @@ def main(): result['changed'] |= set_rules(api, name, all_rules) result['changed'] |= set_default_persistence_profiles(api, name, default_persistence_profile) result['changed'] |= set_state(api, name, state) + result['changed'] |= set_route_advertisement_state(api, destination, partition, route_advertisement_state) api.System.Session.submit_transaction() except Exception as e: raise Exception("Error on updating Virtual Server : %s" % e)