Beispiel #1
0
def settings(request, user, project_slug):
    user_permissions = get_permissions(request, project_slug, sett.PROJECT_SETTINGS_PERM)
    print(user_permissions)
    template = 'settings.html'
    project = Project.objects.filter(Q(owner=request.user) | Q(authorized=request.user), Q(slug=project_slug)).first()
    url_domain = sett.DOMAIN
    platform_users = User.objects.filter(~Q(pk=project.owner.pk))
    environments = Environment.objects.all()

    minio_keys = get_minio_keys(project)
    decrypted_key = minio_keys['project_key']
    decrypted_secret = minio_keys['project_secret']

    if request.method == 'POST':
        form = TransferProjectOwnershipForm(request.POST)
        if form.is_valid():
            new_owner_id = int(form.cleaned_data['transfer_to'])
            new_owner = User.objects.filter(pk=new_owner_id).first()
            project.owner = new_owner
            project.save()

            l = ProjectLog(project=project, module='PR', headline='Project owner',
                           description='Transferred Project ownership to {owner}'.format(owner=project.owner.username))
            l.save()

            return HttpResponseRedirect('/projects/')
    else:
        form = TransferProjectOwnershipForm()

    return render(request, template, locals())
Beispiel #2
0
def delete_deployment(request, user, project, model_id):
    user_permissions = get_permissions(request, project, sett.MONITOR_PERM)
    if not user_permissions['view']:
        request.session['oidc_id_token_expiration'] = -1
        request.session.save()
        return HttpResponse('Not authorized', status=401)
    model = Model.objects.get(id=model_id)
    instance = DeploymentInstance.objects.get(model=model)
    instance.helmchart.delete()
    return HttpResponseRedirect(
        reverse('monitor:overview',
                kwargs={
                    'user': request.user,
                    'project': project
                }))
Beispiel #3
0
def delete_lab(request, user, project, uid):
    # project = Project.objects.filter(Q(slug=project), Q(owner=request.user) | Q(authorized=request.user)).first()
    # session = Session.objects.filter(Q(id=id), Q(project=project), Q(lab_session_owner=request.user)).first()
    user_permissions = get_permissions(request, project, sett.MONITOR_PERM)
    if not user_permissions['view']:
        request.session['oidc_id_token_expiration'] = -1
        request.session.save()
        return HttpResponse('Not authorized', status=401)
    project = Project.objects.get(slug=project)
    session = Session.objects.get(id=uid, project=project)
    if session:
        session.helmchart.delete()

    return HttpResponseRedirect(
        reverse('monitor:overview',
                kwargs={
                    'user': request.user,
                    'project': str(project.slug)
                }))
Beispiel #4
0
def overview(request, user, project):
    is_authorized = True
    user_permissions = get_permissions(request, project, sett.MONITOR_PERM)
    if not user_permissions['view']:
        request.session['oidc_id_token_expiration'] = -1
        request.session.save()
        # return HttpResponse('Not authorized', status=401)
        is_authorized = False
    template = 'monitor_overview.html'
    project = Project.objects.filter(slug=project).first()

    resource_types = ['lab', 'deployment']
    q_types = ['requests', 'limits']
    r_types = ['memory_bytes', 'cpu_cores']

    resource_status = dict()
    for resource_type in resource_types:
        resource_status[resource_type] = dict()
        for q_type in q_types:
            resource_status[resource_type][q_type] = dict()
            for r_type in r_types:
                tmp = get_resource(project.slug, resource_type, q_type, r_type)

                if r_type == 'memory_bytes':
                    tmp = "{:.2f}".format(float(tmp) / 1e9 * 0.931323)
                elif tmp:
                    tmp = "{:.2f}".format(float(tmp))

                resource_status[resource_type][q_type][r_type] = tmp

    total_cpu = float(resource_status['lab']['limits']['cpu_cores']) + float(
        resource_status['deployment']['limits']['cpu_cores'])
    total_mem = float(
        resource_status['lab']['limits']['memory_bytes']) + float(
            resource_status['deployment']['limits']['memory_bytes'])
    total_cpu_req = float(
        resource_status['lab']['requests']['cpu_cores']) + float(
            resource_status['deployment']['requests']['cpu_cores'])
    total_mem_req = float(
        resource_status['lab']['requests']['memory_bytes']) + float(
            resource_status['deployment']['requests']['memory_bytes'])

    labs = Session.objects.filter(project=project)
    lab_list = get_cpu_mem(labs, project.slug, 'lab')

    deps = DeploymentInstance.objects.filter(model__project=project)
    dep_list = get_cpu_mem(deps, project.slug, 'deployment')
    print(dep_list)
    # lab_list = list()
    # for lab in labs:
    #     lab_cpu_limit = get_resource(project.slug, 'lab', 'limits', 'cpu_cores', app_name=lab.appname)
    #     lab_cpu_limit = "{:.2f}".format(float(lab_cpu_limit))
    #     lab_cpu_request = get_resource(project.slug, 'lab', 'requests', 'cpu_cores', app_name=lab.appname)
    #     lab_cpu_limit = "{:.2f}".format(float(lab_cpu_request))
    #     lab_mem_limit = get_resource(project.slug, 'lab', 'limits', 'memory_bytes', app_name=lab.appname)
    #     lab_mem_limit = "{:.2f}".format(float(lab_mem_limit)/1e9*0.931323)
    #     lab_mem_request = get_resource(project.slug, 'lab', 'requests', 'memory_bytes', app_name=lab.appname)
    #     lab_mem_request = "{:.2f}".format(float(lab_mem_request)/1e9*0.931323)
    #     lab_flavor = lab.flavor_slug
    #     lab_owner = lab.lab_session_owner.username
    #     lab_list.append((lab_owner, lab_flavor, lab_cpu_limit, lab_cpu_request, lab_mem_limit, lab_mem_request, str(lab.id)))

    return render(request, template, locals())