Пример #1
0
class ActionPayload(notificationbase.NotificationPayloadBase):
    SCHEMA = {
        'uuid': ('action', 'uuid'),

        'action_type': ('action', 'action_type'),
        'input_parameters': ('action', 'input_parameters'),
        'state': ('action', 'state'),
        'parents': ('action', 'parents'),

        'created_at': ('action', 'created_at'),
        'updated_at': ('action', 'updated_at'),
        'deleted_at': ('action', 'deleted_at'),
    }

    # Version 1.0: Initial version
    VERSION = '1.0'

    fields = {
        'uuid': wfields.UUIDField(),
        'action_type': wfields.StringField(nullable=False),
        'input_parameters': wfields.DictField(nullable=False, default={}),
        'state': wfields.StringField(nullable=False),
        'parents': wfields.ListOfUUIDsField(nullable=False, default=[]),
        'action_plan_uuid': wfields.UUIDField(),
        'action_plan': wfields.ObjectField('TerseActionPlanPayload'),

        'created_at': wfields.DateTimeField(nullable=True),
        'updated_at': wfields.DateTimeField(nullable=True),
        'deleted_at': wfields.DateTimeField(nullable=True),
    }

    def __init__(self, action, **kwargs):
        super(ActionPayload, self).__init__(**kwargs)
        self.populate_schema(action=action)
Пример #2
0
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)
Пример #3
0
class StrategyPayload(notificationbase.NotificationPayloadBase):
    SCHEMA = {
        'uuid': ('strategy', 'uuid'),
        'name': ('strategy', 'name'),
        'display_name': ('strategy', 'display_name'),
        'parameters_spec': ('strategy', 'parameters_spec'),
        'created_at': ('strategy', 'created_at'),
        'updated_at': ('strategy', 'updated_at'),
        'deleted_at': ('strategy', 'deleted_at'),
    }

    # Version 1.0: Initial version
    VERSION = '1.0'

    fields = {
        'uuid': wfields.UUIDField(),
        'name': wfields.StringField(),
        'display_name': wfields.StringField(),
        'parameters_spec': wfields.FlexibleDictField(nullable=True),
        'created_at': wfields.DateTimeField(nullable=True),
        'updated_at': wfields.DateTimeField(nullable=True),
        'deleted_at': wfields.DateTimeField(nullable=True),
    }

    def __init__(self, strategy, **kwargs):
        super(StrategyPayload, self).__init__(**kwargs)
        self.populate_schema(strategy=strategy)
Пример #4
0
class ComputeNode(compute_resource.ComputeResource):

    fields = {
        "hostname": wfields.StringField(),
        "status": wfields.StringField(default=ServiceState.ENABLED.value),
        "disabled_reason": wfields.StringField(nullable=True),
        "state": wfields.StringField(default=ServiceState.ONLINE.value),
        "memory": wfields.NonNegativeIntegerField(),
        "memory_mb_reserved": wfields.NonNegativeIntegerField(),
        "disk": wfields.NonNegativeIntegerField(),
        "disk_gb_reserved": wfields.NonNegativeIntegerField(),
        "vcpus": wfields.NonNegativeIntegerField(),
        "vcpu_reserved": wfields.NonNegativeIntegerField(),
        "memory_ratio": wfields.NonNegativeFloatField(),
        "vcpu_ratio": wfields.NonNegativeFloatField(),
        "disk_ratio": wfields.NonNegativeFloatField(),
    }

    def accept(self, visitor):
        raise NotImplementedError()

    @property
    def memory_mb_capacity(self):
        return (self.memory - self.memory_mb_reserved) * self.memory_ratio

    @property
    def disk_gb_capacity(self):
        return (self.disk - self.disk_gb_reserved) * self.disk_ratio

    @property
    def vcpu_capacity(self):
        return (self.vcpus - self.vcpu_reserved) * self.vcpu_ratio
Пример #5
0
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)
Пример #6
0
class ServiceStatusUpdatePayload(notificationbase.NotificationPayloadBase):
    # Version 1.0: Initial version
    VERSION = '1.0'
    fields = {
        'old_state': wfields.StringField(nullable=True),
        'state': wfields.StringField(nullable=True),
    }
Пример #7
0
class NotificationPublisher(NotificationObject):
    # Version 1.0: Initial version
    VERSION = '1.0'

    fields = {
        'host': wfields.StringField(nullable=False),
        'binary': wfields.StringField(nullable=False),
    }
Пример #8
0
class BaremetalResource(base.Element):

    VERSION = '1.0'

    fields = {
        "uuid": wfields.StringField(),
        "human_id": wfields.StringField(default=""),
    }
Пример #9
0
class IronicNode(baremetal_resource.BaremetalResource):

    fields = {
        "power_state": wfields.StringField(),
        "maintenance": wfields.BooleanField(),
        "maintenance_reason": wfields.StringField(),
        "extra": wfields.DictField()
    }

    def accept(self, visitor):
        raise NotImplementedError()
