diff options
author | Parker Berberian <pberberian@iol.unh.edu> | 2018-10-10 16:06:47 -0400 |
---|---|---|
committer | Parker Berberian <pberberian@iol.unh.edu> | 2018-10-15 13:16:11 -0400 |
commit | 1f3a770d2547848590f39e9d9b9bdffeb94eec14 (patch) | |
tree | 97222e5facd1a242d951c38482315057b5790d51 /src/api/views.py | |
parent | 6d4019e59eda897384e9c00d1daf8b2ce87d128f (diff) |
Lab as a Service 2.0
See changes here:
https://wiki.opnfv.org/display/INF/Pharos+Laas
Change-Id: I59ada5f98e70a28d7f8c14eab3239597e236ca26
Signed-off-by: Sawyer Bergeron <sbergeron@iol.unh.edu>
Signed-off-by: Parker Berberian <pberberian@iol.unh.edu>
Diffstat (limited to 'src/api/views.py')
-rw-r--r-- | src/api/views.py | 101 |
1 files changed, 83 insertions, 18 deletions
diff --git a/src/api/views.py b/src/api/views.py index b873ef1..cefd131 100644 --- a/src/api/views.py +++ b/src/api/views.py @@ -1,5 +1,6 @@ ############################################################################## # Copyright (c) 2016 Max Breitenfeldt and others. +# Copyright (c) 2018 Parker Berberian, Sawyer Bergeron, and others. # # All rights reserved. This program and the accompanying materials # are made available under the terms of the Apache License, Version 2.0 @@ -8,17 +9,23 @@ ############################################################################## -from django.contrib.auth.decorators import login_required, user_passes_test +from django.contrib.auth.decorators import login_required from django.shortcuts import redirect from django.utils.decorators import method_decorator from django.views import View +from django.http.response import JsonResponse from rest_framework import viewsets from rest_framework.authtoken.models import Token +from django.views.decorators.csrf import csrf_exempt -from api.serializers import * +import json + +from api.serializers.booking_serializer import * +from api.serializers.old_serializers import NotifierSerializer, UserSerializer from account.models import UserProfile from booking.models import Booking -from dashboard.models import Resource, Server, ResourceStatus +from notifier.models import Notifier +from api.models import * class BookingViewSet(viewsets.ModelViewSet): @@ -27,29 +34,16 @@ class BookingViewSet(viewsets.ModelViewSet): filter_fields = ('resource', 'id') -class ServerViewSet(viewsets.ModelViewSet): - queryset = Server.objects.all() - serializer_class = ServerSerializer - filter_fields = ('resource', 'name') - - -class ResourceViewSet(viewsets.ModelViewSet): - queryset = Resource.objects.all() - serializer_class = ResourceSerializer - filter_fields = ('name', 'id') - -class ResourceStatusViewSet(viewsets.ModelViewSet): - queryset = ResourceStatus.objects.all() - serializer_class = ResourceStatusSerializer - class NotifierViewSet(viewsets.ModelViewSet): queryset = Notifier.objects.none() serializer_class = NotifierSerializer + class UserViewSet(viewsets.ModelViewSet): queryset = UserProfile.objects.all() serializer_class = UserSerializer + @method_decorator(login_required, name='dispatch') class GenerateTokenView(View): def get(self, request, *args, **kwargs): @@ -59,3 +53,74 @@ class GenerateTokenView(View): token.delete() Token.objects.create(user=user) return redirect('account:settings') + + +def lab_inventory(request, lab_name=""): + lab_token = request.META.get('HTTP_AUTH_TOKEN') + lab_manager = LabManagerTracker.get(lab_name, lab_token) + return JsonResponse(lab_manager.get_inventory(), safe=False) + + +def lab_status(request, lab_name=""): + lab_token = request.META.get('HTTP_AUTH_TOKEN') + lab_manager = LabManagerTracker.get(lab_name, lab_token) + if request.method == "POST": + return JsonResponse(lab_manager.set_status(request.POST), safe=False) + return JsonResponse(lab_manager.get_status(), safe=False) + + +def lab_profile(request, lab_name=""): + lab_token = request.META.get('HTTP_AUTH_TOKEN') + lab_manager = LabManagerTracker.get(lab_name, lab_token) + return JsonResponse(lab_manager.get_profile(), safe=False) + + +@csrf_exempt +def specific_task(request, lab_name="", job_id="", task_id=""): + lab_token = request.META.get('HTTP_AUTH_TOKEN') + LabManagerTracker.get(lab_name, lab_token) # Authorize caller, but we dont need the result + + if request.method == "POST": + task = get_task(task_id) + if 'status' in request.POST: + task.status = request.POST.get('status') + if 'message' in request.POST: + task.message = request.POST.get('message') + task.save() + d = {} + d['task'] = task.config.get_delta() + m = {} + m['status'] = task.status + m['job'] = str(task.job) + m['message'] = task.message + d['meta'] = m + response = json.dumps(d) + return JsonResponse(response) + elif request.method == "GET": + return JsonResponse(get_task(task_id).config.get_delta()) + + +def specific_job(request, lab_name="", job_id=""): + lab_token = request.META.get('HTTP_AUTH_TOKEN') + lab_manager = LabManagerTracker.get(lab_name, lab_token) + if request.method == "POST": + return JsonResponse(lab_manager.update_job(job_id, request.POST), safe=False) + return JsonResponse(lab_manager.get_job(job_id), safe=False) + + +def new_jobs(request, lab_name=""): + lab_token = request.META.get('HTTP_AUTH_TOKEN') + lab_manager = LabManagerTracker.get(lab_name, lab_token) + return JsonResponse(lab_manager.get_new_jobs(), safe=False) + + +def current_jobs(request, lab_name=""): + lab_token = request.META.get('HTTP_AUTH_TOKEN') + lab_manager = LabManagerTracker.get(lab_name, lab_token) + return JsonResponse(lab_manager.get_current_jobs(), safe=False) + + +def done_jobs(request, lab_name=""): + lab_token = request.META.get('HTTP_AUTH_TOKEN') + lab_manager = LabManagerTracker.get(lab_name, lab_token) + return JsonResponse(lab_manager.get_done_jobs(), safe=False) |