def stats(): return jsonify({ 'current_instances': len(redis.smembers('ports')), 'total_instances': redis.get('instances'), 'current_users': len(redis.smembers('users')), 'challenges': len(challenge_data) })
def get_instance_for(user, challenge): for instance_id in redis.smembers(challenge): instance = Instance.get(instance_id) if len(instance.users) < instance.user_limit and not redis.sismember( f'{user}_avoid', instance.container.id): if len(instance.users) + 2 > instance.user_limit: redis.sadd('new_instance_queue', challenge) instance.users.append(user) instance.save() redis.set(user, str(instance)) return instance instance = start_instance(challenge) instance.users.append(user) instance.save() redis.set(user, str(instance)) return instance
def list_instances(): return jsonify(list(redis.smembers('instance_set')))