Пример #10
0
class StorageNode(storage_resource.StorageResource):

    fields = {
        "host": wfields.StringField(),
        "zone": wfields.StringField(),
        "status": wfields.StringField(default=ServiceState.ENABLED.value),
        "state": wfields.StringField(default=ServiceState.ONLINE.value),
        "volume_type": wfields.ListOfStringsField()
    }

    def accept(self, visitor):
        raise NotImplementedError()
Пример #11
0
        class TestNotificationPayload(
                notificationbase.NotificationPayloadBase):
            VERSION = '1.0'

            SCHEMA = {
                'field_1': ('source_field', 'field_1'),
                'field_2': ('source_field', 'field_2'),
            }

            fields = {
                'extra_field': wfields.StringField(),  # filled by ctor
                'field_1': wfields.StringField(),  # filled by the schema
                'field_2': wfields.IntegerField(),   # filled by the schema
            }
Пример #12
0
class ComputeNode(compute_resource.ComputeResource):

    fields = {
        "id": wfields.NonNegativeIntegerField(),
        "hostname": wfields.StringField(),
        "status": wfields.StringField(default=ServiceState.ENABLED.value),
        "state": wfields.StringField(default=ServiceState.ONLINE.value),
        "memory": wfields.NonNegativeIntegerField(),
        "disk": wfields.IntegerField(),
        "disk_capacity": wfields.NonNegativeIntegerField(),
        "vcpus": wfields.NonNegativeIntegerField(),
    }

    def accept(self, visitor):
        raise NotImplementedError()
Пример #13
0
    class TestNotificationPayloadEmptySchema(
            notificationbase.NotificationPayloadBase):
        VERSION = '1.0'

        fields = {
            'extra_field': wfields.StringField(),  # filled by ctor
        }
Пример #14
0
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()
Пример #15
0
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)
Пример #16
0
class ComputeResource(base.Element):

    VERSION = '1.0'

    fields = {
        "uuid": wfields.StringField(),
    }
Пример #17
0
 class TestObject(base.WatcherObject):
     VERSION = '1.0'
     fields = {
         'field_1': wfields.StringField(),
         'field_2': wfields.IntegerField(),
         'not_important_field': wfields.IntegerField(),
     }
Пример #18
0
class MyObj(base.WatcherPersistentObject, base.WatcherObject,
            base.WatcherObjectDictCompat):
    VERSION = '1.5'

    fields = {
        'foo': fields.IntegerField(),
        'bar': fields.StringField(),
        'missing': fields.StringField()
    }

    def obj_load_attr(self, attrname):
        setattr(self, attrname, 'loaded!')

    @object_base.remotable_classmethod
    def query(cls, context):
        obj = cls(context)
        obj.foo = 1
        obj.bar = 'bar'
        obj.obj_reset_changes()
        return obj

    @object_base.remotable
    def marco(self, context=None):
        return 'polo'

    @object_base.remotable
    def update_test(self, context=None):
        if context and context.user == 'alternate':
            self.bar = 'alternate-context'
        else:
            self.bar = 'updated'

    @object_base.remotable
    def save(self, context=None):
        self.obj_reset_changes()

    @object_base.remotable
    def refresh(self, context=None):
        self.foo = 321
        self.bar = 'refreshed'
        self.obj_reset_changes()

    @object_base.remotable
    def modify_save_modify(self, context=None):
        self.bar = 'meow'
        self.save()
        self.foo = 42
Пример #19
0
    class TestNotificationPayload(notificationbase.NotificationPayloadBase):
        VERSION = '1.0'

        SCHEMA = {
            'field_1': ('source_field', 'field_1'),
            'field_2': ('source_field', 'field_2'),
        }

        fields = {
            'extra_field': wfields.StringField(),  # filled by ctor
            'field_1': wfields.StringField(),  # filled by the schema
            'field_2': wfields.IntegerField(),   # filled by the schema
        }

        def populate_schema(self, source_field):
            super(TestNotificationBase.TestNotificationPayload,
                  self).populate_schema(source_field=source_field)
Пример #20
0
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)
Пример #21
0
class Instance(compute_resource.ComputeResource):

    fields = {
        # If the resource is excluded by the scope,
        # 'watcher_exclude' property will be set True.
        "watcher_exclude": wfields.BooleanField(default=False),
        "name": wfields.StringField(),
        "state": wfields.StringField(default=InstanceState.ACTIVE.value),
        "memory": wfields.NonNegativeIntegerField(),
        "disk": wfields.NonNegativeIntegerField(),
        "vcpus": wfields.NonNegativeIntegerField(),
        "metadata": wfields.JsonField(),
        "project_id": wfields.UUIDField(),
        "locked": wfields.BooleanField(default=False),
    }

    def accept(self, visitor):
        raise NotImplementedError()
