def serialize_to_dict(self, entity):
        cls = type(entity.action)

        return {
            'cls_name': cls.__name__,
            'cls_attrs': inspect_utils.get_public_fields(cls),
            'data': vars(entity.action),
            'code_source_id': entity.code_source_id,
            'namespace': entity.namespace,
        }
Exemple #2
0
    def _validate(self):
        """Validation of types after YAQL evaluation."""
        props = inspect_utils.get_public_fields(self)

        try:
            jsonschema.validate(props, self._schema)
        except Exception as e:
            raise exc.InvalidModelException(
                "Invalid data type in %s: %s. Value(s) can be shown after "
                "YAQL evaluating. If you use YAQL here, please correct it." %
                (self.__class__.__name__, str(e)))
def _register_actions(generator, namespace):
    module = generator.base_action_class.__module__
    class_name = generator.base_action_class.__name__
    action_class_str = "%s.%s" % (module, class_name)

    for action in generator.create_actions():
        attrs = i_utils.get_public_fields(action['class'])

        register_action_class(action['name'],
                              action_class_str,
                              attrs,
                              action['description'],
                              action['arg_list'],
                              namespace=namespace)
def register_action_classes(namespace=''):
    mgr = extension.ExtensionManager(namespace='mistral.actions',
                                     invoke_on_load=False)
    for name in mgr.names():
        action_class_str = mgr[name].entry_point_target.replace(':', '.')
        action_class = mgr[name].plugin
        description = i_utils.get_docstring(action_class)
        input_str = i_utils.get_arg_list_as_str(action_class.__init__)

        attrs = i_utils.get_public_fields(mgr[name].plugin)

        register_action_class(name,
                              action_class_str,
                              attrs,
                              description=description,
                              input_str=input_str,
                              namespace=namespace)

    _register_dynamic_action_classes(namespace=namespace)
Exemple #5
0
    def _register_generator_actions(self, generator):
        # TODO(rakhmerov): Here we have an implicit dependency on
        # "mistral-extra" because ActionGenerator class is defined
        # in "mistral-extra". Of course, it works because of duck
        # typing but architecture wise it's just very bad. "mistral"
        # must not depend on "mistral-extra" because the latter is
        # just a project with mistral extensions. In fact, we can't
        # even extend ActionGenerator class within "mistral" for
        # testing purposes.
        # So it's all done this way for compatibility until all
        # OpenStack actions are redesigned with action providers.
        for action in generator.create_actions():
            action_desc = GeneratedPythonActionDescriptor(
                action['name'],
                generator.base_action_class,
                i_utils.get_public_fields(action['class']),
                desc=action['description'],
                params_spec=action['arg_list']
            )

            LOG.debug('Registered action: %s', action_desc)

            self._action_descs[action['name']] = action_desc
Exemple #6
0
def _build_action_descriptor(name, action_cls):
    action_cls_attrs = i_utils.get_public_fields(action_cls)

    return ml_actions.PythonActionDescriptor(name, action_cls,
                                             action_cls_attrs)
    def test_get_public_fields(self):

        attrs = i_u.get_public_fields(ClassWithProperties)

        self.assertEqual(attrs, {'a': 1})