def do_reserve(): if request.post_vars: opengnsys = Ognsys(db) if opengnsys.set_apikey(request.post_vars.ou_id): my_context = Storage(**request.post_vars) my_context['db'] = db my_context['user_id'] = auth.user_id my_context['num_retries'] = 0 connection = Connection(my_context) reserve = connection.do_reserve() logger.log(auth.user.first_name, auth.user.last_name, reserve['equipo_reservado']['name'], reserve['equipo_reservado']['ip'], "do_reserve") return json.dumps(reserve) else: return json.dumps({ 'error', 'Error de inicialización, compruebe configuración opengnsys' }) else: return json.dumps({'error', 'Error haciendo reserva status'})
def ous(): opengnsys = Ognsys(db) opengnsys.synchronize_table_ous(db) grid = SQLFORM.grid(opengnsys.get_query_ous(db),fields=[db.ous_setup.ou_name, db.ous_setup.ou_user], csv=False, details=False, deletable=False, paginate = 10) return dict(grid=grid)
def labs(): opengnsys = Ognsys(db) if opengnsys.set_apikey(request.post_vars.ou_id): labs_on = ou.get_labs_on(request.post_vars.ou_id) return json.dumps(labs_on) else: return json.dumps({'error': "Error de acceso. Por favor compruebe configuración de usuario y contraseña de la OU"})
def clients(): if (__user_has_reserve()) and (auth.has_membership(group_id='admin') == False): return json.dumps({'error': "Tiene reservas activas. Por favor, cancelelas antes de realizar una nueva."}) else: opengnsys = Ognsys(db) if opengnsys.set_apikey(request.post_vars.ou_id): lab = Lab(request.post_vars.ou_id, request.post_vars.lab_id) return json.dumps(lab.get_remote_clients()) else: return json.dumps({'error': "Error de acceso. Por favor compruebe configuración de usuario y contraseña de la OU"})
def ous(): opengnsys = Ognsys(db) active_reserves = ActiveReserves(db, auth.user_id, auth.user_groups.values()) check_time = adoDB_openRlabs_setup.getSetup_OpenRLabs(db)['seconds_to_wait'] return dict(ous=opengnsys.get_ous(), services=adoDB_services.get_services(db), maxtime_reserve = adoDB_openRlabs_setup.get_maxtime_reserve(db), active_reserves= active_reserves.get_reserves(), exits_reserves = active_reserves.exits_reserves(), check_time = check_time )
def getEventsLogout(): print('Evento producido: logout') opengnsys = Ognsys(db) if opengnsys.set_apikey(request.post_vars.ou_id): my_context = Storage(**request.vars) my_context['db'] = db client = Client(my_context) client.unreserve_remote_pc() else: print({'error': 'Error de inicialización'})
def unreserve(): opengnsys = Ognsys(db) if opengnsys.set_apikey(request.post_vars.ou_id): my_context = Storage(**request.post_vars) my_context['db'] = db client = Client(my_context) client.unreserve_remote_pc() return json.dumps({"response": "200 OK"}) else: return json.dumps({"response": "500 Innternal Error"})
def check_pc_status(): print('check_status') if request.post_vars: opengnsys = Ognsys(db) if opengnsys.set_apikey(request.post_vars.ou_id): my_context = Storage(**request.post_vars) my_context['db'] = db connection = Connection(my_context) pc_status_info = connection.check_pc_status() if 'error' in pc_status_info: print('unreserve') client = Client(my_context) client.unreserve_remote_pc() logger.log(auth.user.first_name, auth.user.last_name, request.post_vars.name, request.post_vars.ip, "reserve_error") # Key db raise error in json.load if 'equipo_reservado' in pc_status_info: if 'db' in pc_status_info['equipo_reservado']: pc_status_info['equipo_reservado']['db'] = None return json.dumps(pc_status_info) else: return json.dumps({ 'error', 'Error de inicialización, compruebe configuración opengnsys' }) else: return json.dumps({'error', 'Error chequeando status'})