From 940419d08539dec0a643fe9825bed39463d04c94 Mon Sep 17 00:00:00 2001 From: Serge van Ginderachter Date: Fri, 30 Aug 2013 17:41:40 +0200 Subject: [PATCH] some fixes and cleanup per feedback from Matt Hite --- library/net_infrastructure/bigip_monitor_http | 37 ++++++++++++++----- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/library/net_infrastructure/bigip_monitor_http b/library/net_infrastructure/bigip_monitor_http index e9a8d683de..de5d8e7721 100644 --- a/library/net_infrastructure/bigip_monitor_http +++ b/library/net_infrastructure/bigip_monitor_http @@ -73,7 +73,7 @@ options: aliases: ['monitor'] partition: description: - - Partition + - Partition for the monitor required: false default: 'Common' choices: [] @@ -85,6 +85,13 @@ options: default: 'http' choices: [] aliases: [] + parent_partition: + description: + - Partition for the parent monitor + required: false + default: 'Common' + choices: [] + aliases: [] send: description: required: true @@ -147,7 +154,14 @@ def monitor_exists(module, api, monitor, parent): def create_monitor(api, monitor, template_attributes): - api.LocalLB.Monitor.create_template(templates=[{'template_name': monitor, 'template_type': TEMPLATE_TYPE}], template_attributes=[template_attributes]) + try: + api.LocalLB.Monitor.create_template(templates=[{'template_name': monitor, 'template_type': TEMPLATE_TYPE}], template_attributes=[template_attributes]) + except bigsuds.OperationFailed, e: + if "already exists" in str(e): + pass + else: + # genuine exception + raise def delete_monitor(api, monitor): @@ -173,6 +187,9 @@ def set_string_property(api, monitor, str_property): # =========================================== # main loop # +# writing a module for other monitor types should +# only need an updated main() + def main(): @@ -185,6 +202,7 @@ def main(): state = dict(default='present', choices=['present', 'absent']), name = dict(required=True), parent = dict(default=DEFAULT_PARENT_TYPE), + parent_partition = dict(default='Common'), send = dict(required=True), receive = dict(required=True) ), @@ -198,15 +216,14 @@ def main(): user = module.params['user'] password = module.params['password'] partition = module.params['partition'] + parent_partition = module.params['parent_partition'] state = module.params['state'] name = module.params['name'] - parent = "/%s/%s" % (partition, module.params['parent']) + parent = "/%s/%s" % (parent_partition, module.params['parent']) monitor = "/%s/%s" % (partition, name) send = module.params['send'] receive = module.params['receive'] - # sanity check user supplied values - # main logic @@ -239,15 +256,17 @@ def main(): if monitor_exists(module, api, monitor, parent): for str_property in template_string_properties: if not check_string_property(api, monitor, str_property): - set_string_property(api, monitor, str_property) + if not module.check_mode: + set_string_property(api, monitor, str_property) result['changed'] = True - else: - print (api, monitor, template_attributes) + elif not module.check_mode: create_monitor(api, monitor, template_attributes) - print "check" for str_property in template_string_properties: set_string_property(api, monitor, str_property) result['changed'] = True + else: # monitor does not exist and check mode + result['changed'] = True + except Exception, e: module.fail_json(msg="received exception: %s" % e)