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
7 from django.views.generic.base import TemplateView
9 from unfold.loginrequired import LoginRequiredView
10 from django.http import HttpResponse
11 from django.shortcuts import render
13 from unfold.page import Page
15 from myslice.configengine import ConfigEngine
16 from plugins.querytable import QueryTable
17 from plugins.googlemap import GoogleMap
18 from plugins.queryupdater import QueryUpdater
19 from plugins.testbeds import TestbedsPlugin
20 from plugins.scheduler2 import Scheduler2
21 from plugins.columns_editor import ColumnsEditor
23 from myslice.theme import ThemeView
25 class SliceResourceView (LoginRequiredView, ThemeView):
26 template_name = "slice-resource-view.html"
28 def get(self, request, slicename):
30 if request.GET.get('message') :
31 msg = "Slice successfully updated"
36 metadata = page.get_metadata()
37 page.expose_js_metadata()
39 resource_md = metadata.details_by_object('resource')
40 resource_fields = [column['name'] for column in resource_md['column']]
42 user_md = metadata.details_by_object('user')
43 user_fields = ['user_hrn'] # [column['name'] for column in user_md['column']]
45 # TODO The query to run is embedded in the URL
46 main_query = Query.get('slice').filter_by('slice_hrn', '=', slicename)
50 'resource.hostname', 'resource.type',
51 'resource.network_hrn',
54 #'application.measurement_point.counter'
56 # for internal use in the querytable plugin;
57 # needs to be a unique column present for each returned record
58 main_query_init_key = 'urn'
59 aq = AnalyzedQuery(main_query, metadata=metadata)
60 page.enqueue_query(main_query, analyzed_query=aq)
61 sq_resource = aq.subquery('resource')
62 sq_lease = aq.subquery('lease')
64 query_resource_all = Query.get('resource').select(resource_fields)
65 page.enqueue_query(query_resource_all)
68 lease_md = metadata.details_by_object('lease')
69 lease_fields = [column['name'] for column in lease_md['column']]
71 query_lease_all = Query.get('lease').select(lease_fields)
72 page.enqueue_query(query_lease_all)
74 # --------------------------------------------------------------------------
76 # resources as a list using datatable plugin
78 list_resources = QueryTable(
80 domid = 'resources-list',
83 query_all = query_resource_all,
86 datatables_options = {
88 'bLengthChange' : True,
94 # --------------------------------------------------------------------------
95 # RESERVED RESOURCES LIST
96 # resources as a list using datatable plugin
98 list_reserved_resources = QueryTable(
100 domid = 'resources-reserved-list',
103 query_all = sq_resource,
106 datatables_options = {
107 'iDisplayLength': 25,
108 'bLengthChange' : True,
113 # --------------------------------------------------------------------------
115 # list of fields to be applied on the query
116 # this will add/remove columns in QueryTable plugin
118 filter_column_editor = ColumnsEditor(
121 query_all = query_resource_all,
122 title = "Select Columns",
123 domid = 'select-columns',
126 # --------------------------------------------------------------------------
128 # the resources part is made of a Tabs (Geographic, List),
130 map_resources = GoogleMap(
132 title = 'Geographic view',
133 domid = 'resources-map',
134 # tab's sons preferably turn this off
137 query_all = query_resource_all,
138 # this key is the one issued by google
139 googlemap_api_key = ConfigEngine().googlemap_api_key(),
140 # the key to use at init-time
141 init_key = main_query_init_key,
149 # --------------------------------------------------------------------------
150 # LEASES Nitos Scheduler
151 # Display the leases reservation timeslots of the resources
153 resources_as_scheduler2 = Scheduler2(
157 # this is the query at the core of the slice list
159 query_lease = sq_lease,
160 query_all_resources = query_resource_all,
161 query_all_leases = query_lease_all,
164 # --------------------------------------------------------------------------
165 # QueryUpdater (Pending Operations)
167 pending_resources = QueryUpdater(
169 title = 'Pending operations',
172 # start turned off, it will open up itself when stuff comes in
175 outline_complete = True,
178 # --------------------------------------------------------------------------
180 # testbeds as a list of filters
182 network_md = metadata.details_by_object('network')
183 network_fields = [column['name'] for column in network_md['column']]
185 query_network = Query.get('network').select(network_fields)
186 page.enqueue_query(query_network)
188 filter_testbeds = TestbedsPlugin(
190 domid = 'testbeds-filter',
191 title = 'Filter by testbeds',
193 query_all = query_resource_all,
194 query_network = query_network,
195 init_key = "network_hrn",
197 datatables_options = {
198 'iDisplayLength': 25,
199 'bLengthChange' : True,
205 template_env['list_resources'] = list_resources.render(self.request)
206 # template_env['list_reserved_resources'] = list_reserved_resources.render(self.request)
208 template_env['columns_editor'] = filter_column_editor.render(self.request)
210 template_env['filter_testbeds'] = filter_testbeds.render(self.request)
211 template_env['map_resources'] = map_resources.render(self.request)
212 template_env['scheduler'] = resources_as_scheduler2.render(self.request)
213 template_env['pending_resources'] = pending_resources.render(self.request)
214 template_env["theme"] = self.theme
215 template_env["username"] = request.user
216 template_env["slice"] = slicename
217 template_env["section"] = "resources"
218 template_env["msg"] = msg
219 template_env.update(page.prelude_env())
221 return render_to_response(self.template, template_env, context_instance=RequestContext(request))