def edit(server_id): server = Server.query.get(server_id) if not server: flash('There is no server with the ID: %s' % server_id, "warning") return redirect(url_for('index.home')) form = ServerForm() header = "Update Server Details" if server.primary_server: header = "Update Primary Server Details" if request.method == 'POST' and not form.ldap_password.data.strip(): form.ldap_password.data = '**dummy**' form.ldap_password_confirm.data = '**dummy**' else: del form.ldap_password del form.ldap_password_confirm if form.validate_on_submit(): server.hostname = form.hostname.data.strip() server.ip = form.ip.data.strip() if server.primary_server and form.ldap_password.data != '**dummy**': server.ldap_password = form.ldap_password.data.strip() sync_ldap_passwords(server.ldap_password) db.session.commit() # start the background job to get system details collect_server_details.delay(server.id) return redirect(url_for('index.home')) form.hostname.data = server.hostname form.ip.data = server.ip if server.primary_server: form.ldap_password.data = server.ldap_password 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() 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 edit(server_id): server = Server.query.get(server_id) if not server: flash('There is no server with the ID: %s' % server_id, "warning") return redirect(url_for('index.home')) form = ServerForm() pr_server = get_primary_server_id() if pr_server: if not get_primary_server_id() == server_id: form.primary_server.render_kw = {'disabled': 'disabled'} if request.method == 'POST' and not form.ldap_password.data: form.ldap_password.data = '**dummy**' if form.validate_on_submit(): server.gluu_server = form.gluu_server.data server.hostname = form.hostname.data server.ip = form.ip.data server.primary_server = form.primary_server.data if form.ldap_password.data is not '**dummy**': server.ldap_password = form.ldap_password.data db.session.commit() # start the background job to get system details collect_server_details.delay(server.id) return redirect(url_for('index.home')) form.gluu_server.data = server.gluu_server form.hostname.data = server.hostname form.ip.data = server.ip form.ldap_password.data = server.ldap_password form.primary_server.data = server.primary_server return render_template('new_server.html', form=form, header="Update Server Details")
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 install_gluu(server_id): """Gluu server installation view. This function creates setup.properties file and redirects to install_gluu_server which does actual installation. """ # If current server is not primary server, first we should identify # primary server. If primary server is not installed then redirect # to home to install primary. pserver = Server.query.filter_by(primary_server=True).first() if not pserver: flash( "Please identify primary server before starting to install Gluu " "Server.", "warning") return redirect(url_for('index.home')) server = Server.query.get(server_id) # We need os type to perform installation. If it was not identified, # return to home and wait until it is identifed. if not server.os: flash("Server OS version hasn't been identified yet. Checking Now", "warning") collect_server_details.delay(server_id) return redirect(url_for('index.home')) # If current server is not primary server, and primary server was installed, # start installation by redirecting to cluster.install_gluu_server if not server.primary_server: return redirect( url_for('cluster.install_gluu_server', server_id=server_id)) # If we come up here, it is primary server and we will ask admin which # components will be installed. So prepare form by InstallServerForm appconf = AppConfiguration.query.first() form = InstallServerForm() # We don't require these for server installation. These fields are required # for adding new server. del form.hostname del form.ip_address del form.ldap_password header = 'Install Gluu Server on {0}'.format(server.hostname) # Get default setup properties. setup_prop = get_setup_properties() setup_prop['hostname'] = appconf.nginx_host setup_prop['ip'] = server.ip setup_prop['ldapPass'] = server.ldap_password #required for inum fields #if request.method == 'POST': # if not form.inumOrg.data.strip(): # inumOrg, inumAppliance = get_inums() # form.inumOrg.data = inumOrg # form.inumAppliance.data = inumAppliance # If form is submitted and validated, create setup.properties file. if form.validate_on_submit(): setup_prop['countryCode'] = form.countryCode.data.strip() setup_prop['state'] = form.state.data.strip() setup_prop['city'] = form.city.data.strip() setup_prop['orgName'] = form.orgName.data.strip() setup_prop['admin_email'] = form.admin_email.data.strip() setup_prop['application_max_ram'] = str(form.application_max_ram.data) setup_prop['inumOrg'], setup_prop['inumAppliance'] = get_inums() #setup_prop['inumOrg'] = form.inumOrg.data.strip() #setup_prop['inumAppliance'] = form.inumAppliance.data.strip() for o in ( 'installOxAuth', 'installOxTrust', 'installLDAP', 'installHTTPD', 'installJce', 'installSaml', 'installOxAuthRP', 'installPassport', 'ldap_type', 'application_max_ram', ): setup_prop[o] = getattr(form, o).data write_setup_properties_file(setup_prop) # Redirect to cluster.install_gluu_server to start installation. return redirect( url_for('server.confirm_setup_properties', server_id=server_id)) #return redirect(url_for('cluster.install_gluu_server', # server_id=server_id)) # If this view is requested, rather than post, display form to # admin to determaine which elements to be installed. if request.method == 'GET': form.countryCode.data = setup_prop['countryCode'] form.state.data = setup_prop['state'] form.city.data = setup_prop['city'] form.orgName.data = setup_prop['orgName'] form.admin_email.data = setup_prop['admin_email'] form.application_max_ram.data = setup_prop['application_max_ram'] #form.inumOrg.data = setup_prop['inumOrg'] #form.inumAppliance.data = setup_prop['inumAppliance'] for o in ( 'installOxAuth', 'installOxTrust', 'installLDAP', 'installHTTPD', 'installJce', 'installSaml', 'installOxAuthRP', 'installPassport', 'ldap_type', 'application_max_ram', ): getattr(form, o).data = setup_prop.get(o, '') # if appconf.gluu_version < '3.1.2': # print "removeing opendj" # form.ldap_type.choices.remove(('opendj', 'OpenDJ')) # form.ldap_type.data = 'openldap' setup_properties_form = SetupPropertiesLastForm() return render_template('new_server.html', form=form, server_id=server_id, setup_properties_form=setup_properties_form, header=header)
def install_gluu(server_id): """Gluu server installation view. This function creates setup.properties file and redirects to install_gluu_server which does actual installation. """ #If current server is not primary server, first we should identify #primary server. If primary server is not installed then redirect #to home to install primary. pserver = Server.query.filter_by(primary_server=True).first() if not pserver: flash( "Please identify primary server before starting to install Gluu " "Server.", "warning") return redirect(url_for('index.home')) #If current server is not primary server, and primary server was installed, #start installation redirecting to cluster.install_gluu_server server = Server.query.get(server_id) if not server.primary_server: return redirect( url_for('cluster.install_gluu_server', server_id=server_id)) #We need os type to perform installation. If it was not identified, #return to home and wait until it is identifed. if not server.os: flash("Server OS version hasn't been identified yet. Checking Now", "warning") collect_server_details.delay(server_id) return redirect(url_for('index.home')) #If we come up here, it is primary server and we will ask admin which #components will be installed. So prepare form by InstallServerForm appconf = AppConfiguration.query.first() form = InstallServerForm() #We don't require these for server installation. These fields are required #for adding new server. del form.hostname del form.ip_address del form.ldap_password header = 'Install Gluu Server on {0}'.format(server.hostname) #Get default setup properties. setup_prop = get_setup_properties() setup_prop['hostname'] = appconf.nginx_host setup_prop['ip'] = server.ip setup_prop['ldapPass'] = server.ldap_password #If form is submitted and validated, create setup.properties file. if form.validate_on_submit(): setup_prop['countryCode'] = form.countryCode.data.strip() setup_prop['state'] = form.state.data.strip() setup_prop['city'] = form.city.data.strip() setup_prop['orgName'] = form.orgName.data.strip() setup_prop['admin_email'] = form.admin_email.data.strip() setup_prop['inumOrg'] = form.inumOrg.data.strip() setup_prop['inumAppliance'] = form.inumAppliance.data.strip() for o in ( 'installOxAuth', 'installOxTrust', 'installLDAP', 'installHTTPD', 'installJce', 'installSaml', 'installAsimba', #'installCas', 'installOxAuthRP', 'installPassport', ): setup_prop[o] = getattr(form, o).data setup_properties_file = os.path.join(Config.DATA_DIR, 'setup.properties') with open(setup_properties_file, 'w') as f: for k, v in setup_prop.items(): f.write('{0}={1}\n'.format(k, v)) #Redirect to cluster.install_gluu_server to start installation. return redirect( url_for('cluster.install_gluu_server', server_id=server_id)) #If this is view is requested, rather than post, display form to #admin to determaine which elements to be installed. if request.method == 'GET': form.countryCode.data = setup_prop['countryCode'] form.state.data = setup_prop['state'] form.city.data = setup_prop['city'] form.orgName.data = setup_prop['orgName'] form.admin_email.data = setup_prop['admin_email'] form.inumOrg.data = setup_prop['inumOrg'] form.inumAppliance.data = setup_prop['inumAppliance'] for o in ( 'installOxAuth', 'installOxTrust', 'installLDAP', 'installHTTPD', 'installJce', 'installSaml', 'installAsimba', #'installCas', 'installOxAuthRP', 'installPassport', ): getattr(form, o).data = setup_prop[o] return render_template('new_server.html', form=form, header=header)