Пример #22
0
class ServicePayload(notificationbase.NotificationPayloadBase):

    SCHEMA = {
        'sevice_host': ('failed_service', 'host'),
        'name': ('failed_service', 'name'),
        'last_seen_up': ('failed_service', 'last_seen_up'),
    }
    # Version 1.0: Initial version
    VERSION = '1.0'
    fields = {
        'sevice_host': wfields.StringField(),
        'name': wfields.StringField(),
        'last_seen_up': wfields.DateTimeField(nullable=True),
    }

    def __init__(self, failed_service, status_update, **kwargs):
        super(ServicePayload, self).__init__(failed_service=failed_service,
                                             status_update=status_update,
                                             **kwargs)
        self.populate_schema(failed_service=failed_service)
Пример #23
0
class ExceptionPayload(notificationbase.NotificationPayloadBase):
    # Version 1.0: Initial version
    VERSION = '1.0'
    fields = {
        'module_name': wfields.StringField(),
        'function_name': wfields.StringField(),
        'exception': wfields.StringField(),
        'exception_message': wfields.StringField()
    }

    @classmethod
    def from_exception(cls, fault=None):
        fault = fault or sys.exc_info()[1]
        trace = inspect.trace()[-1]
        # TODO(gibi): apply strutils.mask_password on exception_message and
        # consider emitting the exception_message only if the safe flag is
        # true in the exception like in the REST API
        return cls(function_name=trace[3],
                   module_name=inspect.getmodule(trace[0]).__name__,
                   exception=fault.__class__.__name__,
                   exception_message=six.text_type(fault))
Пример #24
0
class Instance(compute_resource.ComputeResource):

    fields = {
        "state": wfields.StringField(default=InstanceState.ACTIVE.value),
        "memory": wfields.NonNegativeIntegerField(),
        "disk": wfields.IntegerField(),
        "disk_capacity": wfields.NonNegativeIntegerField(),
        "vcpus": wfields.NonNegativeIntegerField(),
    }

    def accept(self, visitor):
        raise NotImplementedError()
Пример #25
0
class Pool(storage_resource.StorageResource):

    fields = {
        "name": wfields.StringField(),
        "total_volumes": wfields.NonNegativeIntegerField(),
        "total_capacity_gb": wfields.NonNegativeIntegerField(),
        "free_capacity_gb": wfields.NonNegativeIntegerField(),
        "provisioned_capacity_gb": wfields.NonNegativeIntegerField(),
        "allocated_capacity_gb": wfields.NonNegativeIntegerField(),
        "virtual_free": wfields.NonNegativeIntegerField(default=0),
    }

    def accept(self, visitor):
        raise NotImplementedError()
Пример #26
0
class EventType(NotificationObject):

    # Version 1.0: Initial version
    # Version 1.1: Added STRATEGY action in NotificationAction enum
    # Version 1.2: Added PLANNER action in NotificationAction enum
    # Version 1.3: Added EXECUTION action in NotificationAction enum
    VERSION = '1.3'

    fields = {
        'object': wfields.StringField(),
        'action': wfields.NotificationActionField(),
        'phase': wfields.NotificationPhaseField(nullable=True),
    }

    def to_notification_event_type_field(self):
        """Serialize the object to the wire format."""
        s = '%s.%s' % (self.object, self.action)
        if self.obj_attr_is_set('phase'):
            s += '.%s' % self.phase
        return s
Пример #27
0
class ActionPlanPayload(notificationbase.NotificationPayloadBase):
    SCHEMA = {
        'uuid': ('action_plan', 'uuid'),

        'state': ('action_plan', 'state'),
        'global_efficacy': ('action_plan', 'global_efficacy'),
        'audit_uuid': ('audit', 'uuid'),
        'strategy_uuid': ('strategy', 'uuid'),

        '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.0'

    fields = {
        'uuid': wfields.UUIDField(),
        'state': wfields.StringField(),
        'global_efficacy': wfields.FlexibleDictField(nullable=True),
        'audit_uuid': wfields.UUIDField(),
        'strategy_uuid': wfields.UUIDField(),
        'audit': wfields.ObjectField('TerseAuditPayload'),
        'strategy': wfields.ObjectField('StrategyPayload'),

        'created_at': wfields.DateTimeField(nullable=True),
        'updated_at': wfields.DateTimeField(nullable=True),
        'deleted_at': wfields.DateTimeField(nullable=True),
    }

    def __init__(self, action_plan, audit, strategy, **kwargs):
        super(ActionPlanPayload, self).__init__(
            audit=audit, strategy=strategy, **kwargs)
        self.populate_schema(
            action_plan=action_plan, audit=audit, strategy=strategy)
Пример #28
0
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()
Пример #29
0
class WatcherTestSubclassedObject(MyObj):
    fields = {'new_field': fields.StringField()}
Пример #30
0
 class TestObj(base.WatcherObject):
     fields = {'foo': fields.IntegerField(),
               'bar': fields.StringField()}