1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
##############################################################################
# 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.shortcuts import render, redirect
from laas_dashboard.settings import PROJECT
from django.http import HttpResponse
from liblaas.views import user_get_user
from workflow.forms import BookingMetaForm
from account.models import UserProfile
def login(request):
return render(request, "dashboard/login.html", {'title': 'Authentication Required'})
def design_a_pod_view(request):
if request.method != "GET":
return HttpResponse(status=405)
if not request.user.is_authenticated:
return login(request)
profile = UserProfile.objects.get(user=request.user)
if (not profile or profile.ipa_username == None):
return redirect("dashboard:index")
constraints = get_workflow_contraints(PROJECT)
template = "workflow/design_a_pod.html"
context = {
"constraints": constraints,
}
return render(request, template, context)
def book_a_pod_view(request):
if request.method != "GET":
return HttpResponse(status=405)
if not request.user.is_authenticated:
return login(request)
profile = UserProfile.objects.get(user=request.user)
if (not profile or profile.ipa_username == None):
return redirect("dashboard:index")
vpn_user = user_get_user(profile.ipa_username)
# These booleans need to be represented as strings, due to the way jinja interprets them
prereqs = {
"company": "true" if ("ou" in vpn_user and vpn_user["ou"] != "") else "false",
"keys": "true" if ("ipasshpubkey" in vpn_user) and (len(vpn_user["ipasshpubkey"]) > 0) else "false"
}
template = "workflow/book_a_pod.html"
context = {
"form": BookingMetaForm(initial={}, user_initial=[], owner=request.user),
"prereqs": prereqs
}
return render(request, template, context)
def get_workflow_contraints(project: str) -> dict:
if project == 'anuket':
return {
"max_hosts": 8,
}
if project == 'lfedge':
return {
"max_hosts": "null",
}
return {}
|