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
35 from plugins.columns_editor import ColumnsEditor
36 from plugins.sladialog import SlaDialog
37 from plugins.lists.simplelist import SimpleList
39 from myslice.theme import ThemeView
41 class SliceResourceView (LoginRequiredView, ThemeView):
42 template_name = "slice-resource-view.html"
44 def get(self, request, slicename):
46 if request.GET.get('message') :
47 msg = "Slice successfully updated"
52 metadata = page.get_metadata()
53 page.expose_js_metadata()
55 resource_md = metadata.details_by_object('resource')
56 resource_fields = [column['name'] for column in resource_md['column']]
58 user_md = metadata.details_by_object('user')
59 user_fields = ['user_hrn'] # [column['name'] for column in user_md['column']]
61 # TODO The query to run is embedded in the URL
62 # Example: select slice_hrn, resource.urn, lease.resource, lease.start_time, lease.end_time from slice where slice_hrn == "ple.upmc.myslicedemo"
63 main_query = Query.get('slice').filter_by('slice_hrn', '=', slicename)
67 # - The record key is needed otherwise the storage of records
72 'resource.hostname', 'resource.type',
73 # - The facility_name and testbed_name are required for the
74 # testbeds plugin to properly work.
75 'resource.facility_name',
76 'resource.testbed_name',
81 # - The lease_id is important for NITOS identify already existing
86 #'application.measurement_point.counter'
88 # for internal use in the querytable plugin;
89 # needs to be a unique column present for each returned record
90 main_query_init_key = 'urn'
91 aq = AnalyzedQuery(main_query, metadata=metadata)
92 page.enqueue_query(main_query, analyzed_query=aq)
93 sq_resource = aq.subquery('resource')
94 sq_lease = aq.subquery('lease')
96 query_resource_all = Query.get('resource').select(resource_fields)
97 page.enqueue_query(query_resource_all)
100 #lease_md = metadata.details_by_object('lease')
101 #lease_fields = [column['name'] for column in lease_md['column']]
103 #query_lease_all = Query.get('lease').select(lease_fields)
104 #page.enqueue_query(query_lease_all)
106 # --------------------------------------------------------------------------
108 # resources as a list using datatable plugin
110 list_resources = QueryTable(
112 domid = 'resources-list',
115 query_all = query_resource_all,
118 datatables_options = {
119 'iDisplayLength': 25,
120 'bLengthChange' : True,
126 # --------------------------------------------------------------------------
127 # RESERVED RESOURCES LIST
128 # resources as a list using datatable plugin
130 list_reserved_resources = SimpleList(
137 list_reserved_leases = SimpleList(
144 # list_reserved_resources = QueryTable(
146 # domid = 'resources-reserved-list',
147 # title = 'List view',
148 # query = sq_resource,
149 # query_all = sq_resource,
152 # datatables_options = {
153 # 'iDisplayLength': 25,
154 # 'bLengthChange' : True,
155 # 'bAutoWidth' : True,
159 # --------------------------------------------------------------------------
161 # list of fields to be applied on the query
162 # this will add/remove columns in QueryTable plugin
164 filter_column_editor = ColumnsEditor(
167 query_all = query_resource_all,
168 title = "Select Columns",
169 domid = 'select-columns',
172 # --------------------------------------------------------------------------
174 # the resources part is made of a Tabs (Geographic, List),
176 map_resources = GoogleMap(
178 title = 'Geographic view',
179 domid = 'resources-map',
180 # tab's sons preferably turn this off
183 # this key is the one issued by google
184 googlemap_api_key = ConfigEngine().googlemap_api_key(),
185 # the key to use at init-time
186 init_key = main_query_init_key,
189 # To center around Europe : 53,9 / 3
195 # --------------------------------------------------------------------------
196 # LEASES Nitos Scheduler
197 # Display the leases reservation timeslots of the resources
199 resources_as_scheduler2 = Scheduler2(
203 # this is the query at the core of the slice list
205 query_lease = sq_lease,
208 # --------------------------------------------------------------------------
209 # QueryUpdater (Pending Operations)
211 # pending_resources = QueryUpdaterPlugin(
213 # title = 'Pending operations',
214 # query = main_query,
216 # # start turned off, it will open up itself when stuff comes in
219 # outline_complete = True,
220 # username = request.user,
223 # --------------------------------------------------------------------------
225 # testbeds as a list of filters
227 network_md = metadata.details_by_object('network')
228 network_fields = [column['name'] for column in network_md['column']]
230 #query_networks = Query.get('network').select(network_fields)
231 #page.enqueue_query(query_networks)
233 filter_testbeds = TestbedsPlugin(
235 domid = 'testbeds-filter',
236 title = 'Filter by testbeds',
238 #query_networks = query_networks,
239 #init_key = "network_hrn",
241 #datatables_options = {
242 # 'iDisplayLength': 25,
243 # 'bLengthChange' : True,
244 # 'bAutoWidth' : True,
248 filter_status = FilterStatusPlugin(
250 domid = "filter-status",
257 username = request.user,
260 # --------------------------------------------------------------------------
261 # Ofelia OpenFlow Plugin
264 # plugin which display a "gathering resources" message
265 # waiting for all resources to be returned by manifold
266 univbriswelcome = Univbris(
268 title = 'univbris_welcome',
269 domid = 'univbris_welcome',
270 query = query_resource_all,
273 univbrisfoamlist = UnivbrisFoam(
275 title = 'univbris_foam_ports_selection',
276 domid = 'univbris_foam_ports_selection',
277 query = query_resource_all,
278 query_all = query_resource_all,
280 datatables_options = {
281 'iDisplayLength': 10,
282 'bLengthChange' : True,
287 #plugin which manages the different flowspaces that the user creates, and also sends flowspaces to manifold
288 univbrisfvlist = UnivbrisFv(
290 title = 'univbris_flowspace_selection',
291 domid = 'univbris_flowspace_selection',
294 sync_query = query_resource_all,
295 datatables_options = {
297 'bLengthChange' : True,
302 #plugin which allows the definition of a single flowspace
303 univbrisfvform = UnivbrisFvf(
305 title = 'univbris_flowspace_form',
306 domid = 'univbris_flowspace_form',
307 query = query_resource_all,
309 datatables_options = {
311 'bLengthChange' : True,
316 #plugin which allows the definition the match criteria on a single OPTICAL flowspace
318 univbrisofvform = UnivbrisFvfo(
320 title = 'univbris_oflowspace_form',
321 domid = 'univbris_oflowspace_form',
324 datatables_options = {
326 'bLengthChange' : True,
331 #plugin which display the gathered topology
332 univbristopology = UnivbrisTopo(
334 title = 'univbris_topology',
335 domid = 'univbris_topology',
336 query = query_resource_all,
337 #query = query_resource_all,
340 # --------------------------------------------------------------------------
341 # SLA View and accept dialog
343 sla_dialog = SlaDialog(
345 title = 'sla dialog',
348 # start turned off, it will open up itself when stuff comes in
350 domid = 'sla_dialog',
351 outline_complete = True,
352 username = request.user,
355 ## check user is pi or not
356 platform_query = Query().get('local:platform').select('platform_id','platform','gateway_type','disabled')
357 account_query = Query().get('local:account').select('user_id','platform_id','auth_type','config')
358 platform_details = execute_query(self.request, platform_query)
359 account_details = execute_query(self.request, account_query)
361 # XXX When session has expired, this is None and thus not iterable
362 for platform_detail in platform_details:
363 for account_detail in account_details:
364 if platform_detail['platform_id'] == account_detail['platform_id']:
365 if 'config' in account_detail and account_detail['config'] is not '':
366 account_config = json.loads(account_detail['config'])
367 if 'myslice' in platform_detail['platform']:
368 acc_auth_cred = account_config.get('delegated_authority_credentials','N/A')
370 if acc_auth_cred == {} or acc_auth_cred == 'N/A':
376 template_env['list_resources'] = list_resources.render(self.request)
377 template_env['list_reserved_resources'] = list_reserved_resources.render(self.request)
378 template_env['list_reserved_leases'] = list_reserved_leases.render(self.request)
380 template_env['columns_editor'] = filter_column_editor.render(self.request)
382 template_env['filter_testbeds'] = filter_testbeds.render(self.request)
383 template_env['filter_status'] = filter_status.render(self.request)
384 template_env['apply'] = apply.render(self.request)
386 template_env['map_resources'] = map_resources.render(self.request)
387 template_env['scheduler'] = resources_as_scheduler2.render(self.request)
390 template_env['welcome'] = univbriswelcome.render(self.request)
391 template_env['resources'] = univbrisfoamlist.render(self.request)
392 template_env['flowspaces'] = univbrisfvlist.render(self.request)
393 template_env['oflowspaces_form'] = univbrisofvform.render(self.request)
394 template_env['flowspaces_form'] = univbrisfvform.render(self.request)
395 template_env['topology'] = univbristopology.render(self.request)
397 # template_env['pending_resources'] = pending_resources.render(self.request)
398 template_env['sla_dialog'] = '' # sla_dialog.render(self.request)
399 template_env["theme"] = self.theme
400 template_env["username"] = request.user
401 template_env["pi"] = pi
402 template_env["slice"] = slicename
403 template_env["section"] = "resources"
404 template_env["msg"] = msg
405 template_env.update(page.prelude_env())
407 return render_to_response(self.template, template_env, context_instance=RequestContext(request))