blob: 4fb29cbda13771f4cb838c742f165db4a0e4af2e [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
Scott Baker823b7212014-06-16 10:25:39 -070022 return HttpResponse(json.dumps(result), content_type='application/javascript')
Scott Bakerc7325a42014-05-30 16:06:46 -070023
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'
Scott Baker823b7212014-06-16 10:25:39 -070045 return HttpResponse(json.dumps("Success"), content_type='application/javascript')
Scott Bakerc7325a42014-05-30 16:06:46 -070046
47class DashboardAjaxView(View):
48 def get(self, request, **kwargs):
Scott Baker823b7212014-06-16 10:25:39 -070049 return HttpResponse(json.dumps(getCDNOperatorData(True)), content_type='application/javascript')