class TerseActionPlanPayload(notificationbase.NotificationPayloadBase): SCHEMA = { 'uuid': ('action_plan', 'uuid'), 'state': ('action_plan', 'state'), 'global_efficacy': ('action_plan', 'global_efficacy'), 'created_at': ('action_plan', 'created_at'), 'updated_at': ('action_plan', 'updated_at'), 'deleted_at': ('action_plan', 'deleted_at'), } # Version 1.0: Initial version # Version 1.1: Changed 'global_efficacy' type Dictionary to List VERSION = '1.1' fields = { 'uuid': wfields.UUIDField(), 'state': wfields.StringField(), 'global_efficacy': wfields.FlexibleListOfDictField(nullable=True), 'audit_uuid': wfields.UUIDField(), 'strategy_uuid': wfields.UUIDField(nullable=True), 'created_at': wfields.DateTimeField(nullable=True), 'updated_at': wfields.DateTimeField(nullable=True), 'deleted_at': wfields.DateTimeField(nullable=True), } def __init__(self, action_plan, audit=None, strategy=None, **kwargs): super(TerseActionPlanPayload, self).__init__(audit=audit, strategy=strategy, **kwargs) self.populate_schema(action_plan=action_plan)
class TerseAuditPayload(notificationbase.NotificationPayloadBase): SCHEMA = { 'uuid': ('audit', 'uuid'), 'audit_type': ('audit', 'audit_type'), 'state': ('audit', 'state'), 'parameters': ('audit', 'parameters'), 'interval': ('audit', 'interval'), 'scope': ('audit', 'scope'), 'created_at': ('audit', 'created_at'), 'updated_at': ('audit', 'updated_at'), 'deleted_at': ('audit', 'deleted_at'), } # Version 1.0: Initial version VERSION = '1.0' fields = { 'uuid': wfields.UUIDField(), 'audit_type': wfields.StringField(), 'state': wfields.StringField(), 'parameters': wfields.FlexibleDictField(nullable=True), 'interval': wfields.IntegerField(nullable=True), 'scope': wfields.FlexibleListOfDictField(nullable=True), 'goal_uuid': wfields.UUIDField(), 'strategy_uuid': wfields.UUIDField(nullable=True), 'created_at': wfields.DateTimeField(nullable=True), 'updated_at': wfields.DateTimeField(nullable=True), 'deleted_at': wfields.DateTimeField(nullable=True), } def __init__(self, audit, goal_uuid, strategy_uuid=None, **kwargs): super(TerseAuditPayload, self).__init__(goal_uuid=goal_uuid, strategy_uuid=strategy_uuid, **kwargs) self.populate_schema(audit=audit)
class GoalPayload(notificationbase.NotificationPayloadBase): SCHEMA = { 'uuid': ('goal', 'uuid'), 'name': ('goal', 'name'), 'display_name': ('goal', 'display_name'), 'efficacy_specification': ('goal', 'efficacy_specification'), 'created_at': ('goal', 'created_at'), 'updated_at': ('goal', 'updated_at'), 'deleted_at': ('goal', 'deleted_at'), } # Version 1.0: Initial version VERSION = '1.0' fields = { 'uuid': wfields.UUIDField(), 'name': wfields.StringField(), 'display_name': wfields.StringField(), 'efficacy_specification': wfields.FlexibleListOfDictField(), 'created_at': wfields.DateTimeField(nullable=True), 'updated_at': wfields.DateTimeField(nullable=True), 'deleted_at': wfields.DateTimeField(nullable=True), } def __init__(self, goal, **kwargs): super(GoalPayload, self).__init__(**kwargs) self.populate_schema(goal=goal)
class Volume(storage_resource.StorageResource): fields = { "size": wfields.NonNegativeIntegerField(), "status": wfields.StringField(default=VolumeState.AVAILABLE.value), "attachments": wfields.FlexibleListOfDictField(), "name": wfields.StringField(), "multiattach": wfields.BooleanField(), "snapshot_id": wfields.UUIDField(), "project_id": wfields.UUIDField(), "metadata": wfields.JsonField(), "bootable": wfields.BooleanField() } def accept(self, visitor): raise NotImplementedError()
class TerseAuditPayload(notificationbase.NotificationPayloadBase): SCHEMA = { 'uuid': ('audit', 'uuid'), 'name': ('audit', 'name'), 'audit_type': ('audit', 'audit_type'), 'state': ('audit', 'state'), 'parameters': ('audit', 'parameters'), 'interval': ('audit', 'interval'), 'scope': ('audit', 'scope'), 'auto_trigger': ('audit', 'auto_trigger'), 'next_run_time': ('audit', 'next_run_time'), 'created_at': ('audit', 'created_at'), 'updated_at': ('audit', 'updated_at'), 'deleted_at': ('audit', 'deleted_at'), } # Version 1.0: Initial version # Version 1.1: Added 'auto_trigger' boolean field, # Added 'next_run_time' DateTime field, # 'interval' type has been changed from Integer to String # Version 1.2: Added 'name' string field VERSION = '1.2' fields = { 'uuid': wfields.UUIDField(), 'name': wfields.StringField(), 'audit_type': wfields.StringField(), 'state': wfields.StringField(), 'parameters': wfields.FlexibleDictField(nullable=True), 'interval': wfields.StringField(nullable=True), 'scope': wfields.FlexibleListOfDictField(nullable=True), 'goal_uuid': wfields.UUIDField(), 'strategy_uuid': wfields.UUIDField(nullable=True), 'auto_trigger': wfields.BooleanField(), 'next_run_time': wfields.DateTimeField(nullable=True), 'created_at': wfields.DateTimeField(nullable=True), 'updated_at': wfields.DateTimeField(nullable=True), 'deleted_at': wfields.DateTimeField(nullable=True), } def __init__(self, audit, goal_uuid, strategy_uuid=None, **kwargs): super(TerseAuditPayload, self).__init__(goal_uuid=goal_uuid, strategy_uuid=strategy_uuid, **kwargs) self.populate_schema(audit=audit)
class Audit(base.WatcherPersistentObject, base.WatcherObject, base.WatcherObjectDictCompat): # Version 1.0: Initial version # Version 1.1: Added 'goal' and 'strategy' object field # Version 1.2 Added 'auto_trigger' boolean field VERSION = '1.2' dbapi = db_api.get_instance() fields = { 'id': wfields.IntegerField(), 'uuid': wfields.UUIDField(), 'audit_type': wfields.StringField(), 'state': wfields.StringField(), 'parameters': wfields.FlexibleDictField(nullable=True), 'interval': wfields.IntegerField(nullable=True), 'scope': wfields.FlexibleListOfDictField(nullable=True), 'goal_id': wfields.IntegerField(), 'strategy_id': wfields.IntegerField(nullable=True), 'auto_trigger': wfields.BooleanField(), 'goal': wfields.ObjectField('Goal', nullable=True), 'strategy': wfields.ObjectField('Strategy', nullable=True), } object_fields = { 'goal': (objects.Goal, 'goal_id'), 'strategy': (objects.Strategy, 'strategy_id'), } # Proxified field so we can keep the previous value after an update _state = None _old_state = None # NOTE(v-francoise): The way oslo.versionedobjects works is by using a # __new__ that will automatically create the attributes referenced in # fields. These attributes are properties that raise an exception if no # value has been assigned, which means that they store the actual field # value in an "_obj_%(field)s" attribute. So because we want to proxify a # value that is already proxified, we have to do what you see below. @property def _obj_state(self): return self._state @property def _obj_old_state(self): return self._old_state @property def old_state(self): return self._old_state @_obj_old_state.setter def _obj_old_state(self, value): self._old_state = value @_obj_state.setter def _obj_state(self, value): if self._old_state is None and self._state is None: self._state = value else: self._old_state, self._state = self._state, value @base.remotable_classmethod def get(cls, context, audit_id, eager=False): """Find a audit based on its id or uuid and return a 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 audit_id: the id *or* uuid of a audit. :param eager: Load object fields if True (Default: False) :returns: a :class:`Audit` object. """ if utils.is_int_like(audit_id): return cls.get_by_id(context, audit_id, eager=eager) elif utils.is_uuid_like(audit_id): return cls.get_by_uuid(context, audit_id, eager=eager) else: raise exception.InvalidIdentity(identity=audit_id) @base.remotable_classmethod def get_by_id(cls, context, audit_id, eager=False): """Find a audit based on its integer id and return a 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 audit_id: the id of a audit. :param eager: Load object fields if True (Default: False) :returns: a :class:`Audit` object. """ db_audit = cls.dbapi.get_audit_by_id(context, audit_id, eager=eager) audit = cls._from_db_object(cls(context), db_audit, eager=eager) return audit @base.remotable_classmethod def get_by_uuid(cls, context, uuid, eager=False): """Find a audit based on uuid 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 uuid: the uuid of a audit. :param eager: Load object fields if True (Default: False) :returns: a :class:`Audit` object. """ db_audit = cls.dbapi.get_audit_by_uuid(context, uuid, 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): """Return a list of Audit objects. :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 limit: maximum number of resources to return in a single result. :param marker: pagination marker for large data sets. :param filters: Filters to apply. Defaults to None. :param sort_key: column to sort results by. :param sort_dir: direction to sort. "asc" or "desc". :param eager: Load object fields if True (Default: False) :returns: a list of :class:`Audit` object. """ db_audits = cls.dbapi.get_audit_list(context, limit=limit, marker=marker, filters=filters, sort_key=sort_key, sort_dir=sort_dir, eager=eager) return [cls._from_db_object(cls(context), obj, eager=eager) for obj in db_audits] @base.remotable def create(self): """Create an :class:`Audit` record in the DB. :returns: An :class:`Audit` object. """ values = self.obj_get_changes() db_audit = self.dbapi.create_audit(values) # Note(v-francoise): Always load eagerly upon creation so we can send # notifications containing information about the related relationships self._from_db_object(self, db_audit, eager=True) def _notify(): notifications.audit.send_create(self._context, self) _notify() @base.remotable def destroy(self): """Delete the Audit from the DB.""" self.dbapi.destroy_audit(self.uuid) self.obj_reset_changes() @base.remotable def save(self): """Save updates to this Audit. Updates will be made column by column based on the result of self.what_changed(). """ updates = self.obj_get_changes() db_obj = self.dbapi.update_audit(self.uuid, updates) obj = self._from_db_object( self.__class__(self._context), db_obj, eager=False) self.obj_refresh(obj) def _notify(): notifications.audit.send_update( self._context, self, old_state=self.old_state) _notify() self.obj_reset_changes() @base.remotable def refresh(self, eager=False): """Loads updates for this Audit. Loads a audit with the same uuid from the database and checks for updated attributes. Updates are applied from the loaded audit column by column, if there are any updates. :param eager: Load object fields if True (Default: False) """ current = self.get_by_uuid(self._context, uuid=self.uuid, eager=eager) self.obj_refresh(current) @base.remotable def soft_delete(self): """Soft Delete the Audit from the DB.""" self.state = State.DELETED self.save() db_obj = self.dbapi.soft_delete_audit(self.uuid) obj = self._from_db_object( self.__class__(self._context), db_obj, eager=False) self.obj_refresh(obj) def _notify(): notifications.audit.send_delete(self._context, self) _notify()
class ActionPlan(base.WatcherPersistentObject, base.WatcherObject, base.WatcherObjectDictCompat): # Version 1.0: Initial version # Version 1.1: Added 'audit' and 'strategy' object field # Version 1.2: audit_id is not nullable anymore # Version 2.0: Removed 'first_action_id' object field # Version 2.1: Changed global_efficacy type VERSION = '2.1' dbapi = db_api.get_instance() fields = { 'id': wfields.IntegerField(), 'uuid': wfields.UUIDField(), 'audit_id': wfields.IntegerField(), 'strategy_id': wfields.IntegerField(), 'state': wfields.StringField(nullable=True), 'global_efficacy': wfields.FlexibleListOfDictField(nullable=True), 'audit': wfields.ObjectField('Audit', nullable=True), 'strategy': wfields.ObjectField('Strategy', nullable=True), } object_fields = { 'audit': (objects.Audit, 'audit_id'), 'strategy': (objects.Strategy, 'strategy_id'), } # Proxified field so we can keep the previous value after an update _state = None _old_state = None # NOTE(v-francoise): The way oslo.versionedobjects works is by using a # __new__ that will automatically create the attributes referenced in # fields. These attributes are properties that raise an exception if no # value has been assigned, which means that they store the actual field # value in an "_obj_%(field)s" attribute. So because we want to proxify a # value that is already proxified, we have to do what you see below. @property def _obj_state(self): return self._state @property def _obj_old_state(self): return self._old_state @property def old_state(self): return self._old_state @_obj_old_state.setter def _obj_old_state(self, value): self._old_state = value @_obj_state.setter def _obj_state(self, value): if self._old_state is None and self._state is None: self._state = value else: self._old_state, self._state = self._state, value @base.remotable_classmethod def get(cls, context, action_plan_id, eager=False): """Find a action_plan based on its id or uuid and return a Action object. :param action_plan_id: the id *or* uuid of a action_plan. :param eager: Load object fields if True (Default: False) :returns: a :class:`Action` object. """ if utils.is_int_like(action_plan_id): return cls.get_by_id(context, action_plan_id, eager=eager) elif utils.is_uuid_like(action_plan_id): return cls.get_by_uuid(context, action_plan_id, eager=eager) else: raise exception.InvalidIdentity(identity=action_plan_id) @base.remotable_classmethod def get_by_id(cls, context, action_plan_id, eager=False): """Find a action_plan based on its integer id and return a ActionPlan object. :param action_plan_id: the id of a action_plan. :param eager: Load object fields if True (Default: False) :returns: a :class:`ActionPlan` object. """ db_action_plan = cls.dbapi.get_action_plan_by_id( context, action_plan_id, eager=eager) action_plan = cls._from_db_object( cls(context), db_action_plan, eager=eager) return action_plan @base.remotable_classmethod def get_by_uuid(cls, context, uuid, eager=False): """Find a action_plan based on uuid and return a :class:`ActionPlan` object. :param uuid: the uuid of a action_plan. :param context: Security context :param eager: Load object fields if True (Default: False) :returns: a :class:`ActionPlan` object. """ db_action_plan = cls.dbapi.get_action_plan_by_uuid( context, uuid, eager=eager) action_plan = cls._from_db_object( cls(context), db_action_plan, eager=eager) return action_plan @base.remotable_classmethod def list(cls, context, limit=None, marker=None, filters=None, sort_key=None, sort_dir=None, eager=False): """Return a list of ActionPlan objects. :param context: Security context. :param limit: maximum number of resources to return in a single result. :param marker: pagination marker for large data sets. :param filters: Filters to apply. Defaults to None. :param sort_key: column to sort results by. :param sort_dir: direction to sort. "asc" or "desc". :param eager: Load object fields if True (Default: False) :returns: a list of :class:`ActionPlan` object. """ db_action_plans = cls.dbapi.get_action_plan_list(context, limit=limit, marker=marker, filters=filters, sort_key=sort_key, sort_dir=sort_dir, eager=eager) return [cls._from_db_object(cls(context), obj, eager=eager) for obj in db_action_plans] @base.remotable def create(self): """Create an :class:`ActionPlan` record in the DB. :returns: An :class:`ActionPlan` object. """ values = self.obj_get_changes() db_action_plan = self.dbapi.create_action_plan(values) # Note(v-francoise): Always load eagerly upon creation so we can send # notifications containing information about the related relationships self._from_db_object(self, db_action_plan, eager=True) def _notify(): notifications.action_plan.send_create(self._context, self) _notify() @base.remotable def destroy(self): """Delete the action plan from the DB""" related_efficacy_indicators = objects.EfficacyIndicator.list( context=self._context, filters={"action_plan_uuid": self.uuid}) # Cascade soft_delete of related efficacy indicators for related_efficacy_indicator in related_efficacy_indicators: related_efficacy_indicator.destroy() self.dbapi.destroy_action_plan(self.uuid) self.obj_reset_changes() @base.remotable def save(self): """Save updates to this Action plan. Updates will be made column by column based on the result of self.what_changed(). """ updates = self.obj_get_changes() db_obj = self.dbapi.update_action_plan(self.uuid, updates) obj = self._from_db_object( self.__class__(self._context), db_obj, eager=False) self.obj_refresh(obj) def _notify(): notifications.action_plan.send_update( self._context, self, old_state=self.old_state) _notify() self.obj_reset_changes() @base.remotable def refresh(self, eager=False): """Loads updates for this Action plan. Loads a action_plan with the same uuid from the database and checks for updated attributes. Updates are applied from the loaded action_plan column by column, if there are any updates. :param eager: Load object fields if True (Default: False) """ current = self.get_by_uuid(self._context, uuid=self.uuid, eager=eager) self.obj_refresh(current) @base.remotable def soft_delete(self): """Soft Delete the Action plan from the DB""" related_actions = objects.Action.list( context=self._context, filters={"action_plan_uuid": self.uuid}, eager=True) # Cascade soft_delete of related actions for related_action in related_actions: related_action.soft_delete() related_efficacy_indicators = objects.EfficacyIndicator.list( context=self._context, filters={"action_plan_uuid": self.uuid}) # Cascade soft_delete of related efficacy indicators for related_efficacy_indicator in related_efficacy_indicators: related_efficacy_indicator.soft_delete() self.state = State.DELETED self.save() db_obj = self.dbapi.soft_delete_action_plan(self.uuid) obj = self._from_db_object( self.__class__(self._context), db_obj, eager=False) self.obj_refresh(obj) def _notify(): notifications.action_plan.send_delete(self._context, self) _notify()
class Goal(base.WatcherPersistentObject, base.WatcherObject, base.WatcherObjectDictCompat): # Version 1.0: Initial version VERSION = '1.0' dbapi = db_api.get_instance() fields = { 'id': wfields.IntegerField(), 'uuid': wfields.UUIDField(), 'name': wfields.StringField(), 'display_name': wfields.StringField(), 'efficacy_specification': wfields.FlexibleListOfDictField(), } @base.remotable_classmethod def get(cls, context, goal_id): """Find a goal based on its id or uuid :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.: Goal(context) :param goal_id: the id *or* uuid of a goal. :returns: a :class:`Goal` object. """ if utils.is_int_like(goal_id): return cls.get_by_id(context, goal_id) elif utils.is_uuid_like(goal_id): return cls.get_by_uuid(context, goal_id) else: raise exception.InvalidIdentity(identity=goal_id) @base.remotable_classmethod def get_by_id(cls, context, goal_id): """Find a goal based on its integer id :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.: Goal(context) :param goal_id: the id *or* uuid of a goal. :returns: a :class:`Goal` object. """ db_goal = cls.dbapi.get_goal_by_id(context, goal_id) goal = cls._from_db_object(cls(context), db_goal) return goal @base.remotable_classmethod def get_by_uuid(cls, context, uuid): """Find a goal based on uuid :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.: Goal(context) :param uuid: the uuid of a goal. :returns: a :class:`Goal` object. """ db_goal = cls.dbapi.get_goal_by_uuid(context, uuid) goal = cls._from_db_object(cls(context), db_goal) return goal @base.remotable_classmethod def get_by_name(cls, context, name): """Find a goal based on name :param name: the name of a goal. :param context: Security context :returns: a :class:`Goal` object. """ db_goal = cls.dbapi.get_goal_by_name(context, name) goal = cls._from_db_object(cls(context), db_goal) return goal @base.remotable_classmethod def list(cls, context, limit=None, marker=None, filters=None, sort_key=None, sort_dir=None): """Return a list of :class:`Goal` objects. :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.: Goal(context) :param filters: dict mapping the filter key to a value. :param limit: maximum number of resources to return in a single result. :param marker: pagination marker for large data sets. :param sort_key: column to sort results by. :param sort_dir: direction to sort. "asc" or "desc". :returns: a list of :class:`Goal` object. """ db_goals = cls.dbapi.get_goal_list( context, filters=filters, limit=limit, marker=marker, sort_key=sort_key, sort_dir=sort_dir) return [cls._from_db_object(cls(context), obj) for obj in db_goals] @base.remotable def create(self): """Create a :class:`Goal` record in the DB""" values = self.obj_get_changes() db_goal = self.dbapi.create_goal(values) self._from_db_object(self, db_goal) def destroy(self): """Delete the :class:`Goal` from the DB""" self.dbapi.destroy_goal(self.id) self.obj_reset_changes() @base.remotable def save(self): """Save updates to this :class:`Goal`. Updates will be made column by column based on the result of self.what_changed(). """ updates = self.obj_get_changes() db_obj = self.dbapi.update_goal(self.uuid, updates) obj = self._from_db_object(self, db_obj, eager=False) self.obj_refresh(obj) self.obj_reset_changes() @base.remotable def refresh(self): """Loads updates for this :class:`Goal`. Loads a goal with the same uuid from the database and checks for updated attributes. Updates are applied from the loaded goal column by column, if there are any updates. """ current = self.get_by_uuid(self._context, uuid=self.uuid) self.obj_refresh(current) @base.remotable def soft_delete(self): """Soft Delete the :class:`Goal` from the DB""" db_obj = self.dbapi.soft_delete_goal(self.uuid) obj = self._from_db_object( self.__class__(self._context), db_obj, eager=False) self.obj_refresh(obj)
class AuditTemplate(base.WatcherPersistentObject, base.WatcherObject, base.WatcherObjectDictCompat): # Version 1.0: Initial version # Version 1.1: Added 'goal' and 'strategy' object field VERSION = '1.1' dbapi = db_api.get_instance() fields = { 'id': wfields.IntegerField(), 'uuid': wfields.UUIDField(), 'name': wfields.StringField(), 'description': wfields.StringField(nullable=True), 'scope': wfields.FlexibleListOfDictField(nullable=True), 'goal_id': wfields.IntegerField(), 'strategy_id': wfields.IntegerField(nullable=True), 'goal': wfields.ObjectField('Goal', nullable=True), 'strategy': wfields.ObjectField('Strategy', nullable=True), } object_fields = { 'goal': (objects.Goal, 'goal_id'), 'strategy': (objects.Strategy, 'strategy_id'), } @base.remotable_classmethod def get(cls, context, audit_template_id, eager=False): """Find an audit template based on its id or uuid :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.: AuditTemplate(context) :param audit_template_id: the id *or* uuid of a audit_template. :param eager: Load object fields if True (Default: False) :returns: a :class:`AuditTemplate` object. """ if utils.is_int_like(audit_template_id): return cls.get_by_id(context, audit_template_id, eager=eager) elif utils.is_uuid_like(audit_template_id): return cls.get_by_uuid(context, audit_template_id, eager=eager) else: raise exception.InvalidIdentity(identity=audit_template_id) @base.remotable_classmethod def get_by_id(cls, context, audit_template_id, eager=False): """Find an audit template based on its integer id :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.: AuditTemplate(context) :param audit_template_id: the id of a audit_template. :param eager: Load object fields if True (Default: False) :returns: a :class:`AuditTemplate` object. """ db_audit_template = cls.dbapi.get_audit_template_by_id( context, audit_template_id, eager=eager) audit_template = cls._from_db_object(cls(context), db_audit_template, eager=eager) return audit_template @base.remotable_classmethod def get_by_uuid(cls, context, uuid, eager=False): """Find an audit template based on uuid :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.: AuditTemplate(context) :param uuid: the uuid of a audit_template. :param eager: Load object fields if True (Default: False) :returns: a :class:`AuditTemplate` object. """ db_audit_template = cls.dbapi.get_audit_template_by_uuid(context, uuid, eager=eager) audit_template = cls._from_db_object(cls(context), db_audit_template, eager=eager) return audit_template @base.remotable_classmethod def get_by_name(cls, context, name, eager=False): """Find an audit template based on name :param name: the logical name of a audit_template. :param context: Security context :param eager: Load object fields if True (Default: False) :returns: a :class:`AuditTemplate` object. """ db_audit_template = cls.dbapi.get_audit_template_by_name(context, name, eager=eager) audit_template = cls._from_db_object(cls(context), db_audit_template, eager=eager) return audit_template @base.remotable_classmethod def list(cls, context, filters=None, limit=None, marker=None, sort_key=None, sort_dir=None, eager=False): """Return a list of :class:`AuditTemplate` objects. :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.: AuditTemplate(context) :param filters: dict mapping the filter key to a value. :param limit: maximum number of resources to return in a single result. :param marker: pagination marker for large data sets. :param sort_key: column to sort results by. :param sort_dir: direction to sort. "asc" or "desc". :param eager: Load object fields if True (Default: False) :returns: a list of :class:`AuditTemplate` object. """ db_audit_templates = cls.dbapi.get_audit_template_list( context, filters=filters, limit=limit, marker=marker, sort_key=sort_key, sort_dir=sort_dir, eager=eager) return [ cls._from_db_object(cls(context), obj, eager=eager) for obj in db_audit_templates ] @base.remotable def create(self): """Create a :class:`AuditTemplate` record in the DB :returns: An :class:`AuditTemplate` object. """ values = self.obj_get_changes() db_audit_template = self.dbapi.create_audit_template(values) # Note(v-francoise): Always load eagerly upon creation so we can send # notifications containing information about the related relationships self._from_db_object(self, db_audit_template, eager=True) def destroy(self): """Delete the :class:`AuditTemplate` from the DB""" self.dbapi.destroy_audit_template(self.uuid) self.obj_reset_changes() @base.remotable def save(self): """Save updates to this :class:`AuditTemplate`. Updates will be made column by column based on the result of self.what_changed(). """ updates = self.obj_get_changes() db_obj = self.dbapi.update_audit_template(self.uuid, updates) obj = self._from_db_object(self, db_obj, eager=False) self.obj_refresh(obj) self.obj_reset_changes() @base.remotable def refresh(self, eager=False): """Loads updates for this :class:`AuditTemplate`. Loads a audit_template with the same uuid from the database and checks for updated attributes. Updates are applied from the loaded audit_template column by column, if there are any updates. :param eager: Load object fields if True (Default: False) """ current = self.get_by_uuid(self._context, uuid=self.uuid, eager=eager) self.obj_refresh(current) @base.remotable def soft_delete(self): """Soft Delete the :class:`AuditTemplate` from the DB""" db_obj = self.dbapi.soft_delete_audit_template(self.uuid) obj = self._from_db_object(self.__class__(self._context), db_obj, eager=False) self.obj_refresh(obj)