1 from django.template import RequestContext
2 from django.shortcuts import render_to_response
4 from manifold.core.query import Query, AnalyzedQuery
5 from manifoldapi.manifoldapi import execute_query
8 from django.views.generic.base import TemplateView
10 from unfold.loginrequired import LoginRequiredView
11 from django.http import HttpResponse
12 from django.shortcuts import render
14 from unfold.page import Page
16 from myslice.configengine import ConfigEngine
18 from plugins.apply import ApplyPlugin
19 from plugins.querytable import QueryTable
20 from plugins.googlemap import GoogleMap
21 # from plugins.queryupdater import QueryUpdaterPlugin
22 from plugins.filter_status import FilterStatusPlugin
23 from plugins.testbeds import TestbedsPlugin
24 from plugins.scheduler2 import Scheduler2
27 from plugins.univbris import Univbris
28 from plugins.univbrisfoam import UnivbrisFoam
29 from plugins.univbrisfv import UnivbrisFv
30 from plugins.univbrisfvf import UnivbrisFvf
31 from plugins.univbrisfvfo import UnivbrisFvfo
32 from plugins.univbristopo import UnivbrisTopo
34 from plugins.columns_editor import ColumnsEditor
35 from plugins.sladialog import SlaDialog
36 from plugins.lists.simplelist import SimpleList
38 from myslice.theme import ThemeView
40 class SliceResourceView (LoginRequiredView, ThemeView):
41 template_name = "slice-resource-view.html"
43 def get(self, request, slicename):
45 if request.GET.get('message') :
46 msg = "Slice successfully updated"
51 metadata = page.get_metadata()
52 page.expose_js_metadata()
55 univbrisfoam_query=Query().get('ofelia-bristol-of:resource').select('urn')
56 page.enqueue_query(univbrisfoam_query)
59 resource_md = metadata.details_by_object('resource')
60 resource_fields = [column['name'] for column in resource_md['column']]
62 user_md = metadata.details_by_object('user')
63 user_fields = ['user_hrn'] # [column['name'] for column in user_md['column']]
65 # TODO The query to run is embedded in the URL
66 # Example: select slice_hrn, resource.urn, lease.resource, lease.start_time, lease.end_time from slice where slice_hrn == "ple.upmc.myslicedemo"
67 main_query = Query.get('slice').filter_by('slice_hrn', '=', slicename)
71 # - The record key is needed otherwise the storage of records
76 'resource.hostname', 'resource.type',
77 # - The facility_name and testbed_name are required for the
78 # testbeds plugin to properly work.
79 'resource.facility_name',
80 'resource.testbed_name',
85 # - The lease_id is important for NITOS identify already existing
90 #'application.measurement_point.counter'
92 # for internal use in the querytable plugin;
93 # needs to be a unique column present for each returned record
94 main_query_init_key = 'urn'
95 aq = AnalyzedQuery(main_query, metadata=metadata)
96 page.enqueue_query(main_query, analyzed_query=aq)
97 sq_resource = aq.subquery('resource')
98 sq_lease = aq.subquery('lease')
100 query_resource_all = Query.get('resource').select(resource_fields)
101 page.enqueue_query(query_resource_all)
104 #lease_md = metadata.details_by_object('lease')
105 #lease_fields = [column['name'] for column in lease_md['column']]
107 #query_lease_all = Query.get('lease').select(lease_fields)
108 #page.enqueue_query(query_lease_all)
110 # --------------------------------------------------------------------------
112 # resources as a list using datatable plugin
114 list_resources = QueryTable(
116 domid = 'resources-list',
119 query_all = query_resource_all,
122 datatables_options = {
123 'iDisplayLength': 25,
124 'bLengthChange' : True,
130 # --------------------------------------------------------------------------
131 # RESERVED RESOURCES LIST
132 # resources as a list using datatable plugin
134 list_reserved_resources = SimpleList(
141 list_reserved_leases = SimpleList(
148 # list_reserved_resources = QueryTable(
150 # domid = 'resources-reserved-list',
151 # title = 'List view',
152 # query = sq_resource,
153 # query_all = sq_resource,
156 # datatables_options = {
157 # 'iDisplayLength': 25,
158 # 'bLengthChange' : True,
159 # 'bAutoWidth' : True,
163 # --------------------------------------------------------------------------
165 # list of fields to be applied on the query
166 # this will add/remove columns in QueryTable plugin
168 filter_column_editor = ColumnsEditor(
171 query_all = query_resource_all,
172 title = "Select Columns",
173 domid = 'select-columns',
176 # --------------------------------------------------------------------------
178 # the resources part is made of a Tabs (Geographic, List),
180 map_resources = GoogleMap(
182 title = 'Geographic view',
183 domid = 'resources-map',
184 # tab's sons preferably turn this off
187 # this key is the one issued by google
188 googlemap_api_key = ConfigEngine().googlemap_api_key(),
189 # the key to use at init-time
190 init_key = main_query_init_key,
193 # To center around Europe : 53,9 / 3
199 # --------------------------------------------------------------------------
200 # LEASES Nitos Scheduler
201 # Display the leases reservation timeslots of the resources
203 resources_as_scheduler2 = Scheduler2(
207 # this is the query at the core of the slice list
209 query_lease = sq_lease,
212 # --------------------------------------------------------------------------
213 # QueryUpdater (Pending Operations)
215 # pending_resources = QueryUpdaterPlugin(
217 # title = 'Pending operations',
218 # query = main_query,
220 # # start turned off, it will open up itself when stuff comes in
223 # outline_complete = True,
224 # username = request.user,
227 # --------------------------------------------------------------------------
229 # testbeds as a list of filters
231 network_md = metadata.details_by_object('network')
232 network_fields = [column['name'] for column in network_md['column']]
234 #query_networks = Query.get('network').select(network_fields)
235 #page.enqueue_query(query_networks)
237 filter_testbeds = TestbedsPlugin(
239 domid = 'testbeds-filter',
240 title = 'Filter by testbeds',
242 #query_networks = query_networks,
243 #init_key = "network_hrn",
245 #datatables_options = {
246 # 'iDisplayLength': 25,
247 # 'bLengthChange' : True,
248 # 'bAutoWidth' : True,
252 filter_status = FilterStatusPlugin(
254 domid = "filter-status",
261 username = request.user,
265 univbrisfoamlist = UnivbrisFoam(
267 title = 'univbris_foam_ports_selection',
268 domid = 'univbris_foam_ports_selection',
269 query = univbrisfoam_query,
270 query_all = univbrisfoam_query,
272 datatables_options = {
273 'iDisplayLength': 10,
274 'bLengthChange' : True,
279 #plugin which manages the different flowspaces that the user creates, and also sends flowspaces to manifold
280 univbrisfvlist = UnivbrisFv(
282 title = 'univbris_flowspace_selection',
283 domid = 'univbris_flowspace_selection',
286 datatables_options = {
288 'bLengthChange' : True,
293 #plugin which allows the definition of a single flowspace
294 univbrisfvform = UnivbrisFvf(
296 title = 'univbris_flowspace_form',
297 domid = 'univbris_flowspace_form',
300 datatables_options = {
302 'bLengthChange' : True,
308 # --------------------------------------------------------------------------
309 # Ofelia OpenFlow Plugin
312 # plugin which display a "gathering resources" message
313 # waiting for all resources to be returned by manifold
314 univbriswelcome = Univbris(
316 title = 'univbris_welcome',
317 domid = 'univbris_welcome',
318 query = query_resource_all,
321 univbrisfoamlist = UnivbrisFoam(
323 title = 'univbris_foam_ports_selection',
324 domid = 'univbris_foam_ports_selection',
325 query = query_resource_all,
326 query_all = query_resource_all,
328 datatables_options = {
329 'iDisplayLength': 10,
330 'bLengthChange' : True,
335 #plugin which manages the different flowspaces that the user creates, and also sends flowspaces to manifold
336 univbrisfvlist = UnivbrisFv(
338 title = 'univbris_flowspace_selection',
339 domid = 'univbris_flowspace_selection',
342 sync_query = query_resource_all,
343 datatables_options = {
345 'bLengthChange' : True,
350 #plugin which allows the definition of a single flowspace
351 univbrisfvform = UnivbrisFvf(
353 title = 'univbris_flowspace_form',
354 domid = 'univbris_flowspace_form',
355 query = query_resource_all,
357 datatables_options = {
359 'bLengthChange' : True,
364 #plugin which allows the definition the match criteria on a single OPTICAL flowspace
366 univbrisofvform = UnivbrisFvfo(
368 title = 'univbris_oflowspace_form',
369 domid = 'univbris_oflowspace_form',
372 datatables_options = {
374 'bLengthChange' : True,
379 #plugin which display the gathered topology
380 univbristopology = UnivbrisTopo(
382 title = 'univbris_topology',
383 domid = 'univbris_topology',
384 query = query_resource_all,
385 #query = query_resource_all,
388 # --------------------------------------------------------------------------
389 # SLA View and accept dialog
391 sla_dialog = SlaDialog(
393 title = 'sla dialog',
396 # start turned off, it will open up itself when stuff comes in
398 domid = 'sla_dialog',
399 outline_complete = True,
400 username = request.user,
403 ## check user is pi or not
404 platform_query = Query().get('local:platform').select('platform_id','platform','gateway_type','disabled')
405 account_query = Query().get('local:account').select('user_id','platform_id','auth_type','config')
406 platform_details = execute_query(self.request, platform_query)
407 account_details = execute_query(self.request, account_query)
409 # XXX When session has expired, this is None and thus not iterable
410 for platform_detail in platform_details:
411 for account_detail in account_details:
412 if platform_detail['platform_id'] == account_detail['platform_id']:
413 if 'config' in account_detail and account_detail['config'] is not '':
414 account_config = json.loads(account_detail['config'])
415 if 'myslice' in platform_detail['platform']:
416 acc_auth_cred = account_config.get('delegated_authority_credentials','N/A')
418 if acc_auth_cred == {} or acc_auth_cred == 'N/A':
424 template_env['list_resources'] = list_resources.render(self.request)
425 template_env['list_reserved_resources'] = list_reserved_resources.render(self.request)
426 template_env['list_reserved_leases'] = list_reserved_leases.render(self.request)
428 template_env['columns_editor'] = filter_column_editor.render(self.request)
430 template_env['filter_testbeds'] = filter_testbeds.render(self.request)
431 template_env['filter_status'] = filter_status.render(self.request)
432 template_env['apply'] = apply.render(self.request)
434 template_env['map_resources'] = map_resources.render(self.request)
435 template_env['scheduler'] = resources_as_scheduler2.render(self.request)
438 template_env['welcome'] = univbriswelcome.render(self.request)
439 template_env['resources'] = univbrisfoamlist.render(self.request)
440 template_env['flowspaces'] = univbrisfvlist.render(self.request)
441 template_env['oflowspaces_form'] = univbrisofvform.render(self.request)
442 template_env['flowspaces_form'] = univbrisfvform.render(self.request)
443 template_env['topology'] = univbristopology.render(self.request)
445 # template_env['pending_resources'] = pending_resources.render(self.request)
446 template_env['sla_dialog'] = '' # sla_dialog.render(self.request)
447 template_env["theme"] = self.theme
448 template_env["username"] = self.request.user
449 template_env["person"] = self.request.user
450 template_env["pi"] = pi
451 template_env["slice"] = slicename
452 template_env["section"] = "resources"
453 template_env["msg"] = msg
454 template_env.update(page.prelude_env())
456 return render_to_response(self.template, template_env, context_instance=RequestContext(request))