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)
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")
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)
def step1(): pserver = Server.query.filter_by(primary_server=True).first() if pserver and request.args.get('pass_set') != 'true': flash("Oops this service is not for you.", 'warning') return redirect(url_for('index.home')) wform = WizardStep1() if request.method == 'POST': if wform.validate_on_submit(): replication_pw = uuid.uuid4().hex app_conf = AppConfiguration() app_conf.nginx_host = wform.new_hostname.data.strip() app_conf.replication_pw = replication_pw app_conf.nginx_ip = wform.nginx_ip.data.strip() app_conf.modify_hosts = True db.session.add(app_conf) server = Server() server.ip = wform.ip.data.strip() server.hostname = wform.current_hostname.data.strip() server.primary_server = True db.session.add(app_conf) db.session.add(server) db.session.commit() if request.method == 'POST' or request.args.get('pass_set') == 'true': servers = Server.query.all() ask_passphrase = False c = RemoteClient(servers[0].ip, servers[0].hostname) try: c.startup() except ClientNotSetupException as e: if str(e) == 'Pubkey is encrypted.': ask_passphrase = True flash( "Pubkey seems to password protected. " "Please set passphrase.", 'warning') elif str(e) == 'Could not deserialize key data.': ask_passphrase = True flash( "Password your provided for pubkey did not work. " "Please set valid passphrase.", '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(servers[0].hostname, e), 'error') return render_template( 'index_passphrase.html', e=e, ask_passphrase=ask_passphrase, next=url_for('wizard.step1', pass_set='true'), warning_text="Error accessing Stand Allone Server") task = wizard_step1.delay() print "TASK STARTED", task.id servers = Server.query.all() return render_template('wizard/wizard_logger.html', step=1, task_id=task.id, servers=servers) return render_template('wizard/step1.html', wform=wform)