Exemplo n.º 1
0
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:])
                    data['containermounts'].append({
                        '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',
                           common_init_scripts=settings.INIT_SCRIPTS,
                           user_scripts=scripts, shared_storage=ss,
                           container_types=settings.CONTAINER_TYPES)
Exemplo n.º 2
0
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):
            u.initscripts.get(remove).delete()
        for add in set(names) - defined:
            u.initscripts.create(add, data[add])
        for update in set(names) & defined:
            u.initscripts.get(update).update(data[update])
        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,
        shared_storage=ss)