Example #1
0
    def to_samples_and_publish(self, context, notification):
        """Return samples produced by *process_notification*.

        Samples produced for the given notification.
        :param context: Execution context from the service or RPC call
        :param notification: The notification to process.
        """

        # TODO(sileht): this will be moved into oslo.messaging
        # see oslo.messaging bp notification-dispatcher-filter
        if not self._handle_event_type(notification['event_type'],
                                       self.event_types):
            return

        if self.requeue:
            meters = [
                utils.meter_message_from_counter(
                    sample, cfg.CONF.publisher.telemetry_secret)
                for sample in self.process_notification(notification)
            ]
            for notifier in self.transporter:
                notifier.sample(context.to_dict(),
                                event_type='ceilometer.pipeline',
                                payload=meters)
        else:
            with self.transporter.publisher(context) as p:
                p(list(self.process_notification(notification)))
Example #2
0
    def to_samples_and_publish(self, context, notification):
        """Return samples produced by *process_notification*.

        Samples produced for the given notification.
        :param context: Execution context from the service or RPC call
        :param notification: The notification to process.
        """

        # TODO(sileht): this will be moved into oslo.messaging
        # see oslo.messaging bp notification-dispatcher-filter
        if not self._handle_event_type(notification['event_type'],
                                       self.event_types):
            return

        if self.requeue:
            meters = [
                utils.meter_message_from_counter(
                    sample, cfg.CONF.publisher.metering_secret)
                for sample in self.process_notification(notification)
            ]
            for notifier in self.transporter:
                notifier.sample(context.to_dict(),
                                event_type='ceilometer.pipeline',
                                payload=meters)
        else:
            with self.transporter.publisher(context) as p:
                p(list(self.process_notification(notification)))
Example #3
0
    def gen_headers(self, context, **kw):
        """Generate a header for a simulated HTTP request to Pecan test app.

        :param context: context that store the client user information.
        :param kw: key word aguments, used to overwrite the context attribute.

        note: "is_public_api" is not in headers, it should be in environ
        variables to send along with the request. We can pass it by
        extra_environ when we call delete, get_json or other method request.
        """
        ct = context.to_dict()
        ct.update(kw)
        if ct.get("is_admin"):
            role = "admin"
        else:
            role = "user"
        headers = {
            'X-User-Name': ct.get("user_name") or "user",
            'X-User-Id': ct.get("user") or "1d6d686bc2c949ddb685ffb4682e0047",
            'X-Project-Name': ct.get("project_name") or "no_project_name",
            'X-Project-Id': ct.get("tenant")
            or "86f64f561b6d4f479655384572727f70",
            'X-User-Domain-Id': ct.get("domain_id")
            or "bd5eeb7d0fb046daaf694b36f4df5518",
            'X-User-Domain-Name': ct.get("domain_name") or "no_domain",
            'X-Auth-Token': ct.get("auth_token")
            or "b9764005b8c145bf972634fb16a826e8",
            'X-Roles': ct.get("roles") or role,
        }
        if ct.get('system_scope') == 'all':
            headers.update({'Openstack-System-Scope': 'all'})
        return headers
Example #4
0
    def to_samples_and_publish(self, context, notification):
        """Return samples produced by *process_notification*.

        Samples produced for the given notification.
        :param context: Execution context from the service or RPC call
        :param notification: The notification to process.
        """
        if self.requeue:
            meters = [
                utils.meter_message_from_counter(
                    sample, cfg.CONF.publisher.telemetry_secret)
                for sample in self.process_notification(notification)
            ]
            for notifier in self.transporter:
                notifier.sample(context.to_dict(),
                                event_type='ceilometer.pipeline',
                                payload=meters)
        else:
            with self.transporter.publisher(context) as p:
                p(list(self.process_notification(notification)))
Example #5
0
def target_cell(context, cell_mapping):
    """Yields a new context with connection information for a specific cell.

    This function yields a copy of the provided context, which is targeted to
    the referenced cell for MQ and DB connections.

    Passing None for cell_mapping will yield an untargetd copy of the context.

    :param context: The RequestContext to add connection information
    :param cell_mapping: An objects.CellMapping object or None
    """
    # Create a sanitized copy of context by serializing and deserializing it
    # (like we would do over RPC). This help ensure that we have a clean
    # copy of the context with all the tracked attributes, but without any
    # of the hidden/private things we cache on a context. We do this to avoid
    # unintentional sharing of cached thread-local data across threads.
    # Specifically, this won't include any oslo_db-set transaction context, or
    # any existing cell targeting.
    cctxt = RequestContext.from_dict(context.to_dict())
    set_target_cell(cctxt, cell_mapping)
    yield cctxt
Example #6
0
def target_cell(context, cell_mapping):
    """Yields a new context with connection information for a specific cell.

    This function yields a copy of the provided context, which is targeted to
    the referenced cell for MQ and DB connections.

    Passing None for cell_mapping will yield an untargetd copy of the context.

    :param context: The RequestContext to add connection information
    :param cell_mapping: An objects.CellMapping object or None
    """
    # Create a sanitized copy of context by serializing and deserializing it
    # (like we would do over RPC). This help ensure that we have a clean
    # copy of the context with all the tracked attributes, but without any
    # of the hidden/private things we cache on a context. We do this to avoid
    # unintentional sharing of cached thread-local data across threads.
    # Specifically, this won't include any oslo_db-set transaction context, or
    # any existing cell targeting.
    cctxt = RequestContext.from_dict(context.to_dict())
    set_target_cell(cctxt, cell_mapping)
    yield cctxt
 def serialize_context(self, context):
     return context.to_dict()
Example #8
0
 def serialize_context(self, context):
     return context.to_dict()