Beispiel #1
0
def notify(context, publisher_id, event_type, priority, payload):
    """Sends a notification using the specified driver

    :param publisher_id: the source worker_type.host of the message
    :param event_type:   the literal type of event (ex. Instance Creation)
    :param priority:     patterned after the enumeration of Python logging
                         levels in the set (DEBUG, WARN, INFO, ERROR, CRITICAL)
    :param payload:       A python dictionary of attributes

    Outgoing message format includes the above parameters, and appends the
    following:

    message_id
      a UUID representing the id for this notification

    timestamp
      the GMT timestamp the notification was sent at

    The composite message will be constructed as a dictionary of the above
    attributes, which will then be sent via the transport mechanism defined
    by the driver.

    Message example::

        {'message_id': str(uuid.uuid4()),
         'publisher_id': 'compute.host1',
         'timestamp': timeutils.utcnow(),
         'priority': 'WARN',
         'event_type': 'compute.create_instance',
         'payload': {'instance_id': 12, ... }}

    """
    if priority not in log_levels:
        raise BadPriorityException(
            _('%s not in valid priorities') % priority)

    # Ensure everything is JSON serializable.
    payload = jsonutils.to_primitive(payload, convert_instances=True)

    msg = dict(message_id=str(uuid.uuid4()),
               publisher_id=publisher_id,
               event_type=event_type,
               priority=priority,
               payload=payload,
               timestamp=str(timeutils.utcnow()))

    for driver in _get_drivers():
        try:
            driver.notify(context, msg)
        except Exception, e:
            LOG.exception(_("Problem '%(e)s' attempting to "
                            "send to notification system. "
                            "Payload=%(payload)s") % locals())
Beispiel #2
0
 def __init__(self, user_id, tenant_id, is_admin=None, read_deleted="no",
              roles=None, timestamp=None, **kwargs):
     """
     :param read_deleted: 'no' indicates deleted records are hidden,
                          'yes' indicates deleted records are visible,
                          'only' indicates only deleted records are visible.
     """
     self.user_id = user_id
     self.tenant_id = tenant_id
     self.roles = roles or []
     self.is_admin = is_admin
     if self.is_admin is None:
         self.is_admin = 'admin' in [x.lower() for x in self.roles]
     elif self.is_admin and 'admin' not in [x.lower() for x in self.roles]:
         self.roles.append('admin')
     self.read_deleted = read_deleted
     if not timestamp:
         timestamp = timeutils.utcnow()
     self.timestamp = timestamp
     self._session = None
Beispiel #3
0
def utcnow():
    return timeutils.utcnow()