コード例 #1
0
 def _canonize_parameters(arguments_scheme, args, kwargs):
     arg_names = arguments_scheme.keys()
     parameter_values = helpers.filter_parameters_dict(kwargs)
     for i, arg in enumerate(args):
         name = arg_names[i]
         parameter_values[name] = arg
     return tuple(), parameter_values
コード例 #2
0
 def _canonize_parameters(arguments_scheme, args, kwargs):
     arg_names = arguments_scheme.keys()
     parameter_values = helpers.filter_parameters_dict(kwargs)
     for i, arg in enumerate(args):
         name = arg_names[i]
         parameter_values[name] = arg
     return tuple(), parameter_values
コード例 #3
0
ファイル: yaql_functions.py プロジェクト: tianshangjun/murano
def new_from_dict(type_name,
                  context,
                  parameters,
                  owner=None,
                  object_name=None,
                  extra=None):
    return new(context, type_name, owner, object_name, extra,
               **helpers.filter_parameters_dict(parameters))
コード例 #4
0
    def invoke_method(self,
                      method,
                      this,
                      context,
                      args,
                      kwargs,
                      skip_stub=False):
        if isinstance(this, dsl.MuranoObjectInterface):
            this = this.object
        kwargs = helpers.filter_parameters_dict(kwargs)
        runtime_version = method.murano_class.package.runtime_version
        yaql_engine = yaql_integration.choose_yaql_engine(runtime_version)
        if context is None or not skip_stub:
            actions_only = context is None and not method.name.startswith('.')
            method_context = self.create_method_context(
                self.create_object_context(this, context), method)
            method_context[constants.CTX_SKIP_FRAME] = True
            method_context[constants.CTX_ACTIONS_ONLY] = actions_only
            return method.yaql_function_definition(yaql_engine, method_context,
                                                   this.real_this)(*args,
                                                                   **kwargs)

        if (context[constants.CTX_ACTIONS_ONLY]
                and method.usage != murano_method.MethodUsages.Action):
            raise Exception('{0} is not an action'.format(method.name))

        context = self.create_method_context(
            self.create_object_context(this, context), method)
        this = this.real_this

        if method.arguments_scheme is not None:
            args, kwargs = self._canonize_parameters(method.arguments_scheme,
                                                     args, kwargs)

        with self._acquire_method_lock(method, this):
            for i, arg in enumerate(args, 2):
                context[str(i)] = arg
            for key, value in kwargs.iteritems():
                context[key] = value

            def call():
                if isinstance(method.body, specs.FunctionDefinition):
                    native_this = this.cast(method.murano_class).extension
                    return method.body(yaql_engine, context,
                                       native_this)(*args, **kwargs)
                else:
                    return (None if method.body is None else
                            method.body.execute(context))

            if (not isinstance(method.body, specs.FunctionDefinition)
                    or not method.body.meta.get(constants.META_NO_TRACE)):
                with self._log_method(context, args, kwargs) as log:
                    result = call()
                    log(result)
                    return result
            else:
                return call()
コード例 #5
0
    def invoke_method(self, method, this, context, args, kwargs,
                      skip_stub=False):
        if isinstance(this, dsl.MuranoObjectInterface):
            this = this.object
        kwargs = helpers.filter_parameters_dict(kwargs)
        runtime_version = method.murano_class.package.runtime_version
        yaql_engine = yaql_integration.choose_yaql_engine(runtime_version)
        if context is None or not skip_stub:
            actions_only = context is None and not method.name.startswith('.')
            method_context = self.create_method_context(
                self.create_object_context(this, context), method)
            method_context[constants.CTX_SKIP_FRAME] = True
            method_context[constants.CTX_ACTIONS_ONLY] = actions_only
            return method.yaql_function_definition(
                yaql_engine, method_context, this.real_this)(*args, **kwargs)

        if (context[constants.CTX_ACTIONS_ONLY] and method.usage !=
                murano_method.MethodUsages.Action):
            raise Exception('{0} is not an action'.format(method.name))

        context = self.create_method_context(
            self.create_object_context(this, context), method)
        this = this.real_this

        if method.arguments_scheme is not None:
            args, kwargs = self._canonize_parameters(
                method.arguments_scheme, args, kwargs)

        with self._acquire_method_lock(method, this):
            for i, arg in enumerate(args, 2):
                context[str(i)] = arg
            for key, value in kwargs.iteritems():
                context[key] = value

            def call():
                if isinstance(method.body, specs.FunctionDefinition):
                    native_this = this.cast(
                        method.murano_class).extension
                    return method.body(
                        yaql_engine, context, native_this)(*args, **kwargs)
                else:
                    return (None if method.body is None
                            else method.body.execute(context))

            if (not isinstance(method.body, specs.FunctionDefinition) or
                    not method.body.meta.get(constants.META_NO_TRACE)):
                with self._log_method(context, args, kwargs) as log:
                    result = call()
                    log(result)
                    return result
            else:
                return call()
コード例 #6
0
ファイル: yaql_functions.py プロジェクト: tianshangjun/murano
def new_from_dict(type_name, context, parameters,
                  owner=None, object_name=None, extra=None):
    return new(context, type_name, owner, object_name, extra,
               **helpers.filter_parameters_dict(parameters))