diff --git a/fm-rest-api/fm/fm/api/controllers/v1/alarm.py b/fm-rest-api/fm/fm/api/controllers/v1/alarm.py index 5c59c9ae..2d90552f 100644 --- a/fm-rest-api/fm/fm/api/controllers/v1/alarm.py +++ b/fm-rest-api/fm/fm/api/controllers/v1/alarm.py @@ -78,10 +78,10 @@ class Alarm(base.APIBase): proposed_repair_action = wtypes.text "The action to clear the alarm" - service_affecting = wtypes.text + service_affecting = bool "Whether the alarm affects the service" - suppression = wtypes.text + suppression = bool "'allowed' or 'not-allowed'" suppression_status = wtypes.text @@ -114,8 +114,8 @@ class Alarm(base.APIBase): mgmt_affecting = rpc_ialarm.mgmt_affecting degrade_affecting = rpc_ialarm.degrade_affecting - alarms['service_affecting'] = str(alarms['service_affecting']) - alarms['suppression'] = str(alarms['suppression']) + alarms['service_affecting'] = alarms['service_affecting'] + alarms['suppression'] = alarms['suppression'] alm = Alarm(**alarms.as_dict()) if not expand: diff --git a/fm-rest-api/fm/fm/api/controllers/v1/event_log.py b/fm-rest-api/fm/fm/api/controllers/v1/event_log.py index d39a1e23..ae78e195 100644 --- a/fm-rest-api/fm/fm/api/controllers/v1/event_log.py +++ b/fm-rest-api/fm/fm/api/controllers/v1/event_log.py @@ -79,10 +79,10 @@ class EventLog(base.APIBase): proposed_repair_action = wtypes.text "The action to clear the alarm" - service_affecting = wtypes.text + service_affecting = bool "Whether the log affects the service" - suppression = wtypes.text + suppression = bool "'allowed' or 'not-allowed'" suppression_status = wtypes.text @@ -107,8 +107,8 @@ class EventLog(base.APIBase): ievent_log = rpc_event_log suppress_status = rpc_event_log.suppression_status - ievent_log['service_affecting'] = str(ievent_log['service_affecting']) - ievent_log['suppression'] = str(ievent_log['suppression']) + ievent_log['service_affecting'] = ievent_log['service_affecting'] + ievent_log['suppression'] = ievent_log['suppression'] ilog = EventLog(**ievent_log.as_dict()) if not expand: diff --git a/fm-rest-api/fm/fm/objects/alarm.py b/fm-rest-api/fm/fm/objects/alarm.py index 1229c497..26e7731d 100755 --- a/fm-rest-api/fm/fm/objects/alarm.py +++ b/fm-rest-api/fm/fm/objects/alarm.py @@ -31,10 +31,10 @@ class Alarm(base.FmObject): 'alarm_type': utils.str_or_none, 'probable_cause': utils.str_or_none, 'proposed_repair_action': utils.str_or_none, - 'service_affecting': utils.str_or_none, - 'suppression': utils.str_or_none, - 'inhibit_alarms': utils.str_or_none, - 'masked': utils.str_or_none, + 'service_affecting': utils.bool_or_none, + 'suppression': utils.bool_or_none, + 'inhibit_alarms': utils.bool_or_none, + 'masked': utils.bool_or_none, 'suppression_status': utils.str_or_none, 'mgmt_affecting': utils.str_or_none, 'degrade_affecting': utils.str_or_none, diff --git a/fm-rest-api/fm/fm/objects/event_log.py b/fm-rest-api/fm/fm/objects/event_log.py index 2964cab9..ef550883 100644 --- a/fm-rest-api/fm/fm/objects/event_log.py +++ b/fm-rest-api/fm/fm/objects/event_log.py @@ -33,8 +33,8 @@ class EventLog(base.FmObject): 'event_log_type': utils.str_or_none, 'probable_cause': utils.str_or_none, 'proposed_repair_action': utils.str_or_none, - 'service_affecting': utils.str_or_none, - 'suppression': utils.str_or_none, + 'service_affecting': utils.bool_or_none, + 'suppression': utils.bool_or_none, 'suppression_status': utils.str_or_none, } diff --git a/fm-rest-api/fm/fm/objects/utils.py b/fm-rest-api/fm/fm/objects/utils.py index 459381a4..daf4ca0d 100644 --- a/fm-rest-api/fm/fm/objects/utils.py +++ b/fm-rest-api/fm/fm/objects/utils.py @@ -50,6 +50,16 @@ def datetime_or_str_or_none(val): return datetime_or_none(val) +def bool_or_none(val): + """Attempt to parse an boolean value, or None.""" + if val is None: + return False + elif isinstance(val, six.string_types): + return bool(val.lower() in ['y', 'n', 'yes', 'no', 'true', 'false']) + else: + return bool(int(val) != 0) + + def int_or_none(val): """Attempt to parse an integer value, or None.""" if val is None: