Eliminate redundant module argument checks.
This commit is contained in:
parent
6b753c5c71
commit
23c79ed474
5 changed files with 4 additions and 47 deletions
|
@ -105,17 +105,6 @@ except ImportError:
|
||||||
def alarm(module, state, label, entity_id, check_id, notification_plan_id, criteria,
|
def alarm(module, state, label, entity_id, check_id, notification_plan_id, criteria,
|
||||||
disabled, metadata):
|
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:
|
if len(label) < 1 or len(label) > 255:
|
||||||
module.fail_json(msg='label must be between 1 and 255 characters long')
|
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,
|
criteria=criteria, disabled=disabled, label=label,
|
||||||
metadata=metadata)
|
metadata=metadata)
|
||||||
changed = True
|
changed = True
|
||||||
elif state == 'absent':
|
else:
|
||||||
for a in existing:
|
for a in existing:
|
||||||
a.delete()
|
a.delete()
|
||||||
changed = True
|
changed = True
|
||||||
else:
|
|
||||||
module.fail_json(msg='state must be either present or absent.')
|
|
||||||
|
|
||||||
if alarm:
|
if alarm:
|
||||||
alarm_dict = {
|
alarm_dict = {
|
||||||
|
|
|
@ -141,16 +141,6 @@ def cloud_check(module, state, entity_id, label, check_type,
|
||||||
monitoring_zones_poll, target_hostname, target_alias, details,
|
monitoring_zones_poll, target_hostname, target_alias, details,
|
||||||
disabled, metadata, period, timeout):
|
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.
|
# Coerce attributes.
|
||||||
|
|
||||||
if monitoring_zones_poll and not isinstance(monitoring_zones_poll, list):
|
if monitoring_zones_poll and not isinstance(monitoring_zones_poll, list):
|
||||||
|
|
|
@ -83,8 +83,6 @@ except ImportError:
|
||||||
|
|
||||||
def cloud_monitoring(module, state, label, agent_id, named_ip_addresses,
|
def cloud_monitoring(module, state, label, agent_id, named_ip_addresses,
|
||||||
metadata):
|
metadata):
|
||||||
if not label:
|
|
||||||
module.fail_json(msg='label is required for rax_mon_entity')
|
|
||||||
|
|
||||||
if len(label) < 1 or len(label) > 255:
|
if len(label) < 1 or len(label) > 255:
|
||||||
module.fail_json(msg='label must be between 1 and 255 characters long')
|
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,
|
ip_addresses=named_ip_addresses,
|
||||||
metadata=metadata)
|
metadata=metadata)
|
||||||
changed = True
|
changed = True
|
||||||
elif state == 'absent':
|
else:
|
||||||
# Delete the existing Entities.
|
# Delete the existing Entities.
|
||||||
for e in existing:
|
for e in existing:
|
||||||
e.delete()
|
e.delete()
|
||||||
changed = True
|
changed = True
|
||||||
else:
|
|
||||||
module.fail_json(msg='state must be present or absent')
|
|
||||||
|
|
||||||
if entity:
|
if entity:
|
||||||
entity_dict = {
|
entity_dict = {
|
||||||
|
|
|
@ -76,18 +76,9 @@ except ImportError:
|
||||||
|
|
||||||
def notification(module, state, label, notification_type, details):
|
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:
|
if len(label) < 1 or len(label) > 255:
|
||||||
module.fail_json(msg='label must be between 1 and 255 characters long')
|
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
|
changed = False
|
||||||
notification = None
|
notification = None
|
||||||
|
|
||||||
|
@ -132,12 +123,10 @@ def notification(module, state, label, notification_type, details):
|
||||||
notification = cm.create_notification(notification_type,
|
notification = cm.create_notification(notification_type,
|
||||||
label=label, details=details)
|
label=label, details=details)
|
||||||
changed = True
|
changed = True
|
||||||
elif state == 'absent':
|
else:
|
||||||
for n in existing:
|
for n in existing:
|
||||||
n.delete()
|
n.delete()
|
||||||
changed = True
|
changed = True
|
||||||
else:
|
|
||||||
module.fail_json(msg='state must be either "present" or "absent"')
|
|
||||||
|
|
||||||
if notification:
|
if notification:
|
||||||
notification_dict = {
|
notification_dict = {
|
||||||
|
|
|
@ -80,9 +80,6 @@ except ImportError:
|
||||||
|
|
||||||
def notification_plan(module, state, label, critical_state, warning_state, ok_state):
|
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:
|
if len(label) < 1 or len(label) > 255:
|
||||||
module.fail_json(msg='label must be between 1 and 255 characters long')
|
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,
|
warning_state=warning_state,
|
||||||
ok_state=ok_state)
|
ok_state=ok_state)
|
||||||
changed = True
|
changed = True
|
||||||
elif state == 'absent':
|
else:
|
||||||
for np in existing:
|
for np in existing:
|
||||||
np.delete()
|
np.delete()
|
||||||
changed = True
|
changed = True
|
||||||
else:
|
|
||||||
module.fail_json(msg='state must be either "present" or "absent"')
|
|
||||||
|
|
||||||
if notification_plan:
|
if notification_plan:
|
||||||
notification_plan_dict = {
|
notification_plan_dict = {
|
||||||
|
|
Loading…
Reference in a new issue