コード例 #1
0
ファイル: __init__.py プロジェクト: nfatkhiyev/proxstar
def settings():
    user = User(session['userinfo']['preferred_username'])
    if user.rtp:
        templates = get_templates(db)
        db_ignored_pools = get_ignored_pools(db)
        db_allowed_users = get_allowed_users(db)
        return render_template('settings.html',
                               user=user,
                               templates=templates,
                               ignored_pools=db_ignored_pools,
                               allowed_users=db_allowed_users)
    else:
        return abort(403)
コード例 #2
0
ファイル: __init__.py プロジェクト: harmonherring/proxstar
def create():
    user = User(session['userinfo']['preferred_username'])
    proxmox = connect_proxmox()
    if user.active or user.rtp:
        if request.method == 'GET':
            stored_isos = get_isos(proxmox, app.config['PROXMOX_ISO_STORAGE'])
            pools = get_pools(proxmox, db)
            templates = get_templates(db)
            return render_template(
                'create.html',
                user=user,
                usage=user.usage,
                limits=user.limits,
                percents=user.usage_percent,
                isos=stored_isos,
                pools=pools,
                templates=templates,
            )
        elif request.method == 'POST':
            name = request.form['name'].lower()
            cores = request.form['cores']
            memory = request.form['mem']
            template = request.form['template']
            disk = request.form['disk']
            iso = request.form['iso']
            ssh_key = request.form['ssh_key']
            if iso != 'none':
                iso = '{}:iso/{}'.format(app.config['PROXMOX_ISO_STORAGE'],
                                         iso)
            if not user.rtp:
                if template == 'none':
                    usage_check = user.check_usage(0, 0, disk)
                else:
                    usage_check = user.check_usage(cores, memory, disk)
                username = user.name
            else:
                usage_check = None
                username = request.form['user']
            if usage_check:
                return usage_check
            else:
                valid, available = check_hostname(starrs, name)
                if valid and available:
                    if template == 'none':
                        q.enqueue(
                            create_vm_task,
                            username,
                            name,
                            cores,
                            memory,
                            disk,
                            iso,
                            job_timeout=300,
                        )
                    else:
                        q.enqueue(
                            setup_template_task,
                            template,
                            name,
                            username,
                            ssh_key,
                            cores,
                            memory,
                            job_timeout=600,
                        )
                        return '', 200
            return '', 200
        return None
    else:
        return '', 403