Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1 | #views.py |
Siobhan Tully | 06d2c03 | 2014-02-23 23:48:52 -0500 | [diff] [blame] | 2 | from django.views.generic import TemplateView, View |
| 3 | import datetime |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 4 | |
Siobhan Tully | 06d2c03 | 2014-02-23 23:48:52 -0500 | [diff] [blame] | 5 | import json |
Siobhan Tully | 90040c2 | 2014-01-13 23:47:24 -0500 | [diff] [blame] | 6 | from core.models import Slice,SliceRole,SlicePrivilege,Site,Reservation |
Siobhan Tully | 06d2c03 | 2014-02-23 23:48:52 -0500 | [diff] [blame] | 7 | from django.http import HttpResponse |
| 8 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 9 | |
| 10 | class DashboardWelcomeView(TemplateView): |
| 11 | template_name = 'admin/dashboard/welcome.html' |
| 12 | |
| 13 | def get(self, request, *args, **kwargs): |
| 14 | context = self.get_context_data(**kwargs) |
Siobhan Tully | 90040c2 | 2014-01-13 23:47:24 -0500 | [diff] [blame] | 15 | try: |
| 16 | site = Site.objects.filter(id=request.user.site.id) |
| 17 | except: |
| 18 | site = Site.objects.filter(name="Princeton") |
| 19 | context['site'] = site[0] |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 20 | |
Siobhan Tully | 06d2c03 | 2014-02-23 23:48:52 -0500 | [diff] [blame] | 21 | context['userSliceInfo'] = getSliceInfo(request, context) |
| 22 | context['cdnData'] = getCDNOperatorData(); |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 23 | return self.render_to_response(context=context) |
Siobhan Tully | e18b344 | 2014-02-23 14:23:34 -0500 | [diff] [blame] | 24 | |
Siobhan Tully | 06d2c03 | 2014-02-23 23:48:52 -0500 | [diff] [blame] | 25 | def getSliceInfo(request, context): |
| 26 | sliceList = Slice.objects.all() |
| 27 | slicePrivs = SlicePrivilege.objects.filter(user=request.user) |
| 28 | userSliceInfo = [] |
| 29 | for entry in slicePrivs: |
Siobhan Tully | e18b344 | 2014-02-23 14:23:34 -0500 | [diff] [blame] | 30 | |
Siobhan Tully | 06d2c03 | 2014-02-23 23:48:52 -0500 | [diff] [blame] | 31 | try: |
| 32 | reservationList = Reservation.objects.filter(slice=entry.slice) |
| 33 | reservations = (True,reservationList) |
| 34 | |
| 35 | except: |
| 36 | reservations = None |
| 37 | |
| 38 | userSliceInfo.append({'slice': Slice.objects.get(id=entry.slice.id), |
| 39 | 'role': SliceRole.objects.get(id=entry.role.id).role, |
| 40 | 'reservations': reservations}) |
| 41 | return userSliceInfo |
| 42 | |
| 43 | |
| 44 | def getCDNOperatorData(randomizeData = False): |
| 45 | cdnData = { |
| 46 | "Arizona": { |
| 47 | "lat": 32.2333, |
| 48 | "long": -110.94799999999998, |
| 49 | "health": 0, |
| 50 | "numNodes": 15, |
| 51 | "numHPCSlivers": 2, |
| 52 | "siteUrl": "http://www.cs.arizona.edu/" |
| 53 | }, |
| 54 | "I2 Singapore": { |
| 55 | "lat": 1.33544, |
| 56 | "long": 103.88999999999999, |
| 57 | "health": 0, |
| 58 | "numNodes": 15, |
| 59 | "numHPCSlivers": 5, |
| 60 | "siteUrl": "http://www.internet2.edu/" |
| 61 | }, |
| 62 | "ON.Lab": { |
| 63 | "lat": 37.452955, |
| 64 | "long": -122.18176599999998, |
| 65 | "health": 0, |
| 66 | "numNodes": 45, |
| 67 | "numHPCSlivers": 12, |
| 68 | "siteUrl": "http://www.onlab.us/" |
| 69 | }, |
| 70 | "I2 Washington DC": { |
| 71 | "lat": 38.009, |
| 72 | "long": -77.00029999999998, |
| 73 | "health": 0, |
| 74 | "numNodes": 50, |
| 75 | "numHPCSlivers": 7, |
| 76 | "siteUrl": "http://www.internet2.edu/" |
| 77 | }, |
| 78 | "I2 Seattle": { |
| 79 | "lat": 47.6531, |
| 80 | "long": -122.31299999999999, |
| 81 | "health": 0, |
| 82 | "numNodes": 100, |
| 83 | "numHPCSlivers": 10, |
| 84 | "siteUrl": "http://www.internet2.edu/" |
| 85 | }, |
| 86 | "I2 Salt Lake City": { |
| 87 | "lat": 40.7659, |
| 88 | "long": -111.844, |
| 89 | "health": 0, |
| 90 | "numNodes": 35, |
| 91 | "numHPCSlivers": 10, |
| 92 | "siteUrl": "http://www.internet2.edu/" |
| 93 | }, |
| 94 | "I2 New York": { |
| 95 | "lat": 40.72, |
| 96 | "long": -73.99000000000001, |
| 97 | "health": 0, |
| 98 | "numNodes": 25, |
| 99 | "numHPCSlivers": 4, |
| 100 | "siteUrl": "http://www.internet2.edu/" |
| 101 | }, |
| 102 | "I2 Los Angeles": { |
| 103 | "lat": 33.2505, |
| 104 | "long": -117.50299999999999, |
| 105 | "health": 0, |
| 106 | "numNodes": 20, |
| 107 | "numHPCSlivers": 10, |
| 108 | "siteUrl": "http://www.internet2.edu/" |
| 109 | }, |
| 110 | "I2 Kansas City": { |
| 111 | "lat": 39.0012, |
| 112 | "long": -94.00630000000001, |
| 113 | "health": 0, |
| 114 | "numNodes": 17, |
| 115 | "numHPCSlivers": 8, |
| 116 | "siteUrl": "http://www.internet2.edu/" |
| 117 | }, |
| 118 | "I2 Houston": { |
| 119 | "lat": 29.0077, |
| 120 | "long": -95.00369999999998, |
| 121 | "health": 0, |
| 122 | "numNodes": 15, |
| 123 | "numHPCSlivers": 10, |
| 124 | "siteUrl": "http://www.internet2.edu/" |
| 125 | }, |
| 126 | "I2 Chicago": { |
| 127 | "lat": 41.0085, |
| 128 | "long": -87.00650000000002, |
| 129 | "health": 0, |
| 130 | "numNodes": 15, |
| 131 | "numHPCSlivers": 10, |
| 132 | "siteUrl": "http://www.internet2.edu/" |
| 133 | }, |
| 134 | "I2 Atlanta": { |
| 135 | "lat": 33.0075, |
| 136 | "long": -84.00380000000001, |
| 137 | "health": 0, |
| 138 | "numNodes": 15, |
| 139 | "numHPCSlivers": 10, |
| 140 | "siteUrl": "http://www.internet2.edu/" |
| 141 | }, |
| 142 | "MaxPlanck": { |
| 143 | "lat": 49.14, |
| 144 | "long": 6.588999999999942, |
| 145 | "health": 0, |
| 146 | "numNodes": 15, |
| 147 | "numHPCSlivers": 10, |
| 148 | "siteUrl": "http://www.mpi-sws.mpg.de/" |
| 149 | }, |
| 150 | "GeorgiaTech": { |
| 151 | "lat": 33.7772, |
| 152 | "long": -84.39760000000001, |
| 153 | "health": 0, |
| 154 | "numNodes": 15, |
| 155 | "numHPCSlivers": 10, |
| 156 | "siteUrl": "http://www.gatech.edu/" |
| 157 | }, |
| 158 | "Princeton": { |
| 159 | "lat": 40.3502, |
| 160 | "long": -74.6524, |
| 161 | "health": 0, |
| 162 | "numNodes": 15, |
| 163 | "numHPCSlivers": 10, |
| 164 | "siteUrl": "http://princeton.edu/" |
| 165 | }, |
| 166 | "Washington": { |
| 167 | "lat": 47.6531, |
| 168 | "long": -122.31299999999999, |
| 169 | "health": 0, |
| 170 | "numNodes": 15, |
| 171 | "numHPCSlivers": 10, |
| 172 | "siteUrl": "https://www.washington.edu/" |
| 173 | }, |
| 174 | "Stanford": { |
| 175 | "lat": 37.4294, |
| 176 | "long": -122.17200000000003, |
| 177 | "health": 0, |
| 178 | "numNodes": 15, |
| 179 | "numHPCSlivers": 10, |
| 180 | "siteUrl": "http://www.stanford.edu/" |
| 181 | }, |
| 182 | } |
| 183 | |
| 184 | if randomizeData: |
| 185 | cdnData["Siobhan"] = { "lat": 43.34203, "long": -70.56351, "health": 10, "numNodes": 5, "numHPCSlivers": 3, "siteUrl": "https:devonrexes"} |
| 186 | del cdnData["Princeton"] |
| 187 | cdnData["I2 Seattle"]['siteUrl'] = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") |
| 188 | cdnData["I2 Salt Lake City"]["numHPCSlivers"] = 34 |
| 189 | |
| 190 | |
| 191 | return cdnData |
| 192 | |
| 193 | class DashboardAjaxView(View): |
| 194 | def get(self, request, **kwargs): |
| 195 | return HttpResponse(json.dumps(getCDNOperatorData(True)), mimetype='application/javascript') |
| 196 | |