Beispiel #1
0
def run_recipe(recipe_name, request, fmt='json'):
    recipe_contexts = recipe.get_recipe_contexts(recipe_name)
    args = request.args.to_dict(flat=True)

    for key, value in recipe_contexts.items():
        if "default" in value[1]:
            args.setdefault(key, value[1]["default"])

    for key, value in args.items():
        context = recipe_contexts[key][1]
        if context.get('type') == 'number':
            args[key] = int(value)

    config.fmt = fmt
    return recipe.run_recipe(recipe_name, args, False)
Beispiel #2
0
def recipe_handler(recipe_name):
    """
    :param list recipe:the name of the selected recipe file
    :returns: template
    """
    if recipe_name not in recipe_lists:
        return render_template('home.html',
                               recipes=recipe_lists,
                               type="is-warning",
                               recipe="Warning",
                               error="Please choose recipe to run"), 404

    recipe_contexts = recipe.get_recipe_contexts(recipe_name)
    transform_context_attributes(recipe_contexts, request.args)

    return render_template('recipe.html', recipes=recipe_lists, recipe=recipe_name,
                           recipe_contexts=recipe_contexts,
                           docstring=Markup(recipe.get_docstring(recipe_name)))
Beispiel #3
0
    def build_api_url(recipe_test):
        """
        Build api url from test case and default value of context
        :param recipe_test:
        :return: url_string (str)
        """
        args = recipe_test["args"]
        # Get definition of all contexts
        recipe_context_def = get_recipe_contexts(recipe_test["recipe"])
        recipe_args = {}

        # convert cli form to context form
        for key, value in recipe_context_def.items():
            for name in value.get('flags', []):
                try:
                    index = args.index(name)
                    recipe_args.setdefault(key, args[index + 1])
                except ValueError:
                    pass
        url_string = "{}{}{}?{}".format(api_host, app.API_BASE_PATH,
                                        recipe_test["recipe"],
                                        urlencode(recipe_args))
        return url_string