#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
###############################################################################
# #
# Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/ #
# Contact: beat.support@idiap.ch #
# #
# This file is part of the beat.web module of the BEAT platform. #
# #
# Commercial License Usage #
# Licensees holding valid commercial BEAT licenses may use this file in #
# accordance with the terms contained in a written agreement between you #
# and Idiap. For further information contact tto@idiap.ch #
# #
# Alternatively, this file may be used under the terms of the GNU Affero #
# Public License version 3 as published by the Free Software and appearing #
# in the file LICENSE.AGPL included in the packaging of this file. #
# The BEAT platform is distributed in the hope that it will be useful, but #
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY #
# or FITNESS FOR A PARTICULAR PURPOSE. #
# #
# You should have received a copy of the GNU Affero Public License along #
# with the BEAT platform. If not, see http://www.gnu.org/licenses/. #
# #
###############################################################################
from rest_framework import permissions
from rest_framework.decorators import api_view
from rest_framework.decorators import permission_classes
from rest_framework.response import Response
from ..code.models import Code
from .models import Environment
# ----------------------------------------------------------
[docs]@api_view(["GET"])
@permission_classes([permissions.AllowAny])
def accessible_environments_list(request):
"""Returns all accessible environments for a given user"""
# Retrieve the list of environments
environments = Environment.objects.filter(active=True).order_by("name", "version")
result = []
for environment in environments.iterator():
# Check that the user has access to the environment
(has_access, accessibility) = environment.accessibility_for(request.user)
if not (has_access):
continue
# Retrieve the details about the queues
queues = {}
for queue in environment.queues.iterator():
if request.user.has_perm("can_access", queue):
queues[queue.name] = {
"nb_slots": queue.number_of_slots(),
"memory_limit": queue.memory_limit,
"time_limit": queue.time_limit,
"nb_cores_per_slot": queue.cores_per_slot,
"max_slots_per_user": queue.max_slots_per_user,
}
# Only returns environments which effectively have queues associated
if environment.queues.count():
result.append(
{
"name": environment.name,
"version": environment.version,
"short_description": environment.short_description,
"queues": queues,
"accessibility": accessibility,
"languages": [
Code.language_identifier(x.language)
for x in environment.languages.iterator()
],
}
)
return Response(result)