add name for audit, changes for watcher api/db

Change-Id: Ibe04f5375d741d15999fde6faf767f15311c6351
Implements:blueprint add-name-for-audit
This commit is contained in:
suzhengwei
2017-06-19 18:57:44 +08:00
parent 50935af15f
commit d7d56cbd79
17 changed files with 215 additions and 74 deletions

View File

@@ -86,13 +86,15 @@ class Audit(base.WatcherPersistentObject, base.WatcherObject,
# Version 1.2: Added 'auto_trigger' boolean field
# Version 1.3: Added 'next_run_time' DateTime field,
# 'interval' type has been changed from Integer to String
VERSION = '1.3'
# Version 1.4: Added 'name' string field
VERSION = '1.4'
dbapi = db_api.get_instance()
fields = {
'id': wfields.IntegerField(),
'uuid': wfields.UUIDField(),
'name': wfields.StringField(),
'audit_type': wfields.StringField(),
'state': wfields.StringField(),
'parameters': wfields.FlexibleDictField(nullable=True),
@@ -204,6 +206,25 @@ class Audit(base.WatcherPersistentObject, base.WatcherObject,
audit = cls._from_db_object(cls(context), db_audit, eager=eager)
return audit
@base.remotable_classmethod
def get_by_name(cls, context, name, eager=False):
"""Find an audit based on name and return a :class:`Audit` object.
:param context: Security context. NOTE: This should only
be used internally by the indirection_api.
Unfortunately, RPC requires context as the first
argument, even though we don't use it.
A context should be set when instantiating the
object, e.g.: Audit(context)
:param name: the name of an audit.
:param eager: Load object fields if True (Default: False)
:returns: a :class:`Audit` object.
"""
db_audit = cls.dbapi.get_audit_by_name(context, name, eager=eager)
audit = cls._from_db_object(cls(context), db_audit, eager=eager)
return audit
@base.remotable_classmethod
def list(cls, context, limit=None, marker=None, filters=None,
sort_key=None, sort_dir=None, eager=False):