Exemplo n.º 1
0
def api_cluster_name_configured():
    """
    Define a route.

    This is a main routing method
    """
    #
    # Basic authentication module requirement
    # If the auth module is installed and the user is not authenticated, so go to login
    #
    session = {}
    if hasattr(app, 'auth'):
        try:
            session = get_session_data(
                transaction=transaction,
                session_id=request.cookies.get('session_id'))
        except Exception as e:
            print(e)
            return redirect(url_for('auth_blueprint.login'))
    else:
        session['kubeconfig'] = None
    # not current_user.is_authenticated:
    if hasattr(app, 'auth') and session['email'] is None:
        return redirect(url_for('auth_blueprint.login'))
    #
    # End basic authentication requirement
    #

    return jsonify(cluster_name_configured())
Exemplo n.º 2
0
def index():
    #if not current_user.is_authenticated:
    #    return redirect(url_for('base_blueprint.login'))

    return render_template('index.html',
                           compute_allocated_resources = compute_allocated_resources(),
                           hexagons_data = hexagons_data(),
                           cluster_name_configured  = cluster_name_configured(),
                          )
Exemplo n.º 3
0
def route_client_pystol():
    """try:"""
    if request.method == "GET":
            return redirect( 'pystol-client-cluster')
    if (request.method == "POST"):  
        print("entre por POST")
        print(request.form)
        actionclient = request.form['actionclient']
        result = client_pystol(actionclient)
        print("route" + result)    #flask run --host=0.0.0.0 --port=3000
        return render_template('pystol-client-cluster.html', 
                               compute_allocated_resources = compute_allocated_resources(),
                               cluster_name_configured  = cluster_name_configured(),
                               result = result, 
                               )    
Exemplo n.º 4
0
def route_template(template):
    #if not current_user.is_authenticated:
    #    return redirect(url_for('base_blueprint.login'))
    try:
        return render_template(template + '.html',
                               list_actions = list_actions(),
                               show_actions = show_actions(),
                               state_namespaces = state_namespaces(),
                               state_nodes = state_nodes(),
                               state_pods = state_pods(),
                               compute_allocated_resources = compute_allocated_resources(),
                               cluster_name_configured  = cluster_name_configured(),
                               )
    except TemplateNotFound:
        return render_template('page-404.html'), 404
    except:
        return render_template('page-500.html'), 500
Exemplo n.º 5
0
def pods():
    """
    Render all the templates not from base.

    This is a main method
    """
    #
    # Basic authentication module requirement
    # If the auth module is installed and the user is not authenticated, so go to login
    #
    session = {}
    if hasattr(app, 'auth'):
        try:
            session = get_session_data(transaction=transaction, session_id=request.cookies.get('session_id'))
        except Exception as e:
            return redirect(url_for('auth_blueprint.login'))
    else:
        session['kubeconfig'] = None
    # not current_user.is_authenticated:
    if hasattr(app, 'auth') and session['email'] == None:
        return redirect(url_for('auth_blueprint.login'))
    #
    # End basic authentication requirement
    #

    if not 'kubeconfig' in session or session['kubeconfig'] == None or session['kubeconfig'] == '':
        kubeconfig = None
        api_client = None
    else:
        kubeconfig = session['kubeconfig']
        api_client = remote_cluster(kubeconfig=kubeconfig)

    if (not 'username' in session or
        session['username'] == None or
        session['username'] == '' or
        not 'email' in session or
        session['email'] == None or
            session['email'] == ''):

        username = None
        email = None
    else:
        username = session['username']
        email = session['email']

    try:
        return render_template('pods.html',
                               username=username, email=email,
                               state_pods=state_pods(
                                   api_client=api_client),
                               compute_allocated_resources=compute_allocated_resources(
                                   api_client=api_client),
                               cluster_name_configured=cluster_name_configured(
                                   api_client=api_client),
                               pystol_version=PYSTOL_VERSION,)

    except TemplateNotFound:
        return render_template('page-404.html'), 404
    except Exception as e:
        print("Exception found in %s: %s" % (blueprint.name, e))
        if current_app.config['DEBUG']:
            raise e
        return render_template('page-500.html'), 500
Exemplo n.º 6
0
def run():
    """
    Render all the templates not from base.

    This is a main method
    """
    #
    # Basic authentication module requirement
    # If the auth module is installed and the user is not authenticated, so go to login
    #
    session = {}
    form = RunForm(request.form)
    if hasattr(app, 'auth'):
        try:
            session = get_session_data(
                transaction=transaction,
                session_id=request.cookies.get('session_id'))
        except Exception as e:
            return redirect(url_for('auth_blueprint.login'))
    else:
        session['kubeconfig'] = None

    if hasattr(app, 'auth') and session['email'] == None:
        return redirect(url_for('auth_blueprint.login'))
    #
    # End basic authentication requirement
    #

    if not 'kubeconfig' in session or session['kubeconfig'] == None or session[
            'kubeconfig'] == '':
        kubeconfig = None
        api_client = None
    else:
        kubeconfig = session['kubeconfig']
        api_client = remote_cluster(kubeconfig=kubeconfig)

    if (not 'username' in session or session['username'] == None
            or session['username'] == '' or not 'email' in session
            or session['email'] == None or session['email'] == ''):

        username = None
        email = None
    else:
        username = session['username']
        email = session['email']

    form = RunForm()

    if request.method == "POST":
        dict = request.form

        namespace = ""
        collection = ""
        role = ""
        source = ""
        extra_vars = {}

        if 'namespace' in dict:
            namespace = dict['namespace']
        else:
            namespace = ""

        if 'collection' in dict:
            collection = dict['collection']
        else:
            collection = ""

        if 'role' in dict:
            role = dict['role']
        else:
            role = ""

        if 'source' in dict:
            source = dict['source']
        else:
            source = ""

        if 'extra_vars' in dict:
            if dict['extra_vars'] == "" or dict['extra_vars'] is None:
                extra_vars = "{}"
            else:
                extra_vars = dict['extra_vars']
        else:
            extra_vars = "{}"

        errors = 0
        try:
            json.loads(extra_vars)
        except ValueError as e:
            errors = errors + 1

        if errors == 0:
            insert_pystol_object(namespace=namespace,
                                 collection=collection,
                                 role=role,
                                 source=source,
                                 extra_vars=extra_vars,
                                 api_client=api_client)
            return redirect(url_for('executed_blueprint.executed'))
        else:
            form.extra_vars.errors = ["This must be a valid JSON"]
    try:
        return render_template(
            'run.html',
            username=username,
            email=email,
            form=form,
            compute_allocated_resources=compute_allocated_resources(
                api_client=api_client),
            cluster_name_configured=cluster_name_configured(
                api_client=api_client),
            pystol_version=PYSTOL_VERSION,
        )

    except TemplateNotFound:
        return render_template('page-404.html'), 404
    except Exception as e:
        print("Exception found in %s: %s" % (blueprint.name, e))
        if current_app.config['DEBUG']:
            raise e
        return render_template('page-500.html'), 500
Exemplo n.º 7
0
def api_cluster_name_configured():
    return jsonify(cluster_name_configured())