def api_create_software_profile(): if not can_create(current_user): abort(401) software_profile_name = request.form['software_profile_name'] software_packages = request.form['software_packages'] db_session = DBSession() software_profile = get_software_profile(db_session, software_profile_name) if software_profile is not None: return jsonify({ 'status': 'Software profile "' + software_profile_name + '" already exists. Use a different name instead.' }) software_profile = SoftwareProfile( name=software_profile_name, packages=','.join([l for l in software_packages.splitlines() if l]), created_by=current_user.username) db_session.add(software_profile) db_session.commit() return jsonify({'status': 'OK'})
def jump_host_create(): if not can_create(current_user): abort(401) form = JumpHostForm(request.form) if request.method == 'POST' and form.validate(): db_session = DBSession() host = get_jump_host(db_session, form.hostname.data) if host is not None: return render_template('jump_host/edit.html', form=form, duplicate_error=True) create_or_update_jump_host(db_session=db_session, hostname=form.hostname.data, host_or_ip=form.host_or_ip.data, username=form.username.data, password=form.password.data, connection_type=form.connection_type.data, port_number=form.port_number.data, created_by=current_user.username) return redirect(url_for('home')) return render_template('jump_host/edit.html', form=form)
def software_profile_create(): if not can_create(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.software_profile_name.data) if software_profile is not None: return render_template('conformance/software_profile_edit.html', form=form, system_option=SystemOption.get(db_session), duplicate_error=True) software_profile = SoftwareProfile( name=form.software_profile_name.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/software_profile_edit.html', form=form, server_dialog_form=server_dialog_form, system_option=SystemOption.get(db_session))
def region_create(): if not can_create(current_user): abort(401) form = RegionForm(request.form) if request.method == 'POST' and form.validate(): db_session = DBSession() region = get_region(db_session, form.region_name.data) if region is not None: return render_template('region/edit.html', form=form, duplicate_error=True) # Compose a list of server hostnames server_names = [ get_server_by_id(db_session, id).hostname for id in request.form.getlist('selected-servers') ] try: create_or_update_region(db_session=db_session, region_name=form.region_name.data, server_repositories=",".join(server_names), created_by=current_user.username) except Exception as e: db_session.rollback() logger.exception("region_create() encountered an exception: " + e.message) return redirect(url_for('home')) return render_template('region/edit.html', form=form)
def server_create(): if not can_create(current_user): abort(401) form = ServerForm(request.form) if request.method == 'POST' and form.validate(): db_session = DBSession() server = get_server(db_session, form.hostname.data) if server is not None: return render_template('server/edit.html', form=form, duplicate_error=True) create_or_update_server_repository( db_session=db_session, hostname=form.hostname.data, server_type=form.server_type.data, server_url=form.server_url.data, username=form.username.data, password=form.password.data, vrf=form.vrf.data if form.server_type.data == ServerType.TFTP_SERVER or form.server_type.data == ServerType.FTP_SERVER else '', server_directory=form.server_directory.data, destination_on_host=form.destination_on_host.data, created_by=current_user.username) return redirect(url_for('home')) return render_template('server/edit.html', form=form)
def api_hosts(): try: if request.method == 'POST': if not can_create(g.api_user): return failed_response('Not Authorized', return_code=HTTP_NOT_AUTHORIZED) return api_host.api_create_hosts(request) elif request.method == 'GET': return api_host.api_get_hosts(request) except Exception as e: return failed_response(e.message)
def import_hosts(): if not can_create(current_user): abort(401) form = HostImportForm(request.form) fill_regions(form.region.choices) ip_range_dialog_form = IPRangeForm(request.form) #fill_regions(ip_range_dialog_form.region2.choices) return render_template('host/import_hosts.html', form=form, ip_range_dialog_form=ip_range_dialog_form)
def api_hosts(): try: if request.method == 'POST': if not can_create(g.api_user): return failed_response('Not Authorized', return_code=HTTP_NOT_AUTHORIZED) return api_host.api_create_hosts(request) elif request.method == 'GET': return api_host.api_get_hosts(request) except Exception as e: return failed_response(e.message)
def api_remove_software_profile_for_host(hostname): if not can_create(current_user): abort(401) db_session = DBSession() host = get_host(db_session, hostname) if host: host.software_profile_id = None db_session.commit() return jsonify({'status': 'OK'}) else: return jsonify({'status': 'Failed'})
def api_remove_software_profile_for_host(hostname): if not can_create(current_user): abort(401) db_session = DBSession() host = get_host(db_session, hostname) if host: host.software_profile_id = None db_session.commit() return jsonify({'status': 'OK'}) else: return jsonify({'status': 'Failed'})
def import_hosts(): if not can_create(current_user): abort(401) form = HostImportForm(request.form) fill_regions(form.region.choices) ip_range_dialog_form = IPRangeForm(request.form) #fill_regions(ip_range_dialog_form.region2.choices) return render_template('host/import_hosts.html', form=form, ip_range_dialog_form=ip_range_dialog_form)
def remove_host_enable_password(hostname): if not can_create(current_user): abort(401) db_session = DBSession() host = get_host(db_session, hostname) if host is not None: host.connection_param[0].enable_password = '' db_session.commit() return jsonify({'status': 'OK'}) else: return jsonify({'status': 'Failed'})
def api_remove_jump_host_password(hostname): if not can_create(current_user): abort(401) db_session = DBSession() host = get_jump_host(db_session, hostname) if host is not None: host.password = '' db_session.commit() return jsonify({'status': 'OK'}) else: return jsonify({'status': 'Failed'})
def import_hosts(): if not can_create(current_user): abort(401) db_session = DBSession() form = HostImportForm(request.form) ip_range_dialog_form = IPRangeForm(request.form) fill_regions(db_session, form.region.choices) fill_jump_hosts(db_session, form.jump_host.choices) fill_software_profiles(db_session, form.software_profile.choices) return render_template('host/import_hosts.html', form=form, ip_range_dialog_form=ip_range_dialog_form)
def host_create(): if not can_create(current_user): abort(401) form = HostForm(request.form) db_session = DBSession() fill_jump_hosts(db_session, form.jump_host.choices) fill_regions(db_session, form.region.choices) fill_software_profiles(db_session, form.software_profile.choices) if request.method == 'POST' and form.validate(): db_session = DBSession() try: host = get_host(db_session, form.hostname.data) if host is not None: return render_template('host/edit.html', form=form, duplicate_error=True) create_or_update_host( db_session=db_session, hostname=form.hostname.data, region_id=form.region.data, location=form.location.data, roles=form.roles.data, software_profile_id=form.software_profile.data, connection_type=form.connection_type.data, host_or_ip=form.host_or_ip.data, username=form.username.data, password=form.password.data, enable_password=form.enable_password.data, port_number=form.port_number.data, jump_host_id=form.jump_host.data, created_by=current_user.username) finally: db_session.rollback() return redirect(url_for('home')) return render_template('host/edit.html', form=form)
def software_profile_create(): if not can_create(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.software_profile_name.data) if software_profile is not None: return render_template('conformance/software_profile_edit.html', form=form, system_option=SystemOption.get(db_session), duplicate_error=True) software_profile = SoftwareProfile( name=form.software_profile_name.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/software_profile_edit.html', form=form, server_dialog_form=server_dialog_form, system_option=SystemOption.get(db_session))
def api_create_software_profile(): if not can_create(current_user): abort(401) software_profile_name = request.form['software_profile_name'] software_packages = request.form['software_packages'] db_session = DBSession() software_profile = get_software_profile(db_session, software_profile_name) if software_profile is not None: return jsonify({'status': 'Software profile "' + software_profile_name + '" already exists. Use a different name instead.'}) software_profile = SoftwareProfile( name=software_profile_name, packages=','.join([l for l in software_packages.splitlines() if l]), created_by=current_user.username) db_session.add(software_profile) db_session.commit() return jsonify({'status': 'OK'})