Exemplo n.º 1
0
    def rule_create(self, cnxt, name, spec, metadata=None):
        if len(plugin_base.Rule.load_all(cnxt, filters={'name': name})) > 0:
            msg = _("The rule (%(name)s) already exists."
                    ) % {"name": name}
            raise exception.BileanBadRequest(msg=msg)

        type_name, version = schema.get_spec_version(spec)
        try:
            plugin = environment.global_env().get_plugin(type_name)
        except exception.RuleTypeNotFound:
            msg = _("The specified rule type (%(type)s) is not supported."
                    ) % {"type": type_name}
            raise exception.BileanBadRequest(msg=msg)

        LOG.info(_LI("Creating rule type: %(type)s, name: %(name)s."),
                 {'type': type_name, 'name': name})
        rule = plugin.RuleClass(name, spec, metadata=metadata)
        try:
            rule.validate()
        except exception.InvalidSpec as ex:
            msg = six.text_type(ex)
            LOG.error(_LE("Failed in creating rule: %s"), msg)
            raise exception.BileanBadRequest(msg=msg)

        rule.store(cnxt)
        LOG.info(_LI("Rule %(name)s is created: %(id)s."),
                 {'name': name, 'id': rule.id})
        return rule.to_dict()
Exemplo n.º 2
0
    def rule_create(self, cnxt, name, spec, metadata=None):
        if len(rule_base.Rule.load_all(cnxt, filters={'name': name})) > 0:
            msg = _("The rule (%(name)s) already exists."
                    ) % {"name": name}
            raise exception.BileanBadRequest(msg=msg)

        type_name, version = schema.get_spec_version(spec)
        try:
            plugin = environment.global_env().get_rule(type_name)
        except exception.RuleTypeNotFound:
            msg = _("The specified rule type (%(type)s) is not supported."
                    ) % {"type": type_name}
            raise exception.BileanBadRequest(msg=msg)

        LOG.info(_LI("Creating rule type: %(type)s, name: %(name)s."),
                 {'type': type_name, 'name': name})
        rule = plugin(name, spec, metadata=metadata)
        try:
            rule.validate()
        except exception.InvalidSpec as ex:
            msg = six.text_type(ex)
            LOG.error(_LE("Failed in creating rule: %s"), msg)
            raise exception.BileanBadRequest(msg=msg)

        rule.store(cnxt)
        LOG.info(_LI("Rule %(name)s is created: %(id)s."),
                 {'name': name, 'id': rule.id})
        return rule.to_dict()
Exemplo n.º 3
0
    def __init__(self, name, spec, **kwargs):
        """Initialize a rule instance.

        :param name: A string that specifies the name for the rule.
        :param spec: A dictionary containing the detailed rule spec.
        :param kwargs: Keyword arguments for initializing the rule.
        :returns: An instance of a specific sub-class of Rule.
        """

        type_name, version = schema.get_spec_version(spec)

        self.name = name
        self.spec = spec

        self.id = kwargs.get('id', None)
        self.type = kwargs.get('type', '%s-%s' % (type_name, version))

        self.metadata = kwargs.get('metadata', {})

        self.created_at = kwargs.get('created_at', None)
        self.updated_at = kwargs.get('updated_at', None)
        self.deleted_at = kwargs.get('deleted_at', None)

        self.spec_data = schema.Spec(self.spec_schema, self.spec)
        self.properties = schema.Spec(self.properties_schema,
                                      self.spec.get(self.PROPERTIES, {}))
Exemplo n.º 4
0
    def __init__(self, name, spec, **kwargs):
        """Initialize a rule instance.

        :param name: A string that specifies the name for the rule.
        :param spec: A dictionary containing the detailed rule spec.
        :param kwargs: Keyword arguments for initializing the rule.
        :returns: An instance of a specific sub-class of Rule.
        """

        type_name, version = schema.get_spec_version(spec)

        self.name = name
        self.spec = spec

        self.id = kwargs.get('id', None)
        self.type = kwargs.get('type', '%s-%s' % (type_name, version))

        self.metadata = kwargs.get('metadata', {})

        self.created_at = kwargs.get('created_at', None)
        self.updated_at = kwargs.get('updated_at', None)
        self.deleted_at = kwargs.get('deleted_at', None)

        self.spec_data = schema.Spec(self.spec_schema, self.spec)
        self.properties = schema.Spec(self.properties_schema,
                                      self.spec.get(self.PROPERTIES, {}))
Exemplo n.º 5
0
    def __new__(cls, name, spec, **kwargs):
        """Create a new rule of the appropriate class.

        :param name: The name for the rule.
        :param spec: A dictionary containing the spec for the rule.
        :param kwargs: Keyword arguments for rule creation.
        :returns: An instance of a specific sub-class of Rule.
        """
        type_name, version = schema.get_spec_version(spec)

        if cls != Rule:
            RuleClass = cls
        else:
            RuleClass = environment.global_env().get_rule(type_name)

        return super(Rule, cls).__new__(RuleClass)
Exemplo n.º 6
0
    def __new__(cls, name, spec, **kwargs):
        """Create a new rule of the appropriate class.

        :param name: The name for the rule.
        :param spec: A dictionary containing the spec for the rule.
        :param kwargs: Keyword arguments for rule creation.
        :returns: An instance of a specific sub-class of Rule.
        """
        type_name, version = schema.get_spec_version(spec)

        if cls != Rule:
            RuleClass = cls
        else:
            RuleClass = environment.global_env().get_rule(type_name)

        return super(Rule, cls).__new__(RuleClass)