def stop_session(session_id): _session = helpers.get_session(session_id) if _session: _session.failed(reason=constants.SESSION_CLOSE_REASON_API_CALL) return render_json("Session %s closed successfully" % session_id, 200) else: return render_json("Session %s not found" % session_id, 404)
def get_vnc_info(session_id): vnc_proxy_port, code, _session = None, 500, helpers.get_session(session_id) if not _session or not _session.is_running: return render_json(result={}, code=code) if _session.vnc_proxy_port: return render_json(result={'vnc_proxy_port': _session.vnc_proxy_port}, code=200) (vnc_proxy_port, vnc_proxy_pid), code = start_vnc_proxy(_session.endpoint.ip, _session.endpoint.vnc_port), 200 _session.refresh() if _session.closed: kill_process(vnc_proxy_pid) return render_json(result={}, code=500) if _session.vnc_proxy_port and _session.vnc_proxy_pid: kill_process(vnc_proxy_pid) vnc_proxy_port = _session.vnc_proxy_port else: log.info("VNC Proxy(pid:{}, port:{}) was started for {}".format( vnc_proxy_pid, vnc_proxy_port, _session)) _session.vnc_proxy_port, _session.vnc_proxy_pid = vnc_proxy_port, vnc_proxy_pid _session.save() return render_json(result={'vnc_proxy_port': vnc_proxy_port}, code=code)
def get_vnc_info(session_id): result, code = {}, 500 _session = helpers.get_session(session_id) if _session and _session.endpoint_ip: if _session.vnc_helper.proxy: result, code = ( {'vnc_proxy_port': _session.vnc_helper.get_proxy_port()}, 200 ) else: _session.vnc_helper.start_proxy() result, code = ( {'vnc_proxy_port': _session.vnc_helper.get_proxy_port()}, 200 ) return render_json(result=result, code=code)
def lambda_handler(event, context): logger.info(event) logger.info(context) connection_string = get_db_string() postgres_engine = create_engine(connection_string) tables = pd.read_sql('SELECT * FROM pg_catalog.pg_tables;', con=postgres_engine) logger.info(tables) session = get_session(connection_string) table_name = 'event_v1' event_obj = prepare_event_to_insert(event, table_name) s = session() s.add(event_obj) c = s.commit() logger.info(f'Event was insert in {table_name}') return event
def get_session(session_id): session = helpers.get_session(session_id) if session: return render_json(session.info) else: return render_json("Session %s not found" % session_id, 404)
from flask import Flask, render_template, request, redirect, url_for from helpers import add_rating, get_session app = Flask(__name__) engine, Session = get_session() @app.route('/', methods=['GET', 'POST']) def log_device(): if request.method == 'POST': return redirect( url_for('.buttons', location=request.form.get('location'))) return render_template('login.html') @app.route('/buttons', methods=['GET', 'POST']) def buttons(): s = Session() if request.method == 'POST': rating = request.form.get('rating') location = request.args.get('location') print( f"calling add_rating with rating: {rating} and location: {location}" ) add_rating(Session, rating, location=request.args.get('location')) return render_template('survey.html', location=request.args.get('location'))