Ejemplo n.º 1
0
    def __init__(self, definition_cfg, default_archive_policy, plugin_manager):
        self._default_archive_policy = default_archive_policy
        self.cfg = definition_cfg

        for field, field_type in self.MANDATORY_FIELDS.items():
            if field not in self.cfg:
                raise declarative.DefinitionException(
                    _LE("Required field %s not specified") % field, self.cfg)
            if not isinstance(self.cfg[field], field_type):
                raise declarative.DefinitionException(
                    _LE("Required field %(field)s should be a %(type)s") %
                    {'field': field, 'type': field_type}, self.cfg)

        self._attributes = {}
        for name, attr_cfg in self.cfg.get('attributes', {}).items():
            self._attributes[name] = declarative.Definition(name, attr_cfg,
                                                            plugin_manager)

        self.metrics = {}
        for t in self.cfg['metrics']:
            archive_policy = self.cfg.get('archive_policy',
                                          self._default_archive_policy)
            if archive_policy is None:
                self.metrics[t] = {}
            else:
                self.metrics[t] = dict(archive_policy_name=archive_policy)
Ejemplo n.º 2
0
    def __init__(self, definition_cfg, trait_plugin_mgr):
        self._included_types = []
        self._excluded_types = []
        self.traits = dict()
        self.cfg = definition_cfg
        self.raw_levels = [level.lower() for level in cfg.CONF.event.store_raw]

        try:
            event_type = definition_cfg['event_type']
            traits = definition_cfg['traits']
        except KeyError as err:
            raise declarative.DefinitionException(
                _("Required field %s not specified") % err.args[0], self.cfg)

        if isinstance(event_type, six.string_types):
            event_type = [event_type]

        for t in event_type:
            if t.startswith('!'):
                self._excluded_types.append(t[1:])
            else:
                self._included_types.append(t)

        if self._excluded_types and not self._included_types:
            self._included_types.append('*')

        for trait_name in self.DEFAULT_TRAITS:
            self.traits[trait_name] = TraitDefinition(
                trait_name, self.DEFAULT_TRAITS[trait_name], trait_plugin_mgr)
        for trait_name in traits:
            self.traits[trait_name] = TraitDefinition(trait_name,
                                                      traits[trait_name],
                                                      trait_plugin_mgr)
Ejemplo n.º 3
0
 def __init__(self, name, trait_cfg, plugin_manager):
     super(TraitDefinition, self).__init__(name, trait_cfg, plugin_manager)
     type_name = (trait_cfg.get('type', 'text') if isinstance(
         trait_cfg, dict) else 'text')
     self.trait_type = models.Trait.get_type_by_name(type_name)
     if self.trait_type is None:
         raise declarative.DefinitionException(
             _("Invalid trait type '%(type)s' for trait %(trait)s") %
             dict(type=type_name, trait=name), self.cfg)
Ejemplo n.º 4
0
    def __init__(self, definition_cfg, plugin_manager):
        self.cfg = definition_cfg
        missing = [
            field for field in self.REQUIRED_FIELDS if not self.cfg.get(field)
        ]
        if missing:
            raise declarative.DefinitionException(
                _LE("Required fields %s not specified") % missing, self.cfg)

        self._event_type = self.cfg.get('event_type')
        if isinstance(self._event_type, six.string_types):
            self._event_type = [self._event_type]

        if ('type' not in self.cfg.get('lookup', [])
                and self.cfg['type'] not in sample.TYPES):
            raise declarative.DefinitionException(
                _LE("Invalid type %s specified") % self.cfg['type'], self.cfg)

        self._fallback_user_id = declarative.Definition(
            'user_id', "_context_user_id|_context_user", plugin_manager)
        self._fallback_project_id = declarative.Definition(
            'project_id', "_context_tenant_id|_context_tenant", plugin_manager)
        self._attributes = {}
        self._metadata_attributes = {}

        for name in self.SAMPLE_ATTRIBUTES:
            attr_cfg = self.cfg.get(name)
            if attr_cfg:
                self._attributes[name] = declarative.Definition(
                    name, attr_cfg, plugin_manager)
        metadata = self.cfg.get('metadata', {})
        for name in metadata:
            self._metadata_attributes[name] = declarative.Definition(
                name, metadata[name], plugin_manager)

        # List of fields we expected when multiple meter are in the payload
        self.lookup = self.cfg.get('lookup')
        if isinstance(self.lookup, six.string_types):
            self.lookup = [self.lookup]