Exemplo n.º 1
0
def index():
    """Route for URL /server/. GET returns ServerForm to add a server,
    POST accepts the ServerForm, validates and creates a new Server object
    """
    appconfig = AppConfiguration.query.first()
    if not appconfig:
        flash(
            "Kindly set default values for the application before adding"
            " servers.", "info")
        return redirect(url_for('index.app_configuration', next="/server/"))

    form = ServerForm()
    header = "New Server"
    primary_server = Server.query.filter(
        Server.primary_server.is_(True)).first()

    if primary_server:
        del form.ldap_password
        del form.ldap_password_confirm
    else:
        header = "New Server - Primary Server"

    if form.validate_on_submit():
        server = Server()
        server.hostname = form.hostname.data.strip()
        server.ip = form.ip.data.strip()
        server.mmr = False
        if primary_server:
            server.ldap_password = primary_server.ldap_password
        else:
            server.ldap_password = form.ldap_password.data.strip()
            server.primary_server = True
        db.session.add(server)
        db.session.commit()

        # start the background job to get system details
        collect_server_details.delay(server.id)
        return redirect(url_for('index.home'))

    return render_template('new_server.html', form=form, header=header)
Exemplo n.º 2
0
def index():
    """Route for URL /server/. GET returns ServerForm to add a server,
    POST accepts the ServerForm, validates and creates a new Server object
    """
    appconfig = AppConfiguration.query.first()
    if not appconfig:
        flash(
            "Kindly set default values for the application before adding"
            " servers.", "info")
        return redirect(url_for('index.app_configuration', next="/server/"))
    form = ServerForm()

    pr_server = get_primary_server_id()
    if pr_server:
        form.primary_server.render_kw = {'disabled': 'disabled'}

    if form.validate_on_submit():
        server = Server()
        server.gluu_server = form.gluu_server.data
        server.hostname = form.hostname.data
        server.ip = form.ip.data
        server.ldap_password = form.ldap_password.data
        server.mmr = False
        server.primary_server = form.primary_server.data
        db.session.add(server)
        db.session.commit()

        # start the background job to get system details
        collect_server_details.delay(server.id)
        return redirect(url_for('index.home'))

    flash(
        'Cluster Manager will connect to this server via SSH to perform its'
        ' tasks. Ensure the server running Cluster Manager has'
        '"Password-less" SSH access via shared keys to the server.', 'info')
    return render_template('new_server.html', form=form, header="New Server")
Exemplo n.º 3
0
def index():
    """Route for URL /server/. GET returns ServerForm to add a server,
    POST accepts the ServerForm, validates and creates a new Server object
    """

    appconfig = AppConfiguration.query.first()
    if not appconfig:
        flash(
            "Kindly set default values for the application before adding"
            " servers.", "info")
        return redirect(url_for('index.app_configuration', next="/server/"))

    form = ServerForm()
    header = "New Server"
    primary_server = Server.query.filter(
        Server.primary_server.is_(True)).first()

    if primary_server:
        del form.ldap_password
        del form.ldap_password_confirm
    else:
        header = "New Server - Primary Server"

    if form.validate_on_submit():

        server = Server()
        server.hostname = form.hostname.data.strip()
        server.ip = form.ip.data.strip()
        server.mmr = False
        ask_passphrase = False

        server_exist = Server.query.filter_by(
            hostname=form.hostname.data.strip()).first()

        if server_exist:
            flash(
                "Server with hostname {} is already in cluster".format(
                    server_exist.hostname), "warning")
            return redirect(url_for('index.home'))

        c = RemoteClient(server.hostname, server.ip)
        try:
            c.startup()

        except ClientNotSetupException as e:

            if str(e) == 'Pubkey is encrypted.':
                ask_passphrase = True
                flash(
                    "Pubkey seems to password protected. "
                    "After setting your passphrase re-submit this form.",
                    'warning')
            elif str(e) == 'Could not deserialize key data.':
                ask_passphrase = True
                flash(
                    "Password your provided for pubkey did not work. "
                    "After setting your passphrase re-submit this form.",
                    'warning')
            else:
                flash(
                    "SSH connection to {} failed. Please check if your pub key is "
                    "added to /root/.ssh/authorized_keys on this server. Reason: {}"
                    .format(server.hostname, e), 'error')

        #except:
        #    flash("SSH connection to {} failed. Please check if your pub key is "
        #        "asdded to /root/.ssh/authorized_keys on this server".format(
        #                                            server.hostname))

            print "ask_passphrase", ask_passphrase

            return render_template('new_server.html',
                                   form=form,
                                   header=header,
                                   server_id=None,
                                   ask_passphrase=ask_passphrase,
                                   next=url_for('server.index'))

        if primary_server:
            server.ldap_password = primary_server.ldap_password
        else:
            server.ldap_password = form.ldap_password.data.strip()
            server.primary_server = True

        if not server.hostname == appconfig.nginx_host:
            db.session.add(server)
            db.session.commit()
            # start the background job to get system details
            collect_server_details.delay(server.id)
            return redirect(url_for('index.home'))

        else:
            flash("Load balancer can't be used as gluu server", 'danger')

    return render_template('new_server.html',
                           form=form,
                           header=header,
                           server_id=None)