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
21 from theme import ThemeView
23 class SliceResourceView (LoginRequiredView, ThemeView):
24 template_name = "slice-resource-view.html"
26 def get(self, request, slicename):
28 if request.GET.get('message') :
29 msg = "Slice successfully updated"
34 metadata = page.get_metadata()
35 page.expose_js_metadata()
37 resource_md = metadata.details_by_object('resource')
38 resource_fields = [column['name'] for column in resource_md['column']]
40 user_md = metadata.details_by_object('user')
41 user_fields = ['user_hrn'] # [column['name'] for column in user_md['column']]
43 # TODO The query to run is embedded in the URL
44 main_query = Query.get('slice').filter_by('slice_hrn', '=', slicename)
48 'resource.hostname', 'resource.type',
49 'resource.network_hrn',
52 #'application.measurement_point.counter'
54 # for internal use in the querytable plugin;
55 # needs to be a unique column present for each returned record
56 main_query_init_key = 'urn'
57 aq = AnalyzedQuery(main_query, metadata=metadata)
58 page.enqueue_query(main_query, analyzed_query=aq)
60 query_resource_all = Query.get('resource').select(resource_fields)
61 page.enqueue_query(query_resource_all)
63 sq_resource = aq.subquery('resource')
64 sq_lease = aq.subquery('lease')
66 # --------------------------------------------------------------------------
68 # resources as a list using datatable plugin
70 list_resources = QueryTable(
72 domid = 'resources-list',
75 query_all = query_resource_all,
78 datatables_options = {
80 'bLengthChange' : True,
85 # --------------------------------------------------------------------------
87 # the resources part is made of a Tabs (Geographic, List),
89 map_resources = GoogleMap(
91 title = 'Geographic view',
92 domid = 'resources-map',
93 # tab's sons preferably turn this off
96 query_all = query_resource_all,
97 # this key is the one issued by google
98 googlemap_api_key = ConfigEngine().googlemap_api_key(),
99 # the key to use at init-time
100 init_key = main_query_init_key,
108 # --------------------------------------------------------------------------
109 # QueryUpdater (Pending Operations)
111 pending_resources = QueryUpdater(
113 title = 'Pending operations',
116 # start turned off, it will open up itself when stuff comes in
119 outline_complete = True,
122 # --------------------------------------------------------------------------
124 # testbeds as a list of filters
126 network_md = metadata.details_by_object('network')
127 network_fields = [column['name'] for column in network_md['column']]
128 print "sliceresourceview.py ====> ",network_fields
130 query_network = Query.get('network').select(network_fields)
131 page.enqueue_query(query_network)
133 filter_testbeds = TestbedsPlugin(
135 domid = 'testbeds-filter',
136 title = 'Filter by testbeds',
138 query_all = query_resource_all,
139 query_network = query_network,
140 init_key = "network_hrn",
142 datatables_options = {
143 'iDisplayLength': 25,
144 'bLengthChange' : True,
150 template_env['list_resources'] = list_resources.render(self.request)
151 template_env['filter_testbeds'] = filter_testbeds.render(self.request)
152 template_env['map_resources'] = map_resources.render(self.request)
153 template_env['pending_resources'] = pending_resources.render(self.request)
154 template_env["theme"] = self.theme
155 template_env["username"] = request.user
156 template_env["slice"] = slicename
157 template_env["section"] = "resources"
158 template_env["msg"] = msg
159 template_env.update(page.prelude_env())
161 return render_to_response(self.template, template_env, context_instance=RequestContext(request))