Merge branch 'fibre' of ssh://git.onelab.eu/git/myslice into fibre
[unfold.git] / portal / univbrisview.py
1 import json
2 from manifold.core.query         import Query
3 from manifoldapi.manifoldapi        import execute_query
4
5 from unfold.page                 import Page
6
7 from plugins.lists.testbedlist   import TestbedList
8 from plugins.lists.slicelist     import SliceList
9
10 from unfold.loginrequired       import FreeAccessView
11 from unfold.loginrequired        import LoginRequiredAutoLogoutView
12
13 from ui.topmenu                  import topmenu_items_live, the_user
14 from plugins.querytable          import QueryTable
15 from plugins.univbrisfoam        import UnivbrisFoam
16 from plugins.univbrisfv          import UnivbrisFv
17 from plugins.lists.staticlist    import StaticList
18 from plugins.lists.slicelist     import SliceList
19 from plugins.messages           import Messages
20 from plugins.univbrisfvf        import UnivbrisFvf
21 from plugins.univbrisfvfo       import UnivbrisFvfo
22 from plugins.univbris           import Univbris
23 from plugins.univbristopo       import UnivbrisTopo
24
25 #This view requires login 
26 class UnivbrisView (LoginRequiredAutoLogoutView):
27 #class UnivbrisView (FreeAccessView):
28     template_name = "univbris.html"
29     
30     def get_context_data(self, **kwargs):
31         
32         page = Page(self.request)
33         #print "UNIVBRIS page"
34         metadata = page.get_metadata()
35         page.expose_js_metadata()
36     
37         resource_md = metadata.details_by_object('resource')
38         resource_fields = [column['name'] for column in resource_md['column']]
39     
40         user_md = metadata.details_by_object('user')
41         user_fields = ['user_hrn'] # [column['name'] for column in user_md['column']]
42     
43     
44         #create new query to manifold----query is not called yet
45         #need to modify to get i2cat of resources also
46         univbrisfoam_query=Query().get('ofelia-bristol-of:resource').select('urn')
47         #print univbrisfoam_query #.select('urn')
48         #Query().get('ofelia-bristol-of:resource')
49         ##custom query to communication between univbris plugins
50         #univbris_query=Query()
51             
52         #queue the query
53         page.enqueue_query(univbrisfoam_query)
54         #page.enqueue_query(univbris_query)
55         page.expose_js_metadata()
56     
57     
58         #plugin which display a "gathering resources" message waiting for all resources to be returned by manifold
59         univbriswelcome = Univbris(
60             page  = page,
61             title = 'univbris_welcome',
62             domid = 'univbris_welcome',
63             query = univbrisfoam_query,
64         )
65         
66         #plugin which collects different openflow ports from maniford
67         univbrisfoamlist = UnivbrisFoam(
68             page  = page,
69             title = 'univbris_foam_ports_selection',
70             domid = 'univbris_foam_ports_selection',
71             query = univbrisfoam_query,
72             query_all = univbrisfoam_query,
73             sync_query= univbrisfoam_query,
74             checkboxes = False,
75             datatables_options = { 
76                 'iDisplayLength': 10,
77                 'bLengthChange' : True,
78                 'bAutoWidth'    : True,
79                 },
80         )
81     
82         #plugin which manages the different flowspaces that the user creates, and also sends flowspaces to manifold
83         univbrisfvlist = UnivbrisFv(
84             page  = page,
85             title = 'univbris_flowspace_selection',
86             domid = 'univbris_flowspace_selection',
87             query = None,
88             query_all = None,
89             sync_query= univbrisfoam_query,
90             datatables_options = { 
91                 'iDisplayLength': 5,
92                 'bLengthChange' : True,
93                 'bAutoWidth'    : True,
94                 },
95         )
96     
97         #plugin which allows the definition the match criteria on a single PACKET flowspace
98         univbrisfvform = UnivbrisFvf(
99             page  = page,
100             title = 'univbris_flowspace_form',
101             domid = 'univbris_flowspace_form',
102             query = None,
103             query_all = None,
104             datatables_options = { 
105                 'iDisplayLength': 3,
106                 'bLengthChange' : True,
107                 'bAutoWidth'    : True,
108                 },
109         )
110     
111         #plugin which allows the definition the match criteria on a single OPTICAL flowspace
112     
113         univbrisofvform = UnivbrisFvfo(
114                 page  = page,
115                 title = 'univbris_oflowspace_form',
116                 domid = 'univbris_oflowspace_form',
117                 query = None,
118                 query_all = None,
119                 datatables_options = { 
120                     'iDisplayLength': 3,
121                     'bLengthChange' : True,
122                     'bAutoWidth'    : True,
123                     },
124             )
125     
126     
127         #plugin which display the gathered topology
128         univbristopology = UnivbrisTopo(
129                 page  = page,
130                 title = 'univbris_topology',
131                 domid = 'univbris_topology',
132                 query = univbrisfoam_query,
133             )
134         
135         #render plugins in each context within a single page, but not all plugins are visible at all time.
136         context = super(UnivbrisView, self).get_context_data(**kwargs)
137         context['person']   = self.request.user
138         context['welcome'] = univbriswelcome.render(self.request)
139         context['resources'] = univbrisfoamlist.render(self.request)
140         context['flowspaces']= univbrisfvlist.render(self.request)
141         context['oflowspaces_form']= univbrisofvform.render(self.request)
142         context['flowspaces_form']= univbrisfvform.render(self.request)
143         context['topology']=univbristopology.render(self.request)
144     
145         # XXX This is repeated in all pages
146         # more general variables expected in the template
147         context['title'] = 'Book OpenFlow resources'
148         # the menu items on the top
149         context['topmenu_items'] = topmenu_items_live('univbris', page)
150         # so we can sho who is logged
151         context['username'] = the_user(self.request)
152         
153         context.update(page.prelude_env())
154         page.expose_js_metadata()
155         
156         
157         # the page header and other stuff
158         context.update(page.prelude_env())
159         
160         context['layout_1_or_2']="layout-unfold2.html" if not context['username'] else "layout-unfold1.html"
161         
162         return context