Example #1
0
def task_execute(fabfile, task_name):
    """ Read in the form post, then execute the task. """
    task = get_task(fabfile, task_name)
    form = request.form.copy()
    filtered_form = {}

    hosts = ""
    roles = ""

    if 'env_hosts' in form:
        hosts = form['env_hosts'] + ' '
        del form['env_hosts']

    if 'env_roles' in form:
        roles = request.form['env_roles'] + ' '
        del form['env_roles']

    if ',' in hosts:
        hosts = hosts.split(',')

    if ' ' in hosts:
        hosts = hosts.split()

    if ',' in roles:
        roles = roles.split(',')

    if ' ' in roles:
        roles = roles.split()

    if not hosts and not roles:
        flash('You need to provide either a hostname or choose a role.')
        return redirect("/fabfile/%(fabfile)s/task/%(task_name)s" % locals())

    from easyfab import task_to_dict
    for field, value in list(form.items()):
        value = value.strip()
        if not value:
            continue
        filtered_form[field] = value

    missing_required_args = False
    for required_arg in task_to_dict(task)['required_args']:
        if required_arg not in list(filtered_form.keys()):
            missing_required_args = True
            flash("Missing required argument: %s" % required_arg)

    if missing_required_args:
        return redirect("/fabfile/%(fabfile)s/task/%(task_name)s" % locals())

    stdout, stderr = execute_task(task,
                                  hosts=hosts,
                                  roles=roles,
                                  **filtered_form
                                  )

    stdout = easyfab.format_output(stdout)

    return render('execute.html', task=task, results=stdout, errors=stderr)
Example #2
0
def task_execute(fabfile, task_name):
    """ Read in the form post, then execute the task. """
    task = get_task(fabfile, task_name)
    form = request.form.copy()
    filtered_form = {}

    hosts = ""
    roles = ""

    if 'env_hosts' in form:
        hosts = form['env_hosts'] + ' '
        del form['env_hosts']

    if 'env_roles' in form:
        roles = request.form['env_roles'] + ' '
        del form['env_roles']

    if ',' in hosts:
        hosts = hosts.split(',')

    if ' ' in hosts:
        hosts = hosts.split()

    if ',' in roles:
        roles = roles.split(',')

    if ' ' in roles:
        roles = roles.split()

    if not hosts and not roles:
        flash('You need to provide either a hostname or choose a role.')
        return redirect("/fabfile/%(fabfile)s/task/%(task_name)s" % locals())

    from easyfab import task_to_dict
    for field, value in form.items():
        value = value.strip()
        if not value:
            continue
        filtered_form[field] = value

    missing_required_args = False
    for required_arg in task_to_dict(task)['required_args']:
        if required_arg not in filtered_form.keys():
            missing_required_args = True
            flash("Missing required argument: %s" % required_arg)

    if missing_required_args:
        return redirect("/fabfile/%(fabfile)s/task/%(task_name)s" % locals())

    stdout, stderr = execute_task(task,
                                  hosts=hosts,
                                  roles=roles,
                                  **filtered_form
                                  )

    stdout = easyfab.format_output(stdout)

    return render('execute.html', task=task, results=stdout, errors=stderr)
Example #3
0
def task_display(fabfile, task_name):
    """ Render a task as a html form. """
    task = get_task(fabfile, task_name)
    wrapped_task = task.__dict__['wrapped']
    task_dict = easyfab.task_to_dict(task)

    return render('task_form.html', task=task,
                  wrapped_task=wrapped_task,
                  task_dict=task_dict,
                  )
Example #4
0
def task_display(fabfile, task_name):
    """ Render a task as a html form. """
    task = get_task(fabfile, task_name)
    wrapped_task = task.__dict__['wrapped']
    task_dict = easyfab.task_to_dict(task)

    return render('task_form.html', task=task,
                  wrapped_task=wrapped_task,
                  task_dict=task_dict,
                  )