Base Alarm history persistence model

Provides the storage model and non-implemented hooks
into the storage drivers as a placeholder.

Partially implements bp alarm-audit-api

Change-Id: I950bef5f01e545982709bfb78a2364fb8d4def7b
This commit is contained in:
Eoghan Glynn 2013-08-10 21:16:28 +00:00
parent 9adbc082b2
commit e775ac06c6
7 changed files with 119 additions and 0 deletions

View File

@ -205,6 +205,19 @@ class Connection(object):
"""Delete a alarm
"""
@abc.abstractmethod
def get_alarm_changes(self, alarm_id, on_behalf_of):
"""Yields list of AlarmChanges describing alarm history
:param alarm_id: ID of alarm to return changes for
:param on_behalf_of: ID of tenant to scope changes query (None for
administrative user, indicating all projects)
"""
@abc.abstractmethod
def record_alarm_change(self, alarm_change):
"""Record alarm change event.
"""
@abc.abstractmethod
def clear(self):
"""Clear database."""

View File

@ -616,6 +616,19 @@ class Connection(base.Connection):
"""
self.db.alarm.remove({'alarm_id': alarm_id})
def get_alarm_changes(self, alarm_id, on_behalf_of):
"""Yields list of AlarmChanges describing alarm history
:param alarm_id: ID of alarm to return changes for
:param on_behalf_of: ID of tenant to scope changes query (None for
administrative user, indicating all projects)
"""
raise NotImplementedError('Alarm history not implemented')
def record_alarm_change(self, alarm_change):
"""Record alarm change event.
"""
raise NotImplementedError('Alarm history not implemented')
@staticmethod
def record_events(events):
"""Write the events.

View File

@ -609,6 +609,19 @@ class Connection(base.Connection):
"""
raise NotImplementedError('Alarms not implemented')
def get_alarm_changes(self, alarm_id, on_behalf_of):
"""Yields list of AlarmChanges describing alarm history
:param alarm_id: ID of alarm to return changes for
:param on_behalf_of: ID of tenant to scope changes query (None for
administrative user, indicating all projects)
"""
raise NotImplementedError('Alarm history not implemented')
def record_alarm_change(self, alarm_change):
"""Record alarm change event.
"""
raise NotImplementedError('Alarm history not implemented')
def delete_alarm(self, alarm_id):
"""Delete a alarm
"""

View File

@ -175,6 +175,19 @@ class Connection(base.Connection):
"""Delete a alarm
"""
def get_alarm_changes(self, alarm_id, on_behalf_of):
"""Yields list of AlarmChanges describing alarm history
:param alarm_id: ID of alarm to return changes for
:param on_behalf_of: ID of tenant to scope changes query (None for
administrative user, indicating all projects)
"""
raise NotImplementedError('Alarm history not implemented')
def record_alarm_change(self, alarm_change):
"""Record alarm change event.
"""
raise NotImplementedError('Alarm history not implemented')
def record_events(self, events):
"""Write the events.

View File

@ -865,6 +865,19 @@ class Connection(base.Connection):
"""
self.db.alarm.remove({'alarm_id': alarm_id})
def get_alarm_changes(self, alarm_id, on_behalf_of):
"""Yields list of AlarmChanges describing alarm history
:param alarm_id: ID of alarm to return changes for
:param on_behalf_of: ID of tenant to scope changes query (None for
administrative user, indicating all projects)
"""
raise NotImplementedError('Alarm history not implemented')
def record_alarm_change(self, alarm_change):
"""Record alarm change event.
"""
raise NotImplementedError('Alarm history not implemented')
@staticmethod
def record_events(events):
"""Write the events.

View File

@ -646,6 +646,19 @@ class Connection(base.Connection):
session.query(Alarm).filter(Alarm.id == alarm_id).delete()
session.flush()
def get_alarm_changes(self, alarm_id, on_behalf_of):
"""Yields list of AlarmChanges describing alarm history
:param alarm_id: ID of alarm to return changes for
:param on_behalf_of: ID of tenant to scope changes query (None for
administrative user, indicating all projects)
"""
raise NotImplementedError('Alarm history not implemented')
def record_alarm_change(self, alarm_change):
"""Record alarm change event.
"""
raise NotImplementedError('Alarm history not implemented')
@staticmethod
def _get_unique(session, key):
return session.query(UniqueName).filter(UniqueName.key == key).first()

View File

@ -322,3 +322,44 @@ class Alarm(Model):
insufficient_data_actions,
repeat_actions=repeat_actions,
matching_metadata=matching_metadata)
class AlarmChange(Model):
"""Record of an alarm change.
:param event_id: UUID of the change event
:param alarm_id: UUID of the alarm
:param type: The type of change
:param detail: JSON fragment describing change
:param user_id: the user ID of the initiating identity
:param project_id: the project ID of the initiating identity
:param on_behalf_of: the tenant on behalf of which the change
is being made
:param timestamp: the timestamp of the change
"""
CREATION = 'creation'
RULE_CHANGE = 'rule change'
STATE_TRANSITION = 'state transition'
DELETION = 'deletion'
def __init__(self,
event_id,
alarm_id,
type,
detail,
user_id,
project_id,
on_behalf_of,
timestamp=None
):
Model.__init__(
self,
event_id=event_id,
alarm_id=alarm_id,
type=type,
detail=detail,
user_id=user_id,
project_id=project_id,
on_behalf_of=on_behalf_of,
timestamp=timestamp)