Exemplo n.º 1
Arquivo: ui.py Projeto: doanac/cya
def ui_create_container():
    if g.user is None or 'openid' not in session:
        flash('You must be logged in to create a container')
        return redirect(url_for('login'))

    if request.method == 'POST':
        template, release = request.form['container-type'].split(':')
        data = {
            'requested_by': g.user.nickname,
            'state': 'QUEUED',
            'date_requested': int(time.time()),
            'template': template,
            'release': release,
            'max_memory': int(request.form['max-memory']) * 1000000000,
            'containermounts': [],
        init_script = request.form['init-script'].replace('\r', '')
        if init_script:
            data['initscripts'] = [{'name': 'init', 'content': init_script}]

        print("ANDY", data)
        for x in request.form.keys():
            if x[:3] == 'ss_':
                directory = request.form[x]
                if directory:
                    ss = shared_storage.get(x[3:])
                        'name': ss.name,
                        'type': ss.type,
                        'source': ss.source,
                        'directory': directory,
        container_requests.create(request.form['name'], data)
        flash('Container requested')
        return redirect(url_for('index'))

    ss = [shared_storage.get(x) for x in shared_storage.list()]
    scripts = g.user.to_dict()['initscripts']
    return render_template('create_container.html',
                           user_scripts=scripts, shared_storage=ss,
Exemplo n.º 2
Arquivo: ui.py Projeto: doanac/cya
def user_settings():
    if g.user is None or 'openid' not in session:
        return redirect(url_for('login'))
    if request.method == 'POST':
        names = request.form.getlist('script-name')
        scripts = request.form.getlist('script-content')
        data = {x[0]: {'content': x[1]} for x in zip(names, scripts)}
        u = users.get_user_by_openid(g.user.openid)
        defined = set([x for x in u.initscripts.list()])
        for remove in defined - set(names):
        for add in set(names) - defined:
            u.initscripts.create(add, data[add])
        for update in set(names) & defined:
        g.user = users.get(u.name)
        return redirect(url_for('user_settings'))

    u = [users.get(x) for x in users.list()]
    scripts = g.user.to_dict().get('initscripts', [])
    ss = [shared_storage.get(x) for x in shared_storage.list()]
    return render_template(
        'settings.html', settings=settings, users=u, user_scripts=scripts,