blob: 63ec2f2c6a6c8f9e10364bd6650ac809ad623f67 [file] [log] [blame]
Scott Bakerc7325a42014-05-30 16:06:46 -07001from view_common import *
2
3class DashboardSummaryAjaxView(View):
4 def get(self, request, **kwargs):
5 def avg(x):
6 if len(x)==0:
7 return 0
8 return float(sum(x))/len(x)
9
10 sites = getCDNOperatorData().values()
11
12 sites = [site for site in sites if site["numHPCSlivers"]>0]
13
14 total_slivers = sum( [site["numHPCSlivers"] for site in sites] )
15 total_bandwidth = sum( [site["bandwidth"] for site in sites] )
16 average_cpu = int(avg( [site["load"] for site in sites] ))
17
18 result= {"total_slivers": total_slivers,
19 "total_bandwidth": total_bandwidth,
20 "average_cpu": average_cpu}
21
22 return HttpResponse(json.dumps(result), mimetype='application/javascript')
23
24class DashboardAddOrRemoveSliverView(View):
25 # TODO: deprecate this view in favor of using TenantAddOrRemoveSliverView
26
27 def post(self, request, *args, **kwargs):
28 siteName = request.POST.get("site", None)
29 actionToDo = request.POST.get("actionToDo", "0")
30
31 siteList = [Site.objects.get(name=siteName)]
32 slice = Slice.objects.get(name="HyperCache")
33
34 if request.user.isReadOnlyUser():
35 return HttpResponseForbidden("User is in read-only mode")
36
37 if (actionToDo == "add"):
38 user_ip = request.GET.get("ip", get_ip(request))
39 slice_increase_slivers(request.user, user_ip, siteList, slice, 1)
40 elif (actionToDo == "rem"):
41 slice_decrease_slivers(request.user, siteList, slice, 1)
42
43 print '*' * 50
44 print 'Ask for site: ' + siteName + ' to ' + actionToDo + ' another HPC Sliver'
45 return HttpResponse(json.dumps("Success"), mimetype='application/javascript')
46
47class DashboardAjaxView(View):
48 def get(self, request, **kwargs):
49 return HttpResponse(json.dumps(getCDNOperatorData(True)), mimetype='application/javascript')