1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Eliminate redundant module argument checks.

This commit is contained in:
Ash Wilson 2015-02-23 14:33:02 -06:00 committed by Matt Clay
parent 6b753c5c71
commit 23c79ed474
5 changed files with 4 additions and 47 deletions

View file

@ -105,17 +105,6 @@ except ImportError:
def alarm(module, state, label, entity_id, check_id, notification_plan_id, criteria,
disabled, metadata):
# Verify the presence of required attributes.
required_attrs = {
"label": label, "entity_id": entity_id, "check_id": check_id,
"notification_plan_id": notification_plan_id
}
for (key, value) in required_attrs.iteritems():
if not value:
module.fail_json(msg=('%s is required for rax_mon_alarm' % key))
if len(label) < 1 or len(label) > 255:
module.fail_json(msg='label must be between 1 and 255 characters long')
@ -173,12 +162,10 @@ def alarm(module, state, label, entity_id, check_id, notification_plan_id, crite
criteria=criteria, disabled=disabled, label=label,
metadata=metadata)
changed = True
elif state == 'absent':
else:
for a in existing:
a.delete()
changed = True
else:
module.fail_json(msg='state must be either present or absent.')
if alarm:
alarm_dict = {

View file

@ -141,16 +141,6 @@ def cloud_check(module, state, entity_id, label, check_type,
monitoring_zones_poll, target_hostname, target_alias, details,
disabled, metadata, period, timeout):
# Verify the presence of required attributes.
required_attrs = {
"entity_id": entity_id, "label": label, "check_type": check_type
}
for (key, value) in required_attrs.iteritems():
if not value:
module.fail_json(msg=('%s is required for rax_mon_check' % key))
# Coerce attributes.
if monitoring_zones_poll and not isinstance(monitoring_zones_poll, list):

View file

@ -83,8 +83,6 @@ except ImportError:
def cloud_monitoring(module, state, label, agent_id, named_ip_addresses,
metadata):
if not label:
module.fail_json(msg='label is required for rax_mon_entity')
if len(label) < 1 or len(label) > 255:
module.fail_json(msg='label must be between 1 and 255 characters long')
@ -139,13 +137,11 @@ def cloud_monitoring(module, state, label, agent_id, named_ip_addresses,
ip_addresses=named_ip_addresses,
metadata=metadata)
changed = True
elif state == 'absent':
else:
# Delete the existing Entities.
for e in existing:
e.delete()
changed = True
else:
module.fail_json(msg='state must be present or absent')
if entity:
entity_dict = {

View file

@ -76,18 +76,9 @@ except ImportError:
def notification(module, state, label, notification_type, details):
if not label:
module.fail_json(msg='label is required for rax_mon_notification')
if len(label) < 1 or len(label) > 255:
module.fail_json(msg='label must be between 1 and 255 characters long')
if not notification_type:
module.fail_json(msg='you must provide a notification_type')
if not details:
module.fail_json(msg='notification details are required')
changed = False
notification = None
@ -132,12 +123,10 @@ def notification(module, state, label, notification_type, details):
notification = cm.create_notification(notification_type,
label=label, details=details)
changed = True
elif state == 'absent':
else:
for n in existing:
n.delete()
changed = True
else:
module.fail_json(msg='state must be either "present" or "absent"')
if notification:
notification_dict = {

View file

@ -80,9 +80,6 @@ except ImportError:
def notification_plan(module, state, label, critical_state, warning_state, ok_state):
if not label:
module.fail_json(msg='label is required for rax_mon_notification_plan')
if len(label) < 1 or len(label) > 255:
module.fail_json(msg='label must be between 1 and 255 characters long')
@ -128,12 +125,10 @@ def notification_plan(module, state, label, critical_state, warning_state, ok_st
warning_state=warning_state,
ok_state=ok_state)
changed = True
elif state == 'absent':
else:
for np in existing:
np.delete()
changed = True
else:
module.fail_json(msg='state must be either "present" or "absent"')
if notification_plan:
notification_plan_dict = {