mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-19 03:10:22 -07:00
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']
|
aliases: ['monitor']
|
||||||
partition:
|
partition:
|
||||||
description:
|
description:
|
||||||
- Partition
|
- Partition for the monitor
|
||||||
required: false
|
required: false
|
||||||
default: 'Common'
|
default: 'Common'
|
||||||
choices: []
|
choices: []
|
||||||
|
@ -85,6 +85,13 @@ options:
|
||||||
default: 'http'
|
default: 'http'
|
||||||
choices: []
|
choices: []
|
||||||
aliases: []
|
aliases: []
|
||||||
|
parent_partition:
|
||||||
|
description:
|
||||||
|
- Partition for the parent monitor
|
||||||
|
required: false
|
||||||
|
default: 'Common'
|
||||||
|
choices: []
|
||||||
|
aliases: []
|
||||||
send:
|
send:
|
||||||
description:
|
description:
|
||||||
required: true
|
required: true
|
||||||
|
@ -147,7 +154,14 @@ def monitor_exists(module, api, monitor, parent):
|
||||||
|
|
||||||
def create_monitor(api, monitor, template_attributes):
|
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):
|
def delete_monitor(api, monitor):
|
||||||
|
@ -173,6 +187,9 @@ def set_string_property(api, monitor, str_property):
|
||||||
# ===========================================
|
# ===========================================
|
||||||
# main loop
|
# main loop
|
||||||
#
|
#
|
||||||
|
# writing a module for other monitor types should
|
||||||
|
# only need an updated main()
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
|
|
||||||
|
@ -185,6 +202,7 @@ def main():
|
||||||
state = dict(default='present', choices=['present', 'absent']),
|
state = dict(default='present', choices=['present', 'absent']),
|
||||||
name = dict(required=True),
|
name = dict(required=True),
|
||||||
parent = dict(default=DEFAULT_PARENT_TYPE),
|
parent = dict(default=DEFAULT_PARENT_TYPE),
|
||||||
|
parent_partition = dict(default='Common'),
|
||||||
send = dict(required=True),
|
send = dict(required=True),
|
||||||
receive = dict(required=True)
|
receive = dict(required=True)
|
||||||
),
|
),
|
||||||
|
@ -198,15 +216,14 @@ def main():
|
||||||
user = module.params['user']
|
user = module.params['user']
|
||||||
password = module.params['password']
|
password = module.params['password']
|
||||||
partition = module.params['partition']
|
partition = module.params['partition']
|
||||||
|
parent_partition = module.params['parent_partition']
|
||||||
state = module.params['state']
|
state = module.params['state']
|
||||||
name = module.params['name']
|
name = module.params['name']
|
||||||
parent = "/%s/%s" % (partition, module.params['parent'])
|
parent = "/%s/%s" % (parent_partition, module.params['parent'])
|
||||||
monitor = "/%s/%s" % (partition, name)
|
monitor = "/%s/%s" % (partition, name)
|
||||||
send = module.params['send']
|
send = module.params['send']
|
||||||
receive = module.params['receive']
|
receive = module.params['receive']
|
||||||
|
|
||||||
# sanity check user supplied values
|
|
||||||
|
|
||||||
|
|
||||||
# main logic
|
# main logic
|
||||||
|
|
||||||
|
@ -239,15 +256,17 @@ def main():
|
||||||
if monitor_exists(module, api, monitor, parent):
|
if monitor_exists(module, api, monitor, parent):
|
||||||
for str_property in template_string_properties:
|
for str_property in template_string_properties:
|
||||||
if not check_string_property(api, monitor, str_property):
|
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
|
result['changed'] = True
|
||||||
else:
|
elif not module.check_mode:
|
||||||
print (api, monitor, template_attributes)
|
|
||||||
create_monitor(api, monitor, template_attributes)
|
create_monitor(api, monitor, template_attributes)
|
||||||
print "check"
|
|
||||||
for str_property in template_string_properties:
|
for str_property in template_string_properties:
|
||||||
set_string_property(api, monitor, str_property)
|
set_string_property(api, monitor, str_property)
|
||||||
result['changed'] = True
|
result['changed'] = True
|
||||||
|
else: # monitor does not exist and check mode
|
||||||
|
result['changed'] = True
|
||||||
|
|
||||||
|
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
module.fail_json(msg="received exception: %s" % e)
|
module.fail_json(msg="received exception: %s" % e)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue