1 from django.template import RequestContext
2 from django.shortcuts import render_to_response
4 from unfold.loginrequired import LoginRequiredAutoLogoutView
6 from unfold.page import Page
7 from manifold.core.query import Query, AnalyzedQuery
9 from ui.topmenu import topmenu_items, the_user
11 from plugins.raw import Raw
12 from plugins.stack import Stack
13 from plugins.tabs import Tabs
14 from plugins.hazelnut import Hazelnut
15 from plugins.resources_selected import ResourcesSelected
16 from plugins.googlemap import GoogleMap
17 from plugins.senslabmap import SensLabMap
18 from plugins.querycode import QueryCode
19 from plugins.query_editor import QueryEditor
20 from plugins.active_filters import ActiveFilters
21 from plugins.quickfilter import QuickFilter
22 from plugins.messages import Messages
23 from plugins.slicestat import Slicestat
25 from myslice.config import Config
27 tmp_default_slice='ple.upmc.myslicedemo'
29 # temporary : turn off the users part to speed things up
33 class SliceView (LoginRequiredAutoLogoutView):
35 def get (self,request, slicename=tmp_default_slice):
38 page.add_css_files ('css/slice-view.css')
39 page.add_js_files ( [ "js/common.functions.js" ] )
40 page.add_js_chunks ('$(function() { messages.debug("sliceview: jQuery version " + $.fn.jquery); });')
41 page.add_js_chunks ('$(function() { messages.debug("sliceview: users turned %s"); });'%("on" if do_query_users else "off"))
43 page.add_js_chunks ('$(function() { messages.debug("manifold URL %s"); });'%(config.manifold_url()))
44 page.expose_js_metadata()
46 metadata = page.get_metadata()
47 resource_md = metadata.details_by_object('resource')
48 resource_fields = [column['name'] for column in resource_md['column']]
50 user_md = metadata.details_by_object('user')
51 user_fields = ['user_hrn'] # [column['name'] for column in user_md['column']]
53 # TODO The query to run is embedded in the URL
54 main_query = Query.get('slice').filter_by('slice_hrn', '=', slicename)
57 'resource.hrn', 'resource.hostname', 'resource.type',
58 'resource.network_hrn',
61 #'application.measurement_point.counter'
64 query_resource_all = Query.get('resource').select(resource_fields)
66 query_user_all = Query.get('user').select(user_fields)
68 aq = AnalyzedQuery(main_query, metadata=metadata)
69 page.enqueue_query(main_query, analyzed_query=aq)
70 page.enqueue_query(query_resource_all)
72 page.enqueue_query(query_user_all)
74 # ... and for the relations
75 # XXX Let's hardcode resources for now
76 sq_resource = aq.subquery('resource')
77 sq_user = aq.subquery('user')
78 sq_lease = aq.subquery('lease')
79 sq_measurement = aq.subquery('measurement')
82 # Prepare the display according to all metadata
83 # (some parts will be pending, others can be triggered by users).
85 # For example slice measurements will not be requested by default...
87 # Create the base layout (Stack)...
90 title="Slice %s"%slicename,
94 # ... responsible for the slice properties...
101 html="<h2 class='well well-lg'> Slice %s</h2>"%slicename)
104 # --------------------------------------------------------------------------
105 # ResourcesSelected (Pending Operations)
107 main_stack.insert(ResourcesSelected(
109 title = 'Pending operations',
112 # start turned off, it will open up itself when stuff comes in
115 outline_complete = True,
118 # --------------------------------------------------------------------------
121 filter_query_editor = QueryEditor(
124 query_all = query_resource_all,
125 title = "Select Columns",
126 domid = 'select-columns',
128 filter_active_filters = ActiveFilters(
131 title = "Active Filters",
133 filters_area = Stack(
135 title = 'Filter Resources',
137 sons = [filter_query_editor, filter_active_filters],
139 toggled = 'persistent',
140 outline_complete = True,
142 main_stack.insert (filters_area)
144 # --------------------------------------------------------------------------
146 # the resources part is made of a Tabs (Geographic, List),
148 resources_as_map = GoogleMap(
150 title = 'Geographic view',
151 domid = 'resources-map',
152 # tab's sons preferably turn this off
155 query_all = query_resource_all,
163 resources_as_list = Hazelnut(
165 domid = 'resources-list',
167 # this is the query at the core of the slice list
169 query_all = query_resource_all,
171 datatables_options = {
172 'iDisplayLength': 25,
173 'bLengthChange' : True,
178 resources_stats_cpu = Slicestat(
180 domid = 'resources-stats-cpu',
185 slicename = slicename,
189 resources_stats_mem = Slicestat(
190 title = "Memory Usage",
191 domid = 'resources-stats-mem',
196 slicename = slicename,
200 resources_stats_asb = Slicestat(
201 title = "Traffic Sent",
202 domid = 'resources-stats-asb',
207 slicename = slicename,
211 resources_stats_arb = Slicestat(
212 title = "Traffic Received",
213 domid = 'resources-stats-arb',
218 slicename = slicename,
222 # with the new 'Filter' stuff on top, no need for anything but the hazelnut
223 resources_as_list_area = resources_as_list
225 resources_area = Tabs ( page=page,
229 outline_complete=True,
230 sons=[ resources_as_map, resources_as_list_area, resources_stats_cpu, resources_stats_mem, resources_stats_asb, resources_stats_arb ],
231 active_domid = 'resources-map',
233 main_stack.insert (resources_area)
235 # --------------------------------------------------------------------------
243 outline_complete = True,
246 active_domid = 'users-list',
248 main_stack.insert(tab_users)
250 tab_users.insert(Hazelnut(
252 title = 'Users List',
253 domid = 'users-list',
254 # tab's sons preferably turn this off
256 # this is the query at the core of the slice list
258 query_all = query_user_all,
260 datatables_options = {
261 'iDisplayLength' : 25,
262 'bLengthChange' : True,
273 outline_complete = True,
276 active_domid = 'users-list',
278 main_stack.insert(tab_users)
280 tab_users.insert(Hazelnut(
282 title = 'Users List',
283 domid = 'users-list',
284 # tab's sons preferably turn this off
286 # this is the query at the core of the slice list
288 query_all = query_user_all,
290 datatables_options = {
291 'iDisplayLength' : 25,
292 'bLengthChange' : True,
296 >>>>>>> 0c8a634162f3271018102e75a3934c5db5e48f59
298 # --------------------------------------------------------------------------
300 # tab_measurements = Tabs (
302 # active_domid = 'measurements-list',
303 # outline_complete = True,
305 # title = 'Measurements',
306 # domid = 'measurements',
308 # main_stack.insert(tab_measurements)
310 # tab_measurements.insert(Hazelnut(
312 # title = 'Measurements',
313 # domid = 'measurements-list',
314 # # tab's sons preferably turn this off
316 # # this is the query at the core of the slice list
317 # query = sq_measurement,
318 # # do NOT set checkboxes to False
319 # # this table being otherwise empty, it just does not fly with dataTables
321 # datatables_options = {
322 # 'iDisplayLength' : 25,
323 # 'bLengthChange' : True,
324 # 'bAutoWidth' : True,
328 # # --------------------------------------------------------------------------
329 # # MESSAGES (we use transient=False for now)
330 # main_stack.insert(Messages(
332 # title = "Runtime messages for slice %s"%slicename,
333 # domid = "msgs-pre",
335 # # plain messages are probably less nice for production but more reliable for development for now
337 # # these make sense only in non-transient mode..
339 # toggled = 'persistent',
340 # outline_complete = True,
344 # variables that will get passed to the view-unfold1.html template
347 # define 'unfold1_main' to the template engine - the main contents
348 template_env [ 'unfold1_main' ] = main_stack.render(request)
350 # more general variables expected in the template
351 template_env [ 'title' ] = '%(slicename)s'%locals()
352 # the menu items on the top
353 template_env [ 'topmenu_items' ] = topmenu_items('Slice', request)
354 # so we can sho who is logged
355 template_env [ 'username' ] = the_user (request)
357 # don't forget to run the requests
358 page.expose_queries ()
360 # xxx create another plugin with the same query and a different layout (with_datatables)
361 # show that it worls as expected, one single api call to backend and 2 refreshed views
363 # the prelude object in page contains a summary of the requirements() for all plugins
364 # define {js,css}_{files,chunks}
365 prelude_env = page.prelude_env()
366 template_env.update(prelude_env)
367 result=render_to_response ('view-unfold1.html',template_env,
368 context_instance=RequestContext(request))