some fixes and cleanup per feedback from Matt Hite
This commit is contained in:
parent
2005332e7b
commit
940419d085
1 changed files with 28 additions and 9 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue