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/workflow/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/workflow/views.py')
-rw-r--r-- | src/workflow/views.py | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/src/workflow/views.py b/src/workflow/views.py new file mode 100644 index 0000000..85e4eac --- /dev/null +++ b/src/workflow/views.py @@ -0,0 +1,108 @@ +############################################################################## +# 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 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + + +from django.http import HttpResponse, HttpRequest, HttpResponseGone +from django.urls import reverse +from django.shortcuts import render, redirect +from django import forms + +import uuid + +from workflow.forms import * +from workflow.workflow_manager import * + +import logging +logger = logging.getLogger(__name__) + + +def attempt_auth(request): + try: + manager = ManagerTracker.managers[request.session['manager_session']] + + return manager + + except KeyError: + return None + +def delete_session(request): + try: + manager = ManagerTracker.managers[request.session['manager_session']] + del ManagerTracker.managers[request.session['manager_session']] + return HttpResponse('') + except KeyError: + return None + +def step_view(request): + manager = attempt_auth(request) + if not manager: + #no manager found, redirect to "lost" page + return no_workflow(request) + if request.GET.get('step') is not None: + manager.goto(int(request.GET.get('step'))) + return manager.render(request) + +def manager_view(request): + manager = attempt_auth(request) + + if not manager: + return HttpResponseGone("No session found that relates to current request") + + if request.method == 'GET': #no need for this statement if only intercepting post requests + + #return general context for viewport page + return manager.status(request) + + if request.method == 'POST': + if request.POST.get('add') is not None: + logger.debug("add found") + target_id = None + if 'target' in request.POST: + target_id=int(request.POST.get('target')) + manager.add_workflow(workflow_type=int(request.POST.get('add')), target_id=target_id) + elif request.POST.get('edit') is not None and request.POST.get('edit_id') is not None: + logger.debug("edit found") + manager.add_workflow(workflow_type=request.POST.get('edit'), edit_object=int(request.POST.get('edit_id'))) + elif request.POST.get('cancel') is not None: + mgr = ManagerTracker.managers[request.session['manager_session']] + del ManagerTracker.managers[request.session['manager_session']] + del mgr + + return manager.status(request) + +def viewport_view(request): + if not request.user.is_authenticated: + return login(request) + + manager = attempt_auth(request) + if manager is None: + return no_workflow(request) + + if request.method == 'GET': + return render(request, 'workflow/viewport-base.html') + else: + pass + +def create_session(wf_type, request): + wf = int(wf_type) + smgr = SessionManager(request=request) + smgr.add_workflow(workflow_type=wf, target_id=request.POST.get("target")) + manager_uuid = uuid.uuid4().hex + ManagerTracker.getInstance().managers[manager_uuid] = smgr + + return manager_uuid + +def no_workflow(request): + + logger.debug("There is no active workflow") + + return render(request, 'workflow/no_workflow.html', {'title': "Not Found"}) + +def login(request): + return render(request, "dashboard/login.html", {'title': 'Authentication Required'}) |