Пример #1
0
class NotificationBase(NotificationObject):
    """Base class for versioned notifications.

    Every subclass shall define a 'payload' field.
    """
    VERSION = '1.0'

    fields = {
        'priority': fields.NotificationPriorityField(),
        'event_type': fields.ObjectField('EventType'),
        'publisher': fields.ObjectField('NotificationPublisher'),
    }

    def _emit(self, context, event_type, publisher_id, payload):
        notifier = messaging.get_notifier(publisher_id)
        notify = getattr(notifier, self.priority)
        notify(context, event_type, payload)

    def emit(self, context):
        """Send the notification."""
        self.payload.obj_reset_changes(recursive=False)
        self._emit(context,
                   self.event_type.to_notification_field(),
                   self.publisher.publisher_id,
                   self.payload.obj_to_primitive())
Пример #2
0
class NotificationBase(base.SenlinObject):
    """Base class for versioned notifications.

    Every subclass shall define a 'payload' field.
    """
    VERSION = '1.0'

    fields = {
        'priority': fields.NotificationPriorityField(),
        'event_type': fields.ObjectField('EventType'),
        'publisher': fields.ObjectField('NotificationPublisher'),
    }

    def _emit(self, context, event_type, publisher_id, payload):
        notifier = messaging.get_notifier(publisher_id)
        notify = getattr(notifier, self.priority)
        notify(context, event_type=event_type, payload=payload)

    def emit(self, context):
        """Send the notification."""
        assert self.payload.populated

        # Note(gibi): notification payload will be a newly populated object
        # therefore every field of it will look changed so this does not carry
        # any extra information so we drop this from the payload.
        self.payload.obj_reset_changes(recursive=False)

        self._emit(context,
                   event_type=self.event_type.to_notification_field(),
                   publisher_id='%s:%s' %
                   (self.publisher.binary, self.publisher.host),
                   payload=self.payload.obj_to_primitive())
Пример #3
0
    def setUp(self):
        super(TestNotificationPriority, self).setUp()

        self.field = senlin_fields.NotificationPriorityField()
        self.coerce_good_values = [('audit', 'audit'),
                                   ('critical', 'critical'),
                                   ('debug', 'debug'), ('error', 'error'),
                                   ('sample', 'sample'), ('warn', 'warn')]
        self.coerce_bad_values = ['warning']
        self.to_primitive_values = self.coerce_good_values[0:1]
        self.from_primitive_values = self.coerce_good_values[0:1]