def software_profile_create(): # if not can_create_user(current_user): # abort(401) db_session = DBSession() form = SoftwareProfileForm(request.form) server_dialog_form = ServerDialogForm(request.form) fill_servers(server_dialog_form.server_dialog_server.choices, get_server_list(db_session), False) if request.method == 'POST' and form.validate(): software_profile = get_software_profile(db_session, form.profile_name.data) if software_profile is not None: return render_template('conformance/profile_edit.html', form=form, system_option=SystemOption.get(db_session), duplicate_error=True) software_profile = SoftwareProfile( name=form.profile_name.data, description=form.description.data, packages=','.join([l for l in form.software_packages.data.splitlines() if l]), created_by=current_user.username) db_session.add(software_profile) db_session.commit() return redirect(url_for('conformance.home')) else: return render_template('conformance/profile_edit.html', form=form, server_dialog_form=server_dialog_form, system_option=SystemOption.get(db_session))
def software_profile_edit(profile_name): db_session = DBSession() software_profile = get_software_profile(db_session, profile_name) if software_profile is None: abort(404) form = SoftwareProfileForm(request.form) server_dialog_form = ServerDialogForm(request.form) fill_servers(server_dialog_form.server_dialog_server.choices, get_server_list(db_session), False) if request.method == 'POST' and form.validate(): if profile_name != form.profile_name.data and \ get_software_profile(db_session, form.profile_name.data) is not None: return render_template('conformance/profile_edit.html', form=form, server_dialog_form=server_dialog_form, system_option=SystemOption.get(db_session), duplicate_error=True) software_profile.name = form.profile_name.data software_profile.description = form.description.data software_profile.packages = ','.join([l for l in form.software_packages.data.splitlines() if l]), db_session.commit() return redirect(url_for('conformance.home')) else: form.profile_name.data = software_profile.name form.description.data = software_profile.description if software_profile.packages is not None: form.software_packages.data = '\n'.join(software_profile.packages.split(',')) return render_template('conformance/profile_edit.html', form=form, server_dialog_form=server_dialog_form, system_option=SystemOption.get(db_session))
def api_get_server_repositories(request): validate_url_parameters(request, [KEY_HOSTNAME]) rows = [] db_session = DBSession() hostname = request.args.get(KEY_HOSTNAME) if hostname: server = get_server(db_session, hostname) if server is None: raise ValueError("Server repository '{}' does not exist in the database.".format(hostname)) servers = [server] else: servers = get_server_list(db_session) for server in servers: if server is not None: row = dict() row[KEY_HOSTNAME] = server.hostname row[KEY_SERVER_TYPE] = server.server_type for req in params_dict[server.server_type]: row[req] = server.__getattribute__(req) if server.__getattribute__(req) is not None else '' row[server_url_dict[server.server_type]] = server.server_url if not is_empty(server_directory_dict[server.server_type]): row[server_directory_dict[server.server_type]] = server.server_directory rows.append(row) return jsonify(**{RESPONSE_ENVELOPE: {'server_repository_list': rows}})
def home(platform, release): system_option = SystemOption.get(DBSession()) form = BrowseServerDialogForm(request.form) fill_servers(form.dialog_server.choices, get_server_list(DBSession()), False) export_software_information_form = ExportSoftwareInformationForm(request.form) return render_template('cco/home.html', form=form, platform=platform, release=release, system_option=system_option, export_software_information_form=export_software_information_form)
def init_config_form(db_session, http_request, get=False): config_form = ConfigConversionForm(http_request.form) servers = get_server_list(db_session) fill_servers(config_form.select_server.choices, servers, False) if get: config_form.hidden_submit_config_form.data = 'False' return config_form
def api_get_servers(): result_list = [] db_session = DBSession() servers = get_server_list(db_session) if servers is not None: for server in servers: result_list.append({'server_id': server.id, 'hostname': server.hostname}) return jsonify(**{'data': result_list})
def dashboard(): db_session = DBSession() jump_hosts = get_jump_host_list(db_session) regions = get_region_list(db_session) servers = get_server_list(db_session) form = BrowseServerDialogForm(request.form) fill_servers(form.dialog_server.choices, get_server_list(DBSession()), False) return render_template('host/home.html', form=form, jump_hosts=jump_hosts, regions=regions, servers=servers, system_option=SystemOption.get(db_session), build_date=get_build_date(), current_user=current_user)
def get_nonlocal_servers(db_session, region): result_list = [] if region is not None and len(region.servers) > 0: for server in region.servers: if server.server_type != ServerType.LOCAL_SERVER: result_list.append({'server_id': server.id, 'hostname': server.hostname}) else: servers = get_server_list(db_session) if servers is not None: for server in servers: if server.server_type != ServerType.LOCAL_SERVER: result_list.append({'server_id': server.id, 'hostname': server.hostname}) return jsonify(**{'data': result_list})
def home(platform, release): system_option = SystemOption.get(DBSession()) form = BrowseServerDialogForm(request.form) fill_servers(form.dialog_server.choices, get_server_list(DBSession()), False) export_software_information_form = ExportSoftwareInformationForm( request.form) return render_template( 'cco/home.html', form=form, platform=platform, release=release, system_option=system_option, export_software_information_form=export_software_information_form)
def software_profile_edit(profile_name): db_session = DBSession() software_profile = get_software_profile(db_session, profile_name) if software_profile is None: abort(404) form = SoftwareProfileForm(request.form) server_dialog_form = ServerDialogForm(request.form) fill_servers(server_dialog_form.server_dialog_server.choices, get_server_list(db_session), False) if request.method == 'POST' and form.validate(): if profile_name != form.profile_name.data and \ get_software_profile(db_session, form.profile_name.data) is not None: return render_template('conformance/profile_edit.html', form=form, server_dialog_form=server_dialog_form, system_option=SystemOption.get(db_session), duplicate_error=True) software_profile.name = form.profile_name.data software_profile.description = form.description.data software_profile.packages = ','.join( [l for l in form.software_packages.data.splitlines() if l]), db_session.commit() return redirect(url_for('conformance.home')) else: form.profile_name.data = software_profile.name form.description.data = software_profile.description if software_profile.packages is not None: form.software_packages.data = '\n'.join( software_profile.packages.split(',')) return render_template('conformance/profile_edit.html', form=form, server_dialog_form=server_dialog_form, system_option=SystemOption.get(db_session))
def software_profile_create(): # if not can_create_user(current_user): # abort(401) db_session = DBSession() form = SoftwareProfileForm(request.form) server_dialog_form = ServerDialogForm(request.form) fill_servers(server_dialog_form.server_dialog_server.choices, get_server_list(db_session), False) if request.method == 'POST' and form.validate(): software_profile = get_software_profile(db_session, form.profile_name.data) if software_profile is not None: return render_template('conformance/profile_edit.html', form=form, system_option=SystemOption.get(db_session), duplicate_error=True) software_profile = SoftwareProfile( name=form.profile_name.data, description=form.description.data, packages=','.join( [l for l in form.software_packages.data.splitlines() if l]), created_by=current_user.username) db_session.add(software_profile) db_session.commit() return redirect(url_for('conformance.home')) else: return render_template('conformance/profile_edit.html', form=form, server_dialog_form=server_dialog_form, system_option=SystemOption.get(db_session))
def api_get_server_repositories(request): validate_url_parameters(request, [KEY_HOSTNAME]) rows = [] db_session = DBSession() hostname = request.args.get(KEY_HOSTNAME) if hostname: server = get_server(db_session, hostname) if server is None: raise ValueError( "Server repository '{}' does not exist in the database.". format(hostname)) servers = [server] else: servers = get_server_list(db_session) for server in servers: if server is not None: row = dict() row[KEY_HOSTNAME] = server.hostname row[KEY_SERVER_TYPE] = server.server_type for req in params_dict[server.server_type]: row[req] = server.__getattribute__( req) if server.__getattribute__(req) is not None else '' row[server_url_dict[server.server_type]] = server.server_url if not is_empty(server_directory_dict[server.server_type]): row[server_directory_dict[ server.server_type]] = server.server_directory rows.append(row) return jsonify(**{RESPONSE_ENVELOPE: {'server_repository_list': rows}})
def handle_schedule_install_form(request, db_session, hostname, install_job=None): host = get_host(db_session, hostname) if host is None: abort(404) return_url = get_return_url(request, 'host_dashboard.home') form = HostScheduleInstallForm(request.form) # Retrieves all the install jobs for this host. This will allow # the user to select which install job this install job can depend on. install_jobs = db_session.query(InstallJob).filter( InstallJob.host_id == host.id).order_by(InstallJob.scheduled_time.asc()).all() region_servers = host.region.servers # Returns all server repositories if the region does not have any server repository designated. if is_empty(region_servers): region_servers = get_server_list(db_session) # Fills the selections fill_servers(form.server_dialog_server.choices, region_servers) fill_servers(form.server_modal_dialog_server.choices, region_servers) fill_servers(form.cisco_dialog_server.choices, region_servers, False) fill_dependency_from_host_install_jobs(form.dependency.choices, install_jobs, (-1 if install_job is None else install_job.id)) fill_custom_command_profiles(db_session, form.custom_command_profile.choices) if request.method == 'POST': if install_job is not None: # In Edit mode, the install_action UI on HostScheduleForm is disabled (not allow to change). # Thus, there will be no value returned by form.install_action.data. So, re-use the existing ones. install_action = [install_job.install_action] else: install_action = form.install_action.data scheduled_time = form.scheduled_time_UTC.data software_packages = form.software_packages.data.split() server_id = form.hidden_server.data server_directory = form.hidden_server_directory.data pending_downloads = form.hidden_pending_downloads.data.split() custom_command_profile_ids = [str(i) for i in form.custom_command_profile.data] # install_action is a list object which may contain multiple install actions. # If only one install_action, accept the selected dependency if any if len(install_action) == 1: dependency = int(form.dependency.data) create_or_update_install_job(db_session=db_session, host_id=host.id, install_action=install_action[0], scheduled_time=scheduled_time, software_packages=software_packages, server_id=server_id, server_directory=server_directory, pending_downloads=pending_downloads, custom_command_profile_ids=custom_command_profile_ids, dependency=dependency, created_by=current_user.username, install_job=install_job) else: # The dependency on each install action is already indicated in the implicit ordering in the selector. # If the user selected Pre-Upgrade and Install Add, Install Add (successor) will # have Pre-Upgrade (predecessor) as the dependency. dependency = 0 for one_install_action in install_action: new_install_job = create_or_update_install_job(db_session=db_session, host_id=host.id, install_action=one_install_action, scheduled_time=scheduled_time, software_packages=software_packages, server_id=server_id, server_directory=server_directory, pending_downloads=pending_downloads, custom_command_profile_ids=custom_command_profile_ids, dependency=dependency, created_by=current_user.username, install_job=install_job) dependency = new_install_job.id return redirect(url_for(return_url, hostname=hostname)) elif request.method == 'GET': # Initialize the hidden fields form.hidden_server.data = -1 form.hidden_selected_hosts.data = '' form.hidden_server_name.data = '' form.hidden_server_directory.data = '' form.hidden_pending_downloads.data = '' form.hidden_edit.data = install_job is not None # In Edit mode if install_job is not None: form.install_action.data = install_job.install_action if install_job.server_id is not None: form.hidden_server.data = install_job.server_id server = get_server_by_id(db_session, install_job.server_id) if server is not None: form.hidden_server_name.data = server.hostname form.hidden_server_directory.data = '' if install_job.server_directory is None else install_job.server_directory form.hidden_pending_downloads.data = '' if install_job.pending_downloads is None else install_job.pending_downloads # Form a line separated list for the textarea if install_job.packages is not None: form.software_packages.data = '\n'.join(install_job.packages.split(',')) form.dependency.data = str(install_job.dependency) if install_job.scheduled_time is not None: form.scheduled_time_UTC.data = get_datetime_string(install_job.scheduled_time) if install_job.custom_command_profile_ids: ids = [int(id) for id in install_job.custom_command_profile_ids.split(',')] form.custom_command_profile.data = ids return render_template('host/schedule_install.html', form=form, system_option=SystemOption.get(db_session), host=host, server_time=datetime.datetime.utcnow(), install_job=install_job, return_url=return_url)
def handle_schedule_install_form(request, db_session, hostname, install_job=None): host = get_host(db_session, hostname) if host is None: abort(404) return_url = get_return_url(request, 'host_dashboard.home') form = HostScheduleInstallForm(request.form) # Retrieves all the install jobs for this host. This will allow # the user to select which install job this install job can depend on. install_jobs = db_session.query(InstallJob).filter( InstallJob.host_id == host.id).order_by( InstallJob.scheduled_time.asc()).all() region_servers = host.region.servers # Returns all server repositories if the region does not have any server repository designated. if is_empty(region_servers): region_servers = get_server_list(db_session) # Fills the selections fill_servers(form.server_dialog_server.choices, region_servers) fill_servers(form.server_modal_dialog_server.choices, region_servers) fill_servers(form.cisco_dialog_server.choices, region_servers, False) fill_dependency_from_host_install_jobs( form.dependency.choices, install_jobs, (-1 if install_job is None else install_job.id)) fill_custom_command_profiles(db_session, form.custom_command_profile.choices) if request.method == 'POST': if install_job is not None: # In Edit mode, the install_action UI on HostScheduleForm is disabled (not allow to change). # Thus, there will be no value returned by form.install_action.data. So, re-use the existing ones. install_action = [install_job.install_action] else: install_action = form.install_action.data scheduled_time = form.scheduled_time_UTC.data software_packages = form.software_packages.data.split() server_id = form.hidden_server.data server_directory = form.hidden_server_directory.data pending_downloads = form.hidden_pending_downloads.data.split() custom_command_profile_ids = [ str(i) for i in form.custom_command_profile.data ] # install_action is a list object which may contain multiple install actions. # If only one install_action, accept the selected dependency if any if len(install_action) == 1: dependency = int(form.dependency.data) create_or_update_install_job( db_session=db_session, host_id=host.id, install_action=install_action[0], scheduled_time=scheduled_time, software_packages=software_packages, server_id=server_id, server_directory=server_directory, pending_downloads=pending_downloads, custom_command_profile_ids=custom_command_profile_ids, dependency=dependency, created_by=current_user.username, install_job=install_job) else: # The dependency on each install action is already indicated in the implicit ordering in the selector. # If the user selected Pre-Upgrade and Install Add, Install Add (successor) will # have Pre-Upgrade (predecessor) as the dependency. dependency = 0 for one_install_action in install_action: new_install_job = create_or_update_install_job( db_session=db_session, host_id=host.id, install_action=one_install_action, scheduled_time=scheduled_time, software_packages=software_packages, server_id=server_id, server_directory=server_directory, pending_downloads=pending_downloads, custom_command_profile_ids=custom_command_profile_ids, dependency=dependency, created_by=current_user.username, install_job=install_job) dependency = new_install_job.id return redirect(url_for(return_url, hostname=hostname)) elif request.method == 'GET': # Initialize the hidden fields form.hidden_server.data = -1 form.hidden_selected_hosts.data = '' form.hidden_server_name.data = '' form.hidden_server_directory.data = '' form.hidden_pending_downloads.data = '' form.hidden_edit.data = install_job is not None # In Edit mode if install_job is not None: form.install_action.data = install_job.install_action if install_job.server_id is not None: form.hidden_server.data = install_job.server_id server = get_server_by_id(db_session, install_job.server_id) if server is not None: form.hidden_server_name.data = server.hostname form.hidden_server_directory.data = '' if install_job.server_directory is None else install_job.server_directory form.hidden_pending_downloads.data = '' if install_job.pending_downloads is None else install_job.pending_downloads # Form a line separated list for the textarea if install_job.packages is not None: form.software_packages.data = '\n'.join( install_job.packages.split(',')) form.dependency.data = str(install_job.dependency) if install_job.scheduled_time is not None: form.scheduled_time_UTC.data = get_datetime_string( install_job.scheduled_time) if install_job.custom_command_profile_ids: ids = [ int(id) for id in install_job.custom_command_profile_ids.split(',') ] form.custom_command_profile.data = ids return render_template('host/schedule_install.html', form=form, system_option=SystemOption.get(db_session), host=host, server_time=datetime.datetime.utcnow(), install_job=install_job, return_url=return_